[maxtext] Add generalized block-causal attention#4586
Open
ethannnnnn wants to merge 1 commit into
Open
Conversation
Add block_diffusion as a default-off attention type with one namespaced block-size setting. Resolve it in the shared attention layer so ordinary global layers need no model-name dispatch while explicit specialized attention remains intact. Implement matching dense, Splash, Tokamax, packed-sequence, and load-balanced context-parallel masks. Preserve the autoregressive path and support partial final blocks. Tests: attention 42 passed/37 skipped; config 18 passed plus 21 subtests; Tokamax 3 passed; pyink, yamllint, git diff --check.
ethannnnnn
requested review from
RissyRan,
gobbleturk,
jiangjy1982,
parambole,
shuningjin and
suexu1025
as code owners
July 23, 2026 22:44
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
ethannnnnn
requested review from
NuojCheng,
abhinavclemson,
aireenmei,
bvandermoon,
gagika,
huytransformer,
igorts-git,
khatwanimohit,
richjames0,
shralex and
xibinliu
as code owners
July 23, 2026 22:44
ethannnnnn
requested review from
A9isha,
SurbhiJainUSC,
darisoy,
dipannita08,
hengtaoguo and
vipannalla
as code owners
July 23, 2026 22:44
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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
Block-diffusion models require bidirectional attention within a block and causal visibility across blocks. This should be a declared attention capability, not a model-name branch, and it must leave ordinary causal models unchanged.
Scope
block_diffusionas a default-off attention type with a namespaced block-size setting.Design
For logical query position
q, key positionk, and block sizeB, attention is allowed when both positions belong to the same packed segment andq // B >= k // B. This produces a dense rectangle within the current block while preventing visibility into future blocks. The shared attention boundary applies this rule only to default/global attention; local, full, vision, and other explicit layer policies retain their existing behavior.Logical positions and segment IDs remain the source of truth after context-parallel reordering. Partial final blocks are valid.
Compatibility
attention_type=globalremains the default, so causal masks and autoregressive decode are unchanged unless block diffusion is explicitly selected. This PR adds no training objective, mask token, rollout, or model-specific activation.Extensibility
Later training and generation integrations can consume one attention capability and block-size contract. Supporting another block-diffusion model does not require adding its name to the attention stack.
Tests
git diff --checkpassed.Known limitations
GPU flash/CuDNN combinations that cannot express the block-causal mask are rejected rather than silently falling back to different semantics.
Stack
First PR in this repository stack; no preceding PR dependency.
MaxText block-diffusion design document