Repository navigation
Conversation
_try_reorder_loops_for_candidates picks the largest common buffer to guide loop reordering. When a shared read (e.g., the input tensor) is larger than a write→read dep (e.g., the reduction output), it gets picked. If the shared read has a num_vars mismatch that normalizes away, the function returns a positive score that short-circuits the reindexing fallback in score_fusion_can_reorder_v2 — even though the write→read dep has a factorization mismatch that only reindexing can fix. This manifests in FP8 grouped quantization patterns where reshape changes the iteration domain (e.g., [8, 7168] vs [448, 128]). The reduction and pointwise share the input tensor (large, normalizes to match) but the reduction output (small, different factorization) blocks can_fuse_vertical. Two changes to _try_reorder_loops_for_candidates: 1. Prefer write→read deps over shared reads when selecting the candidate to guide reordering, since write→read deps determine whether can_fuse_vertical will pass. 2. When a write→read dep fails normalize_with_stride_order, check whether the write's dimension sizes appear in the read's sizes. If not, the mismatch is a factorization issue (not a dimension order issue) that reordering cannot fix — return -1 to let the reindexing fallback handle it. Authored with Claude. [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/179090
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 13e7be6 with merge base 58e3fb0 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
…lection" _try_reorder_loops_for_candidates picks the largest common buffer to guide loop reordering. When a shared read (e.g., the input tensor) is larger than a write→read dep (e.g., the reduction output), it gets picked. If the shared read has a num_vars mismatch that normalizes away, the function returns a positive score that short-circuits the reindexing fallback in score_fusion_can_reorder_v2 — even though the write→read dep has a factorization mismatch that only reindexing can fix. This manifests in FP8 grouped quantization patterns where reshape changes the iteration domain (e.g., [8, 7168] vs [448, 128]). The reduction and pointwise share the input tensor (large, normalizes to match) but the reduction output (small, different factorization) blocks can_fuse_vertical. Two changes to _try_reorder_loops_for_candidates: 1. Prefer write→read deps over shared reads when selecting the candidate to guide reordering, since write→read deps determine whether can_fuse_vertical will pass. 2. When a write→read dep fails normalize_with_stride_order, check whether the write's dimension sizes appear in the read's sizes. If not, the mismatch is a factorization issue (not a dimension order issue) that reordering cannot fix — return -1 to let the reindexing fallback handle it. Authored with Claude. [ghstack-poisoned]
…lection" _try_reorder_loops_for_candidates picks the largest common buffer to guide loop reordering. When a shared read (e.g., an input to both kernels) is larger than a write→read dep, it gets picked. Instead, we should prioritize based on the dependencies that are blocking fusion. This pr prioritizes those dependencies, and detects when loop re-ordering will not be able to successfully fix a failed fusion. In this case we do not reorder the node’s loops. Loop ordering after fusion was interfering with loop reindexing. Potential other approaches would be either saving a pre-modified node prior to loop reordering, or, finding a way to reverse the transformation. This fixes an fp8 grouped quantization fusion where reshape changes the iteration domain (e.g., [8, 7168] vs [448, 128]). The reduction and pointwise share the input tensor (large, normalizes to match) but the reduction output (small, different factorization) blocks can_fuse_vertical. Authored with Claude. [ghstack-poisoned]
…lection" _try_reorder_loops_for_candidates picks the largest common buffer to guide loop reordering. When a shared read (e.g., an input to both kernels) is larger than a write→read dep, it gets picked. Instead, we should prioritize based on the dependencies that are blocking fusion. This pr prioritizes those dependencies, and detects when loop re-ordering will not be able to successfully fix a failed fusion. In this case we do not reorder the node’s loops. Loop ordering after fusion was interfering with loop reindexing. Potential other approaches would be either saving a pre-modified node prior to loop reordering, or, finding a way to reverse the transformation. This fixes an fp8 grouped quantization fusion where reshape changes the iteration domain (e.g., [8, 7168] vs [448, 128]). The reduction and pointwise share the input tensor (large, normalizes to match) but the reduction output (small, different factorization) blocks can_fuse_vertical. Authored with Claude. [ghstack-poisoned]
…lection" _try_reorder_loops_for_candidates picks the largest common buffer to guide loop reordering. When a shared read (e.g., an input to both kernels) is larger than a write→read dep, it gets picked. Instead, we should prioritize based on the dependencies that are blocking fusion. This pr prioritizes those dependencies, and detects when loop re-ordering will not be able to successfully fix a failed fusion. In this case we do not reorder the node’s loops. Loop ordering after fusion was interfering with loop reindexing. Potential other approaches would be either saving a pre-modified node prior to loop reordering, or, finding a way to reverse the transformation. This fixes an fp8 grouped quantization fusion where reshape changes the iteration domain (e.g., [8, 7168] vs [448, 128]). The reduction and pointwise share the input tensor (large, normalizes to match) but the reduction output (small, different factorization) blocks can_fuse_vertical. Authored with Claude. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo [ghstack-poisoned]
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Pointwise cat evaluates every input's computation for each output element (masked), so fusing reductions in is normally wasteful. When cat inputs just recombine a reduction's output (e.g. qknorm → RoPE → cat), no computation is duplicated — exclude that specific reduction from the guard so pointwise cat can enable fusion. Authored with Claude. Pull Request resolved: #179091 Approved by: https://github.com/PaulZhang12 ghstack dependencies: #176927, #179090
…torch#179090) _try_reorder_loops_for_candidates picks the largest common buffer to guide loop reordering. When a shared read (e.g., an input to both kernels) is larger than a write→read dep, it gets picked. Instead, we should prioritize based on the dependencies that are blocking fusion. This pr prioritizes those dependencies, and detects when loop re-ordering will not be able to successfully fix a failed fusion. In this case we do not reorder the node’s loops. Loop ordering after fusion was interfering with loop reindexing. Potential other approaches would be either saving a pre-modified node prior to loop reordering, or, finding a way to reverse the transformation. This fixes an fp8 grouped quantization fusion where reshape changes the iteration domain (e.g., [8, 7168] vs [448, 128]). The reduction and pointwise share the input tensor (large, normalizes to match) but the reduction output (small, different factorization) blocks can_fuse_vertical. Authored with Claude. Pull Request resolved: pytorch#179090 Approved by: https://github.com/shunting314 ghstack dependencies: pytorch#176927
…9091) Pointwise cat evaluates every input's computation for each output element (masked), so fusing reductions in is normally wasteful. When cat inputs just recombine a reduction's output (e.g. qknorm → RoPE → cat), no computation is duplicated — exclude that specific reduction from the guard so pointwise cat can enable fusion. Authored with Claude. Pull Request resolved: pytorch#179091 Approved by: https://github.com/PaulZhang12 ghstack dependencies: pytorch#176927, pytorch#179090
…torch#179090) _try_reorder_loops_for_candidates picks the largest common buffer to guide loop reordering. When a shared read (e.g., an input to both kernels) is larger than a write→read dep, it gets picked. Instead, we should prioritize based on the dependencies that are blocking fusion. This pr prioritizes those dependencies, and detects when loop re-ordering will not be able to successfully fix a failed fusion. In this case we do not reorder the node’s loops. Loop ordering after fusion was interfering with loop reindexing. Potential other approaches would be either saving a pre-modified node prior to loop reordering, or, finding a way to reverse the transformation. This fixes an fp8 grouped quantization fusion where reshape changes the iteration domain (e.g., [8, 7168] vs [448, 128]). The reduction and pointwise share the input tensor (large, normalizes to match) but the reduction output (small, different factorization) blocks can_fuse_vertical. Authored with Claude. Pull Request resolved: pytorch#179090 Approved by: https://github.com/shunting314 ghstack dependencies: pytorch#176927
…9091) Pointwise cat evaluates every input's computation for each output element (masked), so fusing reductions in is normally wasteful. When cat inputs just recombine a reduction's output (e.g. qknorm → RoPE → cat), no computation is duplicated — exclude that specific reduction from the guard so pointwise cat can enable fusion. Authored with Claude. Pull Request resolved: pytorch#179091 Approved by: https://github.com/PaulZhang12 ghstack dependencies: pytorch#176927, pytorch#179090
…torch#179090) _try_reorder_loops_for_candidates picks the largest common buffer to guide loop reordering. When a shared read (e.g., an input to both kernels) is larger than a write→read dep, it gets picked. Instead, we should prioritize based on the dependencies that are blocking fusion. This pr prioritizes those dependencies, and detects when loop re-ordering will not be able to successfully fix a failed fusion. In this case we do not reorder the node’s loops. Loop ordering after fusion was interfering with loop reindexing. Potential other approaches would be either saving a pre-modified node prior to loop reordering, or, finding a way to reverse the transformation. This fixes an fp8 grouped quantization fusion where reshape changes the iteration domain (e.g., [8, 7168] vs [448, 128]). The reduction and pointwise share the input tensor (large, normalizes to match) but the reduction output (small, different factorization) blocks can_fuse_vertical. Authored with Claude. Pull Request resolved: pytorch#179090 Approved by: https://github.com/shunting314 ghstack dependencies: pytorch#176927
…9091) Pointwise cat evaluates every input's computation for each output element (masked), so fusing reductions in is normally wasteful. When cat inputs just recombine a reduction's output (e.g. qknorm → RoPE → cat), no computation is duplicated — exclude that specific reduction from the guard so pointwise cat can enable fusion. Authored with Claude. Pull Request resolved: pytorch#179091 Approved by: https://github.com/PaulZhang12 ghstack dependencies: pytorch#176927, pytorch#179090
Stack from ghstack (oldest at bottom):
_try_reorder_loops_for_candidates picks the largest common buffer to guide loop reordering. When a shared read (e.g., an input to both kernels) is larger than a write→read dep, it gets picked. Instead, we should prioritize based on the dependencies that are blocking fusion.
This pr prioritizes those dependencies, and detects when loop re-ordering will not be able to successfully fix a failed fusion. In this case we do not reorder the node’s loops. Loop ordering after fusion was interfering with loop reindexing. Potential other approaches would be either saving a pre-modified node prior to loop reordering, or, finding a way to reverse the transformation.
This fixes an fp8 grouped quantization fusion where reshape changes the iteration domain (e.g., [8, 7168] vs [448, 128]). The reduction and pointwise share the input tensor (large, normalizes to match) but the reduction output (small, different factorization) blocks can_fuse_vertical.
Authored with Claude.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo