Skip to content

DSV4: Add mask hoisting, boolean splash masks, and thresholded indexer membership - #4914

Open
systalyze-ai wants to merge 2 commits into
AI-Hypercomputer:mainfrom
systalyze-ai:upstream-pr/hoisted-bool-attention-masks
Open

DSV4: Add mask hoisting, boolean splash masks, and thresholded indexer membership#4914
systalyze-ai wants to merge 2 commits into
AI-Hypercomputer:mainfrom
systalyze-ai:upstream-pr/hoisted-bool-attention-masks

Conversation

@systalyze-ai

Copy link
Copy Markdown

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_k ordering 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, and indexer_threshold_membership toggled 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.
  • The tie canary pins jax.lax.top_k lower-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):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

jcarin-sys and others added 2 commits August 17, 2026 18:08
…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
systalyze-ai force-pushed the upstream-pr/hoisted-bool-attention-masks branch from e6a245d to f82ff27 Compare August 17, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants