[Cache] W2 Make None arguments fast-cacheable - #879
Merged
Conversation
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.
Collaborator
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
Collaborator
Author
|
No user-facing doc changes required beyond the single row addition to the table in fastcache.md |
Collaborator
Author
|
I will address the doc quality check in separate PR |
Collaborator
Author
|
running genesis benchmarks (dont see how this could affect htem, but anwyay) |
Collaborator
Author
Collaborator
Author
|
Need to run genesis unit tests next (waiting for a node first...) |
Collaborator
Author
|
running genesis unit tests |
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
An absent optional argument (a
qd.Tensororqd.template()slot passedNone) silently disabled fast cache for the entire kernel call and logged a warning.stringify_obj_typehad no branch forNone, so it fell through to thePARAM_INVALIDcatch-all, which set the warn flag and madehash_argsreturnFastcacheSkip.WARN. That hit exactly the absent-branch specialization that #856 wants to be the cheap common case.Noneis 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.Verification
@qd.kernel(fastcache=True)with an optionalqd.Tensorslot, fresh cache then reused cache:b=Nonecache_key_generated=False, warnscache_key_generated=Truecache_validated=Trueb=ndarraycache_validated=Truecache_key_generated=Truecache_validated=TrueThe
Nonespecialization now gets a genuine cross-process fastcache hit, and noPARAM_INVALID/INVALID_FUNCwarnings are emitted. Results and autodiff gradients are unchanged.Test plan
test_args_hasher_none_is_cacheablepasses on x64Nonefastcache validated across processes end-to-end (fastcache=Truekernel)tests/run_tests.py -r 3, x64, split byneeds_torchexactly aslinux/4_test.sh): this branch's unique failing set is identical to unmodifiedmain(and to W1 [Lang] W1 Cache spec keys for None kernel arguments #877) and theneeds_torchphase 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'scuobjdumppredates CUDA 13 and misreads the committed cubin's build toolkit as0.2instead of13.0+;test_pyi_stubs-python -m pyrightcannot fetch its Node runtime on an offline compute node;test_ipython.ipynb-io.UnsupportedOperationfrom quadrants' stdout wrapping under nbmake's ipykernel capture.(An earlier revision of this checklist reported raw
pytestcounts; those were inflated because that run omitted CI's-r 3flaky-rerun.)Context: second of two prerequisite fixes for optional (
None) kernel arguments, motivated by #856.Made with Cursor