Fix fused_mla_rope_kv_split for v_dim == 0 - #6340
Open
htesd wants to merge 1 commit into
Open
Conversation
Two independent failures break v_dim == 0 (callers that only need the rotary-embedded key stream from the fused kernel): 1. Wrapper (sbhd): the value output (forward) and value gradient (backward) tensors have zero elements, so view(..., -1, ...) cannot infer the remaining dimension and raises. Use the explicit batch_size in the forward reshape and dk's flattened length in the backward reshape. The thd path derives shapes from cu_seqlens and is unaffected. 2. Triton kernels: the value load/store offsets are built with tl.arange(0, v_dim) unconditionally, and tl.arange requires end > start, so kernel specialization fails at compile time. Guard the value path behind the v_dim constexpr; for v_dim > 0 the kernel behavior is unchanged (the branch is resolved at compile time). Adds a v_dim == 0 case to the existing kv_split unit tests (covers both sbhd and thd input formats). Signed-off-by: iiap <1471127927@qq.com>
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.
What does this PR do?
fused_mla_rope_kv_splitfails whenv_dim == 0. This is a legitimateconfiguration for callers that only need the rotary-embedded key stream
from the fused kernel (e.g. compressed-attention paths that carry V
separately).
There are two independent failures:
Wrapper (sbhd): the value output (forward) and the value
gradient (backward) tensors have zero elements, so
view(..., -1, ...)cannot infer the remaining dimension and raisesRuntimeError: cannot reshape tensor of 0 elements .... Fixed byusing the explicit
batch_sizein the forward reshape anddk'sflattened length in the backward reshape. The thd path derives
shapes from
cu_seqlensand is unaffected.Triton kernels: the value load/store offsets are built with
tl.arange(0, v_dim)unconditionally, andtl.arangerequiresend > start, so kernel specialization fails at compile time withValueError: arange's end argument must be greater than the start argument. Fixed by guarding the value path behind thev_dimconstexpr — the branch is resolved at compile time, so for
v_dim > 0the generated kernel is unchanged.Tests
Adds a
v_dim == 0case to the existing kv_split forward/backwardparity tests in
tests/unit_tests/fusions/test_mla_yarn_rope_apply.py(covers both sbhd and thd input formats). The new case fails on current
dev (wrapper raises first; with the wrapper fixed, kernel
specialization still fails) and passes with this fix. The pre-existing
kv_split cases pass unchanged (verified on H200 / sm_90a).