Skip to content

[maxtext] Add generalized block-causal attention#4586

Open
ethannnnnn wants to merge 1 commit into
AI-Hypercomputer:mainfrom
ethannnnnn:block-diffusion-maxtext-pr1-attention
Open

[maxtext] Add generalized block-causal attention#4586
ethannnnnn wants to merge 1 commit into
AI-Hypercomputer:mainfrom
ethannnnnn:block-diffusion-maxtext-pr1-attention

Conversation

@ethannnnnn

Copy link
Copy Markdown

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

  • Add block_diffusion as a default-off attention type with a namespaced block-size setting.
  • Implement matching masks for dense attention, TPU Splash/Tokamax, packed sequences, and load-balanced context parallelism.
  • Preserve explicitly specialized attention layers and reject unsupported kernel combinations.

Design

For logical query position q, key position k, and block size B, attention is allowed when both positions belong to the same packed segment and q // 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=global remains 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

  • Attention suite: 42 passed; 37 device-dependent cases skipped.
  • Configuration suite: 18 passed plus 21 subtests.
  • Tokamax mask tests: 3 passed.
  • Pyink, YAML lint, and git diff --check passed.

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

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.
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@google-cla

google-cla Bot commented Jul 23, 2026

Copy link
Copy Markdown

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.

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.

1 participant