[fast-launcher] Concrete-tensor fast path skips _hashable_dims (Python-only)#2611
Draft
yushangdi wants to merge 1 commit into
Draft
[fast-launcher] Concrete-tensor fast path skips _hashable_dims (Python-only)#2611yushangdi wants to merge 1 commit into
yushangdi wants to merge 1 commit into
Conversation
…n-only) Splits the per-tensor specialization-key extractor in two: - ``_concrete_tensor_key`` (new) handles ``torch.Tensor`` and ``torch.nn.Parameter``. Both always have concrete-int sizes/strides, so the cache-key components are just ``obj.size()`` and ``obj.stride()`` directly — ``torch.Size`` and the stride tuple are already tuple subclasses whose hash matches a plain tuple of the same ints, so the dispatch produces an identical hashable key without rebuilding it. - ``_tensor_key`` (existing, unchanged) stays as the ``FakeTensor``-dispatch entry. FakeTensors have SymInt sizes during tracing, and ``_hashable_dims`` is the normalization that maps each ``SymInt`` to ``(id(shape_env), expr)`` so two SymInts from different shape envs don't accidentally collide. The split happens at the ``_specialization_extractors`` table, so the right extractor is selected by a single dict lookup with no per-call type check on the hot path. Hash equality between the two extractors is verified by a test (see ``test_fast_path_key_hash_matches_wrapped``) so existing on-disk ``LooseAutotuneCacheKey`` entries built before this change keep matching. Benchmarks (H100, vector_add at N=4096, cycling through 8 different x/y tensors so the cache hits but never on the same args twice) ----------------------------------------------------------- ``_base_specialization_key`` in isolation (the dominant component of ``Kernel.bind()`` per-call cost): before: 2.76 us after: 2.14 us saving: -0.62 us (-22%) End-to-end per-call timing at this stack position (Chunk D pool + codegen rewrite applied, Phase 2 fast launcher not yet applied): before (parent commit, debc08a): cpu_only=~16.0 us wall+sync=~16.0 us after (this commit): cpu_only= 14.87 us wall+sync= 14.87 us saving: ~-1.1 us/call Tests ----- ``test/test_tensor_key_fast_path.py`` covers: - Dispatch table routes concrete tensors to the fast path and FakeTensor to the old path. - The fast-path key hashes and compares equal to the old wrapped key (cache-compat invariant). - The fast-path key contains a ``torch.Size`` (not a wrapped plain tuple) when the kernel uses ``static_shapes=True``. - ``bind()`` still returns the same ``BoundKernel`` for different tensor objects with matching dtype/shape/stride, and distinguishes different dtypes and shapes. stack-info: PR: #2611, branch: yushangdi/stack/13
a147793 to
0068448
Compare
This was referenced May 27, 2026
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.
Stacked PRs:
[fast-launcher] Concrete-tensor fast path skips _hashable_dims (Python-only)
Splits the per-tensor specialization-key extractor in two:
_concrete_tensor_key(new) handlestorch.Tensorandtorch.nn.Parameter. Both always have concrete-int sizes/strides,so the cache-key components are just
obj.size()andobj.stride()directly —torch.Sizeand the stride tuple arealready tuple subclasses whose hash matches a plain tuple of the same
ints, so the dispatch produces an identical hashable key without
rebuilding it.
_tensor_key(existing, unchanged) stays as theFakeTensor-dispatch entry. FakeTensors have SymInt sizes duringtracing, and
_hashable_dimsis the normalization that maps eachSymIntto(id(shape_env), expr)so two SymInts from differentshape envs don't accidentally collide.
The split happens at the
_specialization_extractorstable, so theright extractor is selected by a single dict lookup with no per-call
type check on the hot path.
Hash equality between the two extractors is verified by a test (see
test_fast_path_key_hash_matches_wrapped) so existing on-diskLooseAutotuneCacheKeyentries built before this change keepmatching.
Benchmarks (H100, vector_add at N=4096, cycling through 8 different
x/y tensors so the cache hits but never on the same args twice)
_base_specialization_keyin isolation (the dominant component ofKernel.bind()per-call cost):before: 2.76 us
after: 2.14 us
saving: -0.62 us (-22%)
End-to-end per-call timing at this stack position (Chunk D pool +
codegen rewrite applied, Phase 2 fast launcher not yet applied):
before (parent commit, debc08a): cpu_only=~16.0 us wall+sync=~16.0 us
after (this commit): cpu_only= 14.87 us wall+sync= 14.87 us
saving: ~-1.1 us/call
Tests
test/test_tensor_key_fast_path.pycovers:FakeTensor to the old path.
(cache-compat invariant).
torch.Size(not a wrapped plaintuple) when the kernel uses
static_shapes=True.bind()still returns the sameBoundKernelfor differenttensor objects with matching dtype/shape/stride, and distinguishes
different dtypes and shapes.