fix: compute local block padding for dynamic splash indexer mask in CP - #4950
Open
RexBearIU wants to merge 1 commit into
Open
fix: compute local block padding for dynamic splash indexer mask in CP#4950RexBearIU wants to merge 1 commit into
RexBearIU wants to merge 1 commit into
Conversation
RexBearIU
requested review from
NuojCheng,
RissyRan,
aireenmei,
bvandermoon,
gagika,
gobbleturk,
huytransformer,
igorts-git,
jiangjy1982,
parambole,
richjames0,
shralex,
shuningjin and
xibinliu
as code owners
August 20, 2026 03:36
There was a problem hiding this comment.
Code Review
This pull request updates the padding calculation for the Tokamax splash kernel in attention_op.py by aligning the query and key-value lengths to their respective block sizes (block_q and block_kv) before computing the padding widths. I have no feedback to provide as there are no review comments.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
RexBearIU
force-pushed
the
jackyf/fix-mla-indexer-cp
branch
from
August 24, 2026 07:57
48e5ccc to
ea0d06c
Compare
RexBearIU
force-pushed
the
jackyf/fix-mla-indexer-cp
branch
from
August 24, 2026 08:32
ea0d06c to
2cdd6c4
Compare
RexBearIU
requested review from
A9isha,
SurbhiJainUSC,
abhinavclemson,
darisoy,
dipannita08,
hengtaoguo,
khatwanimohit and
vipannalla
as code owners
August 24, 2026 08:32
dandragona
approved these changes
Aug 24, 2026
shuningjin
approved these changes
Aug 24, 2026
huytransformer
approved these changes
Aug 25, 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.
Description
Fixes an
AssertionErrorinMLATest.test_tpu_flash_attention_context_parallel_with_indexer(bothno_lb_cp2andlb_cp4_smallk) by properly computing local block-aligned padding for dynamic splash attention masks under context parallelism.Root Cause
Inside
wrap_flash_attentionunderjax.shard_map,indexer_maskis sharded across context devices along the query sequence dimensionQ_LENGTHinto shape(batch, q_local_len, kv_full_len)(e.g.[1, 128, 512]under CP=4 or[1, 256, 512]under CP=2).Previously,
pad_qwas computed usingmask_shape[0](the outer, global un-sharded sequence length 512):This over-padded the local query dimension of$512 \times 512$ mask for a 128 (or 256) token local shard.
indexer_maskwith hundreds ofFalserows back up to 512, creating aMachine-Level Compatibility
dq_reduction_steps=3withq.shape[1], causing trailing mask rows to be benignly ignored in some configurations but prone to subtle stride/allocation issues.padded_q_lenandpadded_kv_lenusingsa_config.block_qandsa_config.block_kvmultiples of the localindexer_maskshape (indexer_mask.shape[-2]andindexer_mask.shape[-1]):Tests
--xla_force_host_platform_device_count=8):MLATest.test_tpu_flash_attention_context_parallel_with_indexer_no_lb_cp2→PASSMLATest.test_tpu_flash_attention_context_parallel_with_indexer_lb_cp4_smallk→PASSMLATest.test_tpu_dot_product_context_parallel_with_indexer→PASSMLATest.test_tpu_flash_attention_ring_context_parallel_with_indexer→PASScodespell,pylint,pyink) passed cleanly.Checklist
gemini-reviewlabel.