DSV4: Add mask hoisting, boolean splash masks, and thresholded indexer membership - #4914
Open
systalyze-ai wants to merge 2 commits into
Open
Conversation
systalyze-ai
requested review from
A9isha,
NuojCheng,
RissyRan,
SurbhiJainUSC,
abhinavclemson,
aireenmei,
bvandermoon,
darisoy,
dipannita08,
gagika,
gobbleturk,
hengtaoguo,
huytransformer,
igorts-git,
jiangjy1982,
khatwanimohit,
parambole,
richjames0,
shralex,
shuningjin,
vipannalla and
xibinliu
as code owners
August 17, 2026 16:32
There was a problem hiding this comment.
Code Review
This pull request introduces several optimizations for DeepSeek-V4 compressed attention on TPU. It adds configuration flags and implementations to route COMPRESSED and LOCAL_SLIDING train attention to the tokamax dynamic splash kernel, keep compressed masks boolean end-to-end, hoist layer-invariant mask tensors to be built once per train step, and compute CSA indexer selections via a boolean threshold membership mask. Corresponding unit tests have been added to verify the correctness and parity of these new masking paths. There are no review comments, so no further feedback is provided.
4 tasks
…ash kernels Opt-in TPU path (compressed_use_dynamic_splash) that avoids materializing dense seq^2 logits. At seq 16384 the dense path needs 96.8 GiB per chip and does not compile on v6e. Co-authored-by: Sudarsanan <[email protected]> Co-authored-by: Armin <[email protected]> Co-authored-by: utlz <[email protected]>
…ership for DeepSeek-V4 Build the layer-invariant masks once per step, keep them boolean on the dynamic-splash path, and select the indexer top-k by thresholding against the k-th value. Selected sets and masks are unchanged, including top_k's tie semantics. Measured together: 9.98 to 8.75 s/step (1.14x) on v6e-128 DeepSeek-V4 LoRA at seq 16384. Co-authored-by: Sudarsanan <[email protected]> Co-authored-by: Armin <[email protected]> Co-authored-by: utlz <[email protected]>
systalyze-ai
force-pushed
the
upstream-pr/hoisted-bool-attention-masks
branch
from
August 17, 2026 18:09
e6a245d to
f82ff27
Compare
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
Stacked on #4908 (the splash attention PR); the diff includes its commit until it merges. Review the top commit.
Adds three opt-in DeepSeek-V4 mask optimizations for the dynamic-splash training path. Static causal, segment, and uncompressed prefix masks are built before the layer scan and reused by compressed-attention layers and rematerialized calls.
Adds boolean compressed masks from the HCA and CSA compressors through splash mask construction, and lets the CSA indexer return threshold-based membership without the one-hot expansion. The threshold path follows
jax.lax.top_kordering at boundary ties, including lower-index and signed-zero ordering.Performance
Step time improved from 9.98 to 8.75 s/step (1.14x) with
hoist_static_attention_masks,splash_bool_masks, andindexer_threshold_membershiptoggled on.Reproduction setup: v6e-128, DeepSeek-V4-Flash 284B, LoRA fine-tuning,
ici_expert_parallelism=16,ici_tensor_parallelism=8,ici_fsdp_parallelism=1,max_target_length=16384,per_device_batch_size=0.125(global batch 16),LIBTPU_INIT_ARGS=--xla_tpu_scoped_vmem_limit_kib=98304, with the dynamic-splash attention path enabled and the three flags toggled off versus on.Tests
PYTHONPATH=$PWD/src JAX_PLATFORMS=cpu /home/jeremy/git/maxtext-16kmem/.venv/bin/python3 -m pytest -q tests/unit/deepseek_v4_mask_flags_test.py— 15 passed.jax.lax.top_klower-index and signed-zero ordering, while the parity tests compare hoisted, boolean, and threshold-membership masks with their default-path forms.Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.