Skip to content

[Cache] W2 Make None arguments fast-cacheable - #879

Merged
hughperkins merged 5 commits into
mainfrom
hp/w2-nonetype-fastcache
Aug 21, 2026
Merged

[Cache] W2 Make None arguments fast-cacheable#879
hughperkins merged 5 commits into
mainfrom
hp/w2-nonetype-fastcache

Conversation

@hughperkins

@hughperkins hughperkins commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

An absent optional argument (a qd.Tensor or qd.template() slot passed None) silently disabled fast cache for the entire kernel call and logged a warning.

stringify_obj_type had no branch for None, so it fell through to the PARAM_INVALID catch-all, which set the warn flag and made hash_args return FastcacheSkip.WARN. That hit exactly the absent-branch specialization that #856 wants to be the cheap common case.

None is a singleton, so its type fully determines its value: this tags it with a constant. It now hashes to a stable key, does not poison the other arguments in the same call, and appears in the fastcache supported-parameter table.

Stacked on #877 (base branch hp/w1-nonetype-primitive-types). Review/merge that first.

Verification

@qd.kernel(fastcache=True) with an optional qd.Tensor slot, fresh cache then reused cache:

call before after run 1 after run 2 (same cache)
b=None cache_key_generated=False, warns cache_key_generated=True cache_validated=True
b=ndarray cache_validated=True cache_key_generated=True cache_validated=True

The None specialization now gets a genuine cross-process fastcache hit, and no PARAM_INVALID / INVALID_FUNC warnings are emitted. Results and autodiff gradients are unchanged.

Test plan

  • New test_args_hasher_none_is_cacheable passes on x64
  • None fastcache validated across processes end-to-end (fastcache=True kernel)
  • Full CPU suite via the CI harness (tests/run_tests.py -r 3, x64, split by needs_torch exactly as linux/4_test.sh): this branch's unique failing set is identical to unmodified main (and to W1 [Lang] W1 Cache spec keys for None kernel arguments #877) and the needs_torch phase passes clean, so this PR introduces no new failures.

The only shared failures are three tests that cannot pass in the offline cluster container regardless of branch (they fail the same way on main), all unrelated to this change:

  • test_committed_fatbin_layout - the container's cuobjdump predates CUDA 13 and misreads the committed cubin's build toolkit as 0.2 instead of 13.0+;
  • test_pyi_stubs - python -m pyright cannot fetch its Node runtime on an offline compute node;
  • test_ipython.ipynb - io.UnsupportedOperation from quadrants' stdout wrapping under nbmake's ipykernel capture.

(An earlier revision of this checklist reported raw pytest counts; those were inflated because that run omitted CI's -r 3 flaky-rerun.)

Context: second of two prerequisite fixes for optional (None) kernel arguments, motivated by #856.

Made with Cursor

TemplateMapper.lookup weakref-tracks every argument whose type is not in
_primitive_types so it can evict the spec-key cache entry when the argument is
collected. weakref.ref(None) raises TypeError, which was caught and downgraded
to a warn_once, leaving the entry unstored - so every launch passing None
re-ran full spec-key extraction instead of hitting the cache.

Add NoneType to _primitive_types. None is an immortal singleton that never needs
lifetime tracking, so excluding it from the weakref loop is both correct and
removes the ~21% per-launch overhead measured for an absent optional qd.Tensor
argument. Specialization counts and results are unchanged.
stringify_obj_type had no branch for None, so an absent optional argument (a
qd.Tensor or qd.template() slot passed None) fell through to the PARAM_INVALID
catch-all, which set the warn flag and made hash_args return FastcacheSkip.WARN
- disabling fast cache for the whole call and logging a warning. This hit
exactly the absent-branch specialization that is meant to be the cheap common
case.

None is a singleton, so its type fully determines its value: tag it with a
constant. It now hashes to a stable key, does not poison other arguments in the
same call, and appears in the fastcache supported-parameter table.
@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

@hughperkins

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: d8e6558e9c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@hughperkins hughperkins removed the awaiting-codex-review awaiting-codex-review label Aug 21, 2026
@hughperkins hughperkins changed the title [Cache] Make None arguments fast-cacheable [Cache] W2 Make None arguments fast-cacheable Aug 21, 2026
@hughperkins

Copy link
Copy Markdown
Collaborator Author

No user-facing doc changes required beyond the single row addition to the table in fastcache.md

@github-actions

Copy link
Copy Markdown

@hughperkins

Copy link
Copy Markdown
Collaborator Author

I will address the doc quality check in separate PR

@github-actions

Copy link
Copy Markdown

Base automatically changed from hp/w1-nonetype-primitive-types to main August 21, 2026 14:34
@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

@hughperkins

Copy link
Copy Markdown
Collaborator Author

running genesis benchmarks (dont see how this could affect htem, but anwyay)

@hughperkins

Copy link
Copy Markdown
Collaborator Author

Genesis benchmarks look ok:

20260821_W2_1508

@hughperkins

Copy link
Copy Markdown
Collaborator Author

Need to run genesis unit tests next (waiting for a node first...)

@hughperkins

Copy link
Copy Markdown
Collaborator Author

running genesis unit tests

@hughperkins

Copy link
Copy Markdown
Collaborator Author

Genesis unit tests ok:

Screenshot 2026-08-21 at 17 30 04

@hughperkins
hughperkins merged commit 009f0a2 into main Aug 21, 2026
79 of 97 checks passed
@hughperkins
hughperkins deleted the hp/w2-nonetype-fastcache branch August 21, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant