Fix transpose kernels to use actual tensor strides - #1631
Merged
Merged
Conversation
…ose_query/output_gluon - Replace hardcoded stride calculations with tensor.stride() calls - Update both JIT and AOT versions of transpose_query_gluon and transpose_output_gluon - Add more test configurations for various batch sizes and seq lengths
fsx950223
approved these changes
Dec 13, 2025
valarLip
approved these changes
Dec 14, 2025
zhuyuhua-v
pushed a commit
that referenced
this pull request
Dec 17, 2025
* Use actual tensor strides to support non-contiguous tensors in transpose_query/output_gluon - Replace hardcoded stride calculations with tensor.stride() calls - Update both JIT and AOT versions of transpose_query_gluon and transpose_output_gluon - Add more test configurations for various batch sizes and seq lengths * move debug code
ZhangLirong-amd
pushed a commit
that referenced
this pull request
Dec 29, 2025
* Use actual tensor strides to support non-contiguous tensors in transpose_query/output_gluon - Replace hardcoded stride calculations with tensor.stride() calls - Update both JIT and AOT versions of transpose_query_gluon and transpose_output_gluon - Add more test configurations for various batch sizes and seq lengths * move debug code
valarLip
pushed a commit
that referenced
this pull request
Mar 18, 2026
* Use actual tensor strides to support non-contiguous tensors in transpose_query/output_gluon - Replace hardcoded stride calculations with tensor.stride() calls - Update both JIT and AOT versions of transpose_query_gluon and transpose_output_gluon - Add more test configurations for various batch sizes and seq lengths * move debug code
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.
Motivation
The current implementation of
transpose_query_gluonandtranspose_output_gluonkernels assumes that input and output tensors are always contiguous in memory. Stride calculations are hardcoded based on tensor dimensions (e.g.,num_kv_heads * query_group_size * head_size), which fails when tensors are non-contiguous (e.g., after slicing, transposing, or view operations). This PR fixes the stride calculation to support non-contiguous tensors by using actual tensor strides viatensor.stride().Technical Details
Modified stride calculations in
transpose_query_gluon:query.stride(0),query.stride(1), etc.stride_input_batch = query_sequence_length * query_stride_0query_gluon.stride(0)andquery_gluon.stride(1)directlyModified stride calculations in
transpose_output_gluon:output_gluon.stride(0)andoutput_gluon.stride(1)output.stride(0)andoutput.stride(1)directlyUpdated AOT (Ahead-of-Time) compilation versions:
transpose_query_gluon_aotandtranspose_output_gluon_aotintranspose_query_output_gluon_aot.pyTest Plan
test_transpose_query_output_gluon.pyto cover more parameter combinations:include_scale=Truefor float16, bfloat16, and float8_e4m3fnuz dtypesTest Result
All test configurations pass, verifying that:
include_scale=TrueSubmission Checklist