[Lang] Cache spec keys for None kernel arguments - #877
Open
hughperkins wants to merge 1 commit into
Open
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.
3 tasks
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
A kernel argument of
None(an absent optionalqd.Tensor/qd.template()slot) is ~21% slower per launch than it should be, because its template-mapper spec-key cache entry is never stored.TemplateMapper.lookupweakref-tracks every argument whose type is not in_primitive_types, so it can evict the spec-key cache entry when the argument is garbage-collected.weakref.ref(None)raisesTypeError, which was caught and downgraded to awarn_once, leaving the entry unstored - so every launch passingNonere-ran full spec-key extraction instead of hitting the cache.This adds
NoneTypeto_primitive_types.Noneis an immortal singleton that never needs lifetime tracking, so excluding it from the weakref loop is both correct and removes the overhead.Measurements
CPU, 20000 iterations, microseconds per launch, optional
qd.Tensorslot:b=Noneb=ndarray(present)The absent branch does strictly less work than the present branch yet was slower than the control; the gap closes from +20.8% to ~0.3%. Specialization counts and results are unchanged. The spec-key cache now populates for a
Noneargument (0 -> 1 entries).Test plan
test_none_argument_populates_spec_key_cachepasses on x64 and cudatests/run_tests.py -r 3, x64, split byneeds_torchexactly aslinux/4_test.sh): this branch's unique failing set is identical to unmodifiedmainand 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, so load-induced flakes and xdist worker-kill collateral surfaced as hard failures. Under the CI harness they do not.)Context: first of two prerequisite fixes for optional (
None) kernel arguments, motivated by #856.Made with Cursor