> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sglang.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Attention Backends

> Select and configure attention backends for SGLang diffusion pipelines.

This document describes the attention backends available in sglang diffusion (`sglang.multimodal_gen`) and how to select them.

## Overview

Attention backends are defined by `AttentionBackendEnum` (`sglang.multimodal_gen.runtime.platforms.interface.AttentionBackendEnum`) and selected via the CLI flag `--attention-backend`.

Backend selection is performed by the shared attention layers (e.g. `LocalAttention` / `USPAttention` / `UlyssesAttention` in `sglang.multimodal_gen.runtime.layers.attention.layer`). `--attention-backend` is strict for the diffusion transformer / DiT. Auxiliary components such as encoders and VAEs use it when compatible, then fall back to a component default or a platform-compatible backend. Use `--component-attention-backends` when an auxiliary component must use a specific backend; incompatible overrides, including an override for a component that constructs no SGLang attention layer, fail unless a sparse backend is being replaced for cross-attention. A component key may carry a `.self` or `.cross` role suffix to override just one kind of attention; see [Per-role overrides](#per-role-overrides).

When using the diffusers backend, `--attention-backend` is passed through to diffusers'
`set_attention_backend` (e.g., `flash`, `_flash_3_hub`, `sage`, `xformers`, `native`).

* **CUDA**: prefers FlashAttention (FA3/FA4) when supported; otherwise falls back to PyTorch SDPA. On SM100/SM103 (B200/B300), dense non-causal fp16/bf16 native attention prefers cuDNN SDPA and falls back to FA4 if cuDNN has no compatible kernel.
* **ROCm**: on Instinct (CDNA, gfx9) GPUs, defaults to `aiter` when `--attention-backend` is not set; on Radeon (RDNA) GPUs, use `torch_sdpa`. `aiter_sage`, `aiter_quant` and `torch_sdpa` can be selected explicitly. FlashAttention dispatches through FA3, which is CUDA-only, so `fa` falls back to PyTorch SDPA on ROCm.
* **Intel XPU**: uses XPU Flash Attention backend (fp16/bf16, head sizes 64/96/128/192/256); otherwise falls back to PyTorch SDPA.
* **MUSA**: uses FlashAttention when available; also supports Sage Attention when installed; otherwise falls back to PyTorch SDPA.
* **MPS**: always uses PyTorch SDPA.
* **NPU**: for ring attention uses FA otherwise uses PyTorch SDPA.
* **CPU**: uses `amx_attn` when the CPU supports AMX, the dtype is bf16/fp16, and the head size is even; otherwise PyTorch SDPA.

On Blackwell, `dynamic_cudnn_sdpa` keeps FA4 for attention with one side shorter than 128 tokens and the other at least 128 during breakable CUDA graph warmup/capture. In eager execution, `lossless` and `high` requests use cuDNN for these shapes to avoid FA4 host-dispatch overhead; `exact` keeps the reference FA4 route. Switching backends can change floating-point rounding.

## Backend options

For SGLang-native pipelines, the CLI accepts the lowercase names of `AttentionBackendEnum`. The table below lists the backends implemented by the built-in platforms. `fa3`/`fa4` are accepted as aliases for `fa`.

<table>
  <colgroup>
    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>CLI value</th>
      <th>Enum value</th>
      <th>Notes</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`flashinfer_fa2`</td>
      <td>`FLASHINFER_FA2`</td>
      <td>FlashInfer's FA2 implementation.</td>
    </tr>

    <tr>
      <td>`fa` / `fa3` / `fa4`</td>
      <td>`FA`</td>
      <td>FlashAttention. `fa3/fa4` are normalized to `fa` during argument parsing (`ServerArgs.post_init`). On Ascend NPU, `fa` selects Ascend FA and supports [quantized attention through MindIE-SD](#ascend-quantized-attention-with-mindie-sd).</td>
    </tr>

    <tr>
      <td>`fa2`</td>
      <td>`FA2`</td>
      <td>FlashAttention 2. CUDA-only; requires the `flash-attn` package.</td>
    </tr>

    <tr>
      <td>`torch_sdpa`</td>
      <td>`TORCH_SDPA`</td>
      <td>PyTorch `scaled_dot_product_attention`.</td>
    </tr>

    <tr>
      <td>`torch_cudnn_sdpa` / `cudnn_sdpa`</td>
      <td>`TORCH_CUDNN_SDPA`</td>
      <td>PyTorch SDPA forced to the cuDNN kernel. CUDA-only. `cudnn_sdpa` is normalized to `torch_cudnn_sdpa`.</td>
    </tr>

    <tr>
      <td>`dynamic_cudnn_sdpa`</td>
      <td>`DYNAMIC_CUDNN_SDPA`</td>
      <td>cuDNN SDPA with a FlashAttention fallback for causal or unsupported shapes and cuDNN runtime errors. CUDA-only. Selected automatically for dense non-causal fp16/bf16 attention on SM100 / SM103 (B200 / B300) when no backend is set and FlashAttention is usable.</td>
    </tr>

    <tr>
      <td>`sliding_tile_attn`</td>
      <td>`SLIDING_TILE_ATTN`</td>
      <td>Sliding Tile Attention (STA). Requires `st_attn`. Configure via `--attention-backend-config`.</td>
    </tr>

    <tr>
      <td>`sage_attn`</td>
      <td>`SAGE_ATTN`</td>
      <td>Requires `sageattention`. On Hopper (SM90), PyPI `sageattention==2.2.0` is unsupported because it lacks the upstream SM90 binding fix. Install `pip install --force-reinstall git+https://github.com/thu-ml/SageAttention.git@d9704247a5139ab4c03bf7fc6b35cc0e2cbb5ea4 --no-build-isolation`. Upstream SageAttention CUDA extensions target SM80/SM86/SM89/SM90/SM120; see upstream `setup.py`.</td>
    </tr>

    <tr>
      <td>`sage_attn_3`</td>
      <td>`SAGE_ATTN_3`</td>
      <td>Requires SageAttention3 installed per upstream instructions.</td>
    </tr>

    <tr>
      <td>`sparge_attn`</td>
      <td>`SPARGE_ATTN`</td>
      <td>Training-free sparse SageAttention2. CUDA SM80/86/87/89/90, FP16/BF16, head dim 64/128, and square self-attention with sequence length at least 128. Other attention shapes use dense SDPA. Install `pip install git+https://github.com/thu-ml/SpargeAttn.git --no-build-isolation`; configure retained block ratio with `topk`.</td>
    </tr>

    <tr>
      <td>`sol_attn`</td>
      <td>`SOL_ATTN`</td>
      <td>Requires the upstream `sol-attn` package. Install with `pip install git+https://github.com/NVlabs/Sana.git@sol-engine#subdirectory=techniques/sparse_backends`. BF16, head dim 128. Configure via `--attention-backend-config`.</td>
    </tr>

    <tr>
      <td>`video_sparse_attn`</td>
      <td>`VIDEO_SPARSE_ATTN`</td>
      <td>Requires `vsa`. Configure `sparsity` via `--attention-backend-config`.</td>
    </tr>

    <tr>
      <td>`subblock_sparse_attn`</td>
      <td>`SUBBLOCK_SPARSE_ATTN`</td>
      <td>Training-free SubBlock sparsity for MiniMax-H3 on CUDA SM90, SM100, and SM120. The default compute mode is BF16; `compute_mode=sage_fp8` is an approximate path on SM90 (requires `SpargeAttn`) and SM120 (uses FlashInfer's CuTe-DSL SM120 Sage kernel). See the [MiniMax-H3 recipe](https://docs.sglang.io/cookbook/diffusion/MiniMax/MiniMax-H3.md#subblock-sparse-attention).</td>
    </tr>

    <tr>
      <td>`cube_sparse_attn`</td>
      <td>`CUBE_SPARSE_ATTN`</td>
      <td>MiniMax-H3 cube sparse attention: TopK sparsity over H3's 3D visual streams, built on PyTorch FlexAttention. CUDA-only. Requires `local_cube_size` and `topk_ratio_list` in `--attention-backend-config`. See the [MiniMax-H3 recipe](https://docs.sglang.io/cookbook/diffusion/MiniMax/MiniMax-H3.md).</td>
    </tr>

    <tr>
      <td>`video_sparse_attn_h3`</td>
      <td>`VIDEO_SPARSE_ATTN_H3`</td>
      <td>Video Sparse Attention for MiniMax-H3 / FastH3 (VSA-H3). In-tree kernels, no external package: FastVideo's native tcgen05 block-sparse forward on SM100 / SM103, the Triton tile-64 kernel on SM80 / SM90. Configure via `--attention-backend-config`.</td>
    </tr>

    <tr>
      <td>`hybrid_window_attn_h3`</td>
      <td>`HYBRID_WINDOW_ATTN_H3`</td>
      <td>VDN-H3 hybrid attention: chunk-aligned window softmax (exact, gated) plus the Video Delta linear branch over the window complement. The window runs as a union of FlashAttention varlen calls (FA4 on SM100 / SM103 / SM120, FA3 on SM90; on SM80 / SM86 / SM89 the same FA3 build runs its Sm80 mainloop at FA2-class speed). Configure via `--attention-backend-config`.</td>
    </tr>

    <tr>
      <td>`vmoba_attn`</td>
      <td>`VMOBA_ATTN`</td>
      <td>Requires `flash-attn` >= 2.7.1. Configure via `--attention-backend-config`.</td>
    </tr>

    <tr>
      <td>`aiter`</td>
      <td>`AITER`</td>
      <td>Requires `aiter`.</td>
    </tr>

    <tr>
      <td>`aiter_sage`</td>
      <td>`AITER_SAGE`</td>
      <td>Requires `aiter`.</td>
    </tr>

    <tr>
      <td>`aiter_quant`</td>
      <td>`AITER_QUANT`</td>
      <td>Quantized AITER MHA v4 family. Requires `SGLANG_USE_AITER=1` and an `aiter` that ships `aiter.ops.mha_v4`. gfx950 (gfx942 supports `i8fp8` / `fp8` only). head\_dim 128, non-causal. Pick the quant format with `--attention-backend-config format=<name>`: `bf16fp8`, `i8fp8`, `fp8`, `mxfp8`, `mxfp6`, `mxfp4` (default `fp8`); see [Configuration](#supported-configuration-parameters) for what each one does.</td>
    </tr>

    <tr>
      <td>`sla_attn`</td>
      <td>`SLA_ATTN`</td>
      <td>Sparse Linear Attention. Requires `SpargeAttn`. Install with `pip install git+https://github.com/thu-ml/SpargeAttn.git --no-build-isolation`.</td>
    </tr>

    <tr>
      <td>`sage_sla_attn`</td>
      <td>`SAGE_SLA_ATTN`</td>
      <td>SageAttention + Sparse Linear Attention. Requires `SpargeAttn` (same install as SLA).</td>
    </tr>

    <tr>
      <td>`sparse_video_gen_2_attn`</td>
      <td>`SPARSE_VIDEO_GEN_2_ATTN`</td>
      <td>Requires `svg`. See installation instructions at [https://github.com/svg-project/Sparse-VideoGen](https://github.com/svg-project/Sparse-VideoGen).</td>
    </tr>

    <tr>
      <td>`laser_attn`</td>
      <td>`LASER_ATTN`</td>
      <td>Requires `attentions` which can be installed with `sgl_kernel_npu`; available only for NPU.</td>
    </tr>

    <tr>
      <td>`block_sparse_attn`</td>
      <td>`BLOCK_SPARSE_ATTN`</td>
      <td>Requires `attentions` which can be installed with `sgl_kernel_npu`; available only for NPU.</td>
    </tr>

    <tr>
      <td>`rain_fusion_attn`</td>
      <td>`RAIN_FUSION_ATTN`</td>
      <td>Requires `attentions` which can be installed with `sgl_kernel_npu`; available only for NPU.</td>
    </tr>

    <tr>
      <td>`fp8_fa_sm120`</td>
      <td>`FP8_FA_SM120`</td>
      <td>FP8 (E4M3) dense attention for SM120/SM121 GPUs (GeForce RTX 50, RTX PRO Blackwell, DGX Spark GB10), written in CuTe-DSL. Q/K/V are quantized per head on the fly; the output stays BF16. Non-causal, batch 1, head dim 128, BF16 inputs; other calls use `torch_cudnn_sdpa`. Opt-in only: outputs differ from BF16 attention by about 5% relative RMS per call on random normal inputs. Each new sequence length compiles once (about 10 s).</td>
    </tr>

    <tr>
      <td>`amx_attn`</td>
      <td>`AMX_ATTN`</td>
      <td>Intel AMX attention for CPU. Requires an AMX-capable CPU, bf16/fp16, and an even head size; selected automatically on CPU when usable.</td>
    </tr>
  </tbody>
</table>

## Selection priority

The selection order in `runtime/layers/attention/selector.py` is:

1. `global_force_attn_backend(...)` / `global_force_attn_backend_context_manager(...)`
2. Component *and role* override from `--component-attention-backends.<component>.<role>` while that component is being constructed
3. Component override from `--component-attention-backends` while that component is being constructed
4. CLI `--attention-backend` (`ServerArgs.attention_backend`)
5. Layer or component default, when declared
6. Auto selection (platform capability, dtype, and installed packages)

An explicit global backend mismatch fails for DiT self-attention. Auxiliary
components may fall back to their declared default or another compatible backend.
Sparse backends selected for self-attention similarly fall back to a compatible
dense backend for cross-attention. Explicit component overrides are otherwise
strict.

### Per-role overrides

A role is the kind of attention a layer performs: `self` or `cross`. Appending
a role to a component key selects a backend for just that role, which is useful
when a quantized or otherwise expensive backend pays off for self-attention but
not for the much lighter cross-attention:

```bash Command theme={null}
sglang generate \
  --model-path <MODEL_PATH_OR_ID> \
  --component-attention-backends.transformer.self sage_attn \
  --component-attention-backends.transformer.cross fa
```

A role override outranks the component-wide backend for layers of that role and
leaves the other role alone. Layers of a role with no override fall through to
the component-wide backend as usual, and `<component>_2` inherits
`<component>`'s role overrides unless it declares its own.

Role overrides are as strict as component-wide ones: a role override that never
reaches a layer fails the load, including when the component builds no layers of
that role at all. The one tolerated divergence is the shared sparse rule above —
a sparse backend named for `cross` is replaced by a compatible dense backend and
logged, rather than failing.

Model and layer backend sets guide automatic selection; they are not positive
allowlists for explicit requests. A backend selected with
`--attention-backend` or `--component-attention-backends` can therefore be used
without first adding it to every model's set. It still fails closed when the
platform cannot resolve it or when it lacks a required operation such as dense
cross-attention, packed variable-length attention, or ring-attention LSE.
Model paths that require one backend for correctness declare it as required;
those layers keep that backend even when the surrounding component is
overridden.

For an automatic, measurement-based choice, pass
`--enable-attention-backend-autotune true`. On each layer's first sufficiently
large input, the native runtime times compatible candidates and switches only
when the output remains within its numerical guard and the measured gain exceeds
the noise margin. The tuner is disabled by default and currently validated on
SM90 and SM12x. It does not replace a backend selected explicitly through
`--attention-backend` or `--component-attention-backends`, or a backend required
by the model for correctness.

## Configuration

Some backends require additional configuration. You can pass these parameters via `--attention-backend-config`. This argument accepts:

* A path to a JSON or YAML configuration file.
* A JSON string (e.g., `'&#123;"sparsity": 0.5&#125;'`).
* Key-value pairs (e.g., `"sparsity=0.5,enable_x=true"`).

The key-value form splits on commas, so list values (for example Sol-Attn `dense_layers=0,1` or VSA-H3 `vsa_dense_layers`) must use the JSON or file form, e.g. `'&#123;"dense_layers": "0,1"&#125;'` for Sol-Attn or `'&#123;"vsa_dense_layers": [0, 1]&#125;'` for VSA-H3 (a JSON list, not a string). Sol-Attn also accepts ranges such as `dense_layers=0-1`.

### Supported Configuration Parameters

**Sliding Tile Attention (`sliding_tile_attn`)**

<table>
  <colgroup>
    <col />

    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Parameter</th>
      <th>Type</th>
      <th>Description</th>
      <th>Default</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`mask_strategy_file_path`</td>
      <td>`str`</td>
      <td>**Required.** Path to the mask strategy JSON file.</td>
      <td>-</td>
    </tr>

    <tr>
      <td>`STA_mode`</td>
      <td>`str`</td>
      <td>**Required.** Mode of STA: `STA_INFERENCE`, `STA_SEARCHING`, `STA_TUNING`, or `STA_TUNING_CFG`.</td>
      <td>-</td>
    </tr>

    <tr>
      <td>`skip_time_steps`</td>
      <td>`int`</td>
      <td>Number of steps to use full attention before switching to sparse attention. Required for the `STA_TUNING` and `STA_TUNING_CFG` modes; ignored otherwise.</td>
      <td>-</td>
    </tr>
  </tbody>
</table>

**Video Sparse Attention (`video_sparse_attn`)**

<table>
  <colgroup>
    <col />

    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Parameter</th>
      <th>Type</th>
      <th>Description</th>
      <th>Default</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`sparsity`</td>
      <td>`float`</td>
      <td>Validation sparsity (0.0 - 1.0).</td>
      <td>`0.0`</td>
    </tr>
  </tbody>
</table>

**SpargeAttention (`sparge_attn`)**

| Parameter | Type | Description | Default |
| - | - | - | - |
| `topk` | `float` | Fraction of predicted attention blocks retained per head. Higher values preserve more attention work and generally improve quality. Must be in `(0, 1]`. | `0.5` |

SpargeAttention is approximate even when `topk=1`: the recommended upstream
kernel quantizes attention through SageAttention2. Validate output quality and
end-to-end latency on the target model and resolution before deployment.

**Video Sparse Attention for H3 (`video_sparse_attn_h3`)**

<table>
  <colgroup>
    <col />

    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Parameter</th>
      <th>Type</th>
      <th>Description</th>
      <th>Default</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`VSA_sparsity`</td>
      <td>`float`</td>
      <td>Fraction of video tiles excluded from the top-k selection (0.0 - 1.0). FastH3 defaults to its trained `0.8`.</td>
      <td>`0.8` (FastH3), `0.9` (base H3, FastH3 Omni)</td>
    </tr>

    <tr>
      <td>`vsa_mode`</td>
      <td>`str`</td>
      <td>`exempt`: non-video keys (text/audio prefix tiles) are always selected. `compete`: they compete with video tiles in the top-k.</td>
      <td>`exempt`</td>
    </tr>

    <tr>
      <td>`vsa_dense_first_n_steps`</td>
      <td>`int`</td>
      <td>Use dense attention for the first N denoising steps.</td>
      <td>`0`</td>
    </tr>

    <tr>
      <td>`vsa_dense_layers`</td>
      <td>`list[int]`</td>
      <td>Layer indices kept dense, e.g. `[0, 1]`.</td>
      <td>`[]`</td>
    </tr>

    <tr>
      <td>`vsa_tile_size`</td>
      <td>`int`</td>
      <td>Kernel tile size: `64` ((4, 4, 4) tiles) or `128` ((4, 4, 8) tiles, the FastH3 Omni default).</td>
      <td>`64`, `128` (FastH3 Omni)</td>
    </tr>

    <tr>
      <td>`vsa_ref_keep_rate`</td>
      <td>`float`</td>
      <td>Fraction of reference-video tiles kept, in (0, 1]. Required when the layout has reference videos (Ref2VA).</td>
      <td>`0.1` (FastH3 Omni), unset otherwise</td>
    </tr>
  </tbody>
</table>

VSA-H3 constraints:

* Only the DiT runs sparse; the token refiner, text encoder, and VAEs keep
  their dense defaults. An explicit `--component-attention-backends
  text_encoder=fa` is rejected because the H3 text encoder has SDPA-only layers.
* Uses the checkpoint's trained `to_gate_compress` compression branch. Base
  MiniMax-H3 weights load zero gates and run pure sparse.
* Ulysses sequence parallelism is supported; `--ring-degree` greater than 1,
  `torch.compile`, and breakable CUDA graph execution are rejected.

**Hybrid window attention for VDN-H3 (`hybrid_window_attn_h3`)**

[VDN-H3](https://docs.sglang.io/cookbook/diffusion/MiniMax/MiniMax-H3.md#7-vdn-h3-hybrid-attention-8-step-distill)
replaces every DiT block's dense self-attention with two branches. The
softmax branch is an exact softmax over a chunk-aligned frame window (frame
`t` belongs to chunk `t // 5` and attends to chunks `c - 1 .. c + 1`; frames
0 and F-1 are dense as rows and columns; every text / audio pair stays dense)
scaled by a per-head sigmoid gate. The linear branch (a frame-wise Video Delta
rule recurrence, forward and reverse over frames) covers exactly the window's
complement and is driven by the attention module. The mask is request-static,
so the metadata is built once per request. The checkpoint's
`transformer/config.json` carries the window geometry; the backend reads it.

<table>
  <colgroup>
    <col />

    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Parameter</th>
      <th>Type</th>
      <th>Description</th>
      <th>Default</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`vdn_h3_dense_smoke`</td>
      <td>`bool`</td>
      <td>Allows a dense transformer backend (`fa`) on the VDN-H3 weights for the base-H3 + LoRA equivalence smoke. The gates and the linear branch are skipped: a study, not a sample.</td>
      <td>`false`</td>
    </tr>

    <tr>
      <td>`vdn_max_gather_rows`</td>
      <td>`int`</td>
      <td>Upper bound on the gathered K/V rows per window FlashAttention call; consecutive chunk groups fill one call up to it. Splitting changes no query's kept key set, only the pass count and the gather's peak memory.</td>
      <td>`200000`</td>
    </tr>
  </tbody>
</table>

Hybrid window attention constraints:

* VDN-H3 requires this backend for the transformer; a dense backend on these
  weights would silently skip the linear branch and the gates, so it is
  rejected unless `vdn_h3_dense_smoke` is set. The token refiner, text
  encoder, and VAEs keep dense attention.
* Base MiniMax-H3 and FastH3 checkpoints have no linear branch and are
  rejected by this backend.
* Ulysses sequence parallelism is supported (QK-norm + RoPE run after the
  all-to-all on the head shard); `--ring-degree` greater than 1,
  `torch.compile`, and breakable CUDA graph execution are rejected.

**V-MoBA (`vmoba_attn`)**

<table>
  <colgroup>
    <col />

    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Parameter</th>
      <th>Type</th>
      <th>Description</th>
      <th>Default</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`temporal_chunk_size`</td>
      <td>`int`</td>
      <td>Chunk size for temporal dimension.</td>
      <td>-</td>
    </tr>

    <tr>
      <td>`temporal_topk`</td>
      <td>`int`</td>
      <td>Top-K tokens to select in temporal dimension.</td>
      <td>-</td>
    </tr>

    <tr>
      <td>`spatial_chunk_size`</td>
      <td>`list[int]`</td>
      <td>Chunk size for spatial dimension (H, W).</td>
      <td>-</td>
    </tr>

    <tr>
      <td>`spatial_topk`</td>
      <td>`int`</td>
      <td>Top-K tokens to select in spatial dimension.</td>
      <td>-</td>
    </tr>

    <tr>
      <td>`st_chunk_size`</td>
      <td>`list[int]`</td>
      <td>Chunk size for spatiotemporal dimension (T, H, W).</td>
      <td>-</td>
    </tr>

    <tr>
      <td>`st_topk`</td>
      <td>`int`</td>
      <td>Top-K tokens to select in spatiotemporal dimension.</td>
      <td>-</td>
    </tr>

    <tr>
      <td>`moba_select_mode`</td>
      <td>`str`</td>
      <td>Selection mode (e.g., `threshold`).</td>
      <td>`threshold`</td>
    </tr>

    <tr>
      <td>`moba_threshold`</td>
      <td>`float`</td>
      <td>Threshold value for selection.</td>
      <td>`0.25`</td>
    </tr>

    <tr>
      <td>`moba_threshold_type`</td>
      <td>`str`</td>
      <td>Type of thresholding (e.g., `query_head`).</td>
      <td>`query_head`</td>
    </tr>

    <tr>
      <td>`first_full_step`</td>
      <td>`int`</td>
      <td>Number of initial steps to use full attention.</td>
      <td>`12`</td>
    </tr>

    <tr>
      <td>`first_full_layer`</td>
      <td>`int`</td>
      <td>Number of initial layers to use full attention.</td>
      <td>`0`</td>
    </tr>

    <tr>
      <td>`temporal_layer`</td>
      <td>`int`</td>
      <td>Number of temporal layers.</td>
      <td>`1`</td>
    </tr>

    <tr>
      <td>`spatial_layer`</td>
      <td>`int`</td>
      <td>Number of spatial layers.</td>
      <td>`1`</td>
    </tr>

    <tr>
      <td>`st_layer`</td>
      <td>`int`</td>
      <td>Number of spatiotemporal layers.</td>
      <td>`1`</td>
    </tr>
  </tbody>
</table>

**Block Sparse Attention (`block_sparse_attn`)**

<table>
  <colgroup>
    <col />

    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Parameter</th>
      <th>Type</th>
      <th>Description</th>
      <th>Default</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`skip_first_steps`</td>
      <td>`int`</td>
      <td>Number of steps to use laser attention before switching to sparse attention.</td>
      <td>`10`</td>
    </tr>

    <tr>
      <td>`sparsity`</td>
      <td>`float`</td>
      <td> The sparsity coefficient must be in the range (0, 1).</td>
      <td>`0.2`</td>
    </tr>
  </tbody>
</table>

**Sol-Attn (`sol_attn`)**

<table>
  <colgroup>
    <col />

    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Parameter</th>
      <th>Type</th>
      <th>Description</th>
      <th>Default</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`tau`</td>
      <td>`float`</td>
      <td>Routing threshold scale. Higher values select fewer exact KV blocks.</td>
      <td>`1.0`</td>
    </tr>

    <tr>
      <td>`thresh_type`</td>
      <td>`str`</td>
      <td>Threshold mode: `diag` or `exact`.</td>
      <td>`diag`</td>
    </tr>

    <tr>
      <td>`sink_tokens`</td>
      <td>`int`</td>
      <td>Exact KV sink length for prefix tokens such as text/audio rows.</td>
      <td>`0`</td>
    </tr>

    <tr>
      <td>`sink_start`</td>
      <td>`int`</td>
      <td>Start index of the exact KV sink range.</td>
      <td>`0`</td>
    </tr>

    <tr>
      <td>`dense_steps`</td>
      <td>`int`</td>
      <td>Use dense attention for the first N denoising steps.</td>
      <td>`10`</td>
    </tr>

    <tr>
      <td>`dense_layers`</td>
      <td>`str`</td>
      <td>Layer indices kept dense, e.g. `0,1` or `0-2`.</td>
      <td>`0,1`</td>
    </tr>

    <tr>
      <td>`dense_backend`</td>
      <td>`str`</td>
      <td>Backend used for the dense prefix: `fa` (default) or `sage_attn`. `sage_attn` is approximate.</td>
      <td>`fa`</td>
    </tr>

    <tr>
      <td>`kv_splits`</td>
      <td>`int | str`</td>
      <td>KV split factor passed to the Sol-Attn kernel. Use `auto` on long sequences.</td>
      <td>`auto`</td>
    </tr>
  </tbody>
</table>

**AITER Quant (`aiter_quant`)**

The backend passes raw BF16 Q/K/V to `aiter.ops.mha_v4`, which applies the
canonical quantizer for the requested operand pair and launches the matching ASM
row. No calibration pass and no extra checkpoint weights are involved: the
format is purely a runtime choice.

<table>
  <colgroup>
    <col />

    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Parameter</th>
      <th>Type</th>
      <th>Description</th>
      <th>Default</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`format`</td>
      <td>`str`</td>
      <td>Quant format for the `mha_v4` call, one of the names in the table below. An unknown name, or one with no kernel row on the active arch, raises at construction rather than falling back.</td>
      <td>`fp8`</td>
    </tr>
  </tbody>
</table>

Variants, from widest operands to narrowest. Q and K always share an encoding;
only V varies independently.

<table>
  <colgroup>
    <col />

    <col />

    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Variant</th>
      <th>Q/K format</th>
      <th>V format</th>
      <th>Architectures</th>
      <th>Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`bf16fp8`</td>
      <td>BF16</td>
      <td>FP8</td>
      <td>gfx950</td>
      <td>Quantizes only PV, preserving BF16 attention scores for conservative quality.</td>
    </tr>

    <tr>
      <td>`i8fp8`</td>
      <td>INT8</td>
      <td>FP8</td>
      <td>gfx950, gfx942</td>
      <td>Uniform 8-bit Q/K quantization; effective for well-conditioned values but sensitive to outliers.</td>
    </tr>

    <tr>
      <td>`fp8`</td>
      <td>FP8</td>
      <td>FP8</td>
      <td>gfx950, gfx942</td>
      <td>Default native FP8: E4M3 on gfx950 and E4M3FNUZ on gfx942.</td>
    </tr>

    <tr>
      <td>`mxfp8`</td>
      <td>MXFP8 E4M3</td>
      <td>FP8</td>
      <td>gfx950</td>
      <td>Per-1x32 E8M0 Q/K scales and a per-tensor V scale improve outlier handling.</td>
    </tr>

    <tr>
      <td>`mxfp6`</td>
      <td>MXFP6 E2M3</td>
      <td>FP8</td>
      <td>gfx950</td>
      <td>Block-scaled 6-bit Q/K balances compression, throughput, and quality.</td>
    </tr>

    <tr>
      <td>`mxfp4`</td>
      <td>MXFP4 E2M1</td>
      <td>MXFP4 E2M1</td>
      <td>gfx950</td>
      <td>The most compact block-scaled Q/K/V format; validate quality for the target workload.</td>
    </tr>
  </tbody>
</table>

AITER quant constraints:

* Every row targets full-MHA `head_dim == 128` and non-causal attention; a
  causal layer or another head dim raises rather than falling back. Varlen
  attention is not supported.
* gfx942 ships only the `i8fp8` and `fp8` kernel rows. Every other format is
  gfx950-only and is rejected at construction on gfx942.
* Requires `SGLANG_USE_AITER=1` and an `aiter` build that ships
  `aiter.ops.mha_v4`.

## Platform support matrix

<table>
  <colgroup>
    <col />

    <col />

    <col />

    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Backend</th>
      <th>CUDA</th>
      <th>ROCm</th>
      <th>XPU</th>
      <th>MUSA</th>
      <th>MPS</th>
      <th>NPU</th>
      <th>Notes</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`fa`</td>
      <td>Yes</td>
      <td>No</td>
      <td>✅</td>
      <td>✅</td>
      <td>❌</td>
      <td>✅</td>
      <td>CUDA requires SM80+ and fp16/bf16. XPU uses its own flash attention backend. FlashAttention is only used when the required runtime is installed; otherwise it falls back to `torch_sdpa`. On ROCm, `fa` resolves to `torch_sdpa`. Native Ascend FA requires no additional attention package. Selecting FP8, MXFP8, or MXFP4 through `precision` requires MindIE-SD.</td>
    </tr>

    <tr>
      <td>`torch_sdpa`</td>
      <td>Yes</td>
      <td>Yes</td>
      <td>Yes</td>
      <td>Yes</td>
      <td>✅</td>
      <td>✅</td>
      <td>Most compatible option across platforms.</td>
    </tr>

    <tr>
      <td>`sliding_tile_attn`</td>
      <td>Yes</td>
      <td>No</td>
      <td>No</td>
      <td>No</td>
      <td>❌</td>
      <td>❌</td>
      <td>CUDA-only. Requires `st_attn`. Configure via `--attention-backend-config`.</td>
    </tr>

    <tr>
      <td>`sage_attn`</td>
      <td>Yes</td>
      <td>No</td>
      <td>No</td>
      <td>Yes</td>
      <td>❌</td>
      <td>❌</td>
      <td>Optional dependency on CUDA and MUSA. On Hopper, also falls back to FlashAttention when the installed package lacks the SM90 binding fix.</td>
    </tr>

    <tr>
      <td>`sage_attn_3`</td>
      <td>Yes</td>
      <td>No</td>
      <td>No</td>
      <td>No</td>
      <td>❌</td>
      <td>❌</td>
      <td>CUDA-only (optional dependency).</td>
    </tr>

    <tr>
      <td>`sparge_attn`</td>
      <td>Yes</td>
      <td>No</td>
      <td>No</td>
      <td>No</td>
      <td>❌</td>
      <td>❌</td>
      <td>CUDA SM80/86/87/89/90 only. Requires `SpargeAttn`; head dim 64/128 and square self-attention with sequence length at least 128.</td>
    </tr>

    <tr>
      <td>`sol_attn`</td>
      <td>Yes</td>
      <td>No</td>
      <td>No</td>
      <td>No</td>
      <td>❌</td>
      <td>❌</td>
      <td>CUDA-only. Requires `sol-attn`. Install with `pip install git+https://github.com/NVlabs/Sana.git@sol-engine#subdirectory=techniques/sparse_backends`. Configure via `--attention-backend-config`.</td>
    </tr>

    <tr>
      <td>`video_sparse_attn`</td>
      <td>Yes</td>
      <td>No</td>
      <td>No</td>
      <td>No</td>
      <td>❌</td>
      <td>❌</td>
      <td>CUDA-only. Requires `vsa`. Configure `sparsity` via `--attention-backend-config`.</td>
    </tr>

    <tr>
      <td>`video_sparse_attn_h3`</td>
      <td>Yes</td>
      <td>No</td>
      <td>No</td>
      <td>No</td>
      <td>❌</td>
      <td>❌</td>
      <td>CUDA-only (SM80 / SM90 / SM100 / SM103). In-tree kernels (native tcgen05 forward on Blackwell, Triton on Ampere and Hopper), no external dependency. Configure via `--attention-backend-config`.</td>
    </tr>

    <tr>
      <td>`sla_attn`</td>
      <td>Yes</td>
      <td>No</td>
      <td>No</td>
      <td>No</td>
      <td>❌</td>
      <td>❌</td>
      <td>CUDA-only. Requires `SpargeAttn`.</td>
    </tr>

    <tr>
      <td>`sage_sla_attn`</td>
      <td>Yes</td>
      <td>No</td>
      <td>No</td>
      <td>No</td>
      <td>❌</td>
      <td>❌</td>
      <td>CUDA-only. Requires `SpargeAttn`.</td>
    </tr>

    <tr>
      <td>`vmoba_attn`</td>
      <td>Yes</td>
      <td>No</td>
      <td>No</td>
      <td>No</td>
      <td>❌</td>
      <td>❌</td>
      <td>CUDA-only. Requires `flash-attn` >= 2.7.1. Configure via `--attention-backend-config`.</td>
    </tr>

    <tr>
      <td>`aiter`</td>
      <td>❌</td>
      <td>✅</td>
      <td>No</td>
      <td>No</td>
      <td>❌</td>
      <td>❌</td>
      <td>Requires `aiter`.</td>
    </tr>

    <tr>
      <td>`aiter_sage`</td>
      <td>❌</td>
      <td>✅</td>
      <td>No</td>
      <td>No</td>
      <td>❌</td>
      <td>❌</td>
      <td>Requires `aiter`.</td>
    </tr>

    <tr>
      <td>`aiter_quant`</td>
      <td>❌</td>
      <td>✅</td>
      <td>No</td>
      <td>No</td>
      <td>❌</td>
      <td>❌</td>
      <td>Requires `SGLANG_USE_AITER=1` and an `aiter` that ships `aiter.ops.mha_v4`; gfx950 (gfx942 supports `i8fp8` / `fp8` only). Select the quant format via `--attention-backend-config`.</td>
    </tr>

    <tr>
      <td>`sparse_video_gen_2_attn`</td>
      <td>Yes</td>
      <td>No</td>
      <td>No</td>
      <td>No</td>
      <td>❌</td>
      <td>❌</td>
      <td>CUDA-only. Requires `svg`.</td>
    </tr>

    <tr>
      <td>`laser_attn`</td>
      <td>❌</td>
      <td>❌</td>
      <td>❌</td>
      <td>❌</td>
      <td>❌</td>
      <td>✅</td>
      <td>NPU-only. Requires `attentions` from `sgl_kernel_npu`. Uses SDPA if seqlen less than 2048.</td>
    </tr>

    <tr>
      <td>`block_sparse_attn`</td>
      <td>❌</td>
      <td>❌</td>
      <td>❌</td>
      <td>❌</td>
      <td>❌</td>
      <td>✅</td>
      <td>NPU-only. Requires `attentions` from `sgl_kernel_npu`. Configuration via `--attention-backend-config`.</td>
    </tr>

    <tr>
      <td>`rain_fusion_attn`</td>
      <td>❌</td>
      <td>❌</td>
      <td>❌</td>
      <td>❌</td>
      <td>❌</td>
      <td>✅</td>
      <td>NPU-only. Requires `attentions` from `sgl_kernel_npu` Configuration via `--attention-backend-config`.</td>
    </tr>

    <tr>
      <td>`fp8_fa_sm120`</td>
      <td>Yes</td>
      <td>❌</td>
      <td>❌</td>
      <td>❌</td>
      <td>❌</td>
      <td>❌</td>
      <td>CUDA SM120/SM121; falls back to `torch_cudnn_sdpa` on other devices and for unsupported calls.</td>
    </tr>
  </tbody>
</table>

## Usage

### Select a backend via CLI

```bash theme={null}
sglang generate \
  --model-path <MODEL_PATH_OR_ID> \
  --prompt "..." \
  --attention-backend fa
```

```bash theme={null}
sglang generate \
  --model-path <MODEL_PATH_OR_ID> \
  --prompt "..." \
  --attention-backend torch_sdpa
```

### Override one component

Use component overrides when a specific module needs different attention semantics from the main transformer:

```bash theme={null}
sglang generate \
  --model-path <MODEL_PATH_OR_ID> \
  --prompt "..." \
  --attention-backend fa \
  --component-attention-backends text_encoder=torch_sdpa
```

Component keys match pipeline module names from `model_index.json`, such as `text_encoder`, `text_encoder_2`, `transformer`, `transformer_2`, or `connectors`.
Use this override when the fallback must be pinned: unlike the global backend,
an incompatible component override raises an error instead of selecting another
backend. The one role-based exception is a sparse self-attention backend, which
uses a compatible dense backend for cross-attention layers in the same component.
The component must construct SGLang-selectable attention or explicitly defer
selection until first use; components with fixed attention reject the override.
Per-component overrides apply only to native pipelines. The Diffusers backend
accepts the global `--attention-backend` passthrough instead.

### Per-request override (denoise loop)

A single server can serve exact and approximate attention side by side: requests
may switch the DiT denoise attention backend via the `attention_backend_override`
sampling param. Valid values are the exact/drop-in dense kernels — `fa`,
`torch_sdpa`, `sage_attn`, `sage_attn_3`. The field participates in the
dynamic-batch signature, so requests with different backends never share a batch.

```bash theme={null}
sglang generate \
  --model-path <MODEL_PATH_OR_ID> \
  --prompt "..." \
  --attention-backend-override sage_attn
```

```python theme={null}
client.images.generate(
    model="<MODEL_PATH_OR_ID>",
    prompt="...",
    extra_body={"attention_backend_override": "sage_attn"},
)
```

Incompatible server settings **reject the request** (with a server log) instead
of silently falling back: breakable CUDA graphs and `torch.compile` bake the
attention kernel into a captured/traced graph; sparse server backends
(`sliding_tile_attn`, `video_sparse_attn`, ...) cannot be mixed with per-request
dense switching; under ring parallelism the target must be ring-capable. Note
`sage_attn` / `sage_attn_3` are lossy (quantized attention) — validate quality
on your workload.

### Request-scoped Skip Softmax

Skip Softmax (BLASST) keeps the QK matmul, but skips the exponential,
softmax-state update, V load, and PV matmul for attention tiles whose estimated
softmax mass is below a threshold. It is an explicit lossy optimization backed
by the FlashInfer kernels shipped with SGLang's pinned dependencies. See the
[BLASST paper](https://arxiv.org/abs/2512.12087) and NVIDIA's
[video-generation study](https://github.com/NVIDIA/TensorRT-LLM/blob/main/docs/source/blogs/tech_blog/blog28_Accelerating_Video_Generation_with_GEMM_Quantization_Attention_Quantization_and_Skip_Softmax_Attention_in_TensorRT-LLM.md)
for the algorithm and measured quality/performance trade-offs.

Pass `skip_softmax_params` in one image or video request. The runtime routes
compatible self-attention layers through the FA/FlashInfer path for that batch;
cross-attention keeps its normal backend, and the next request restores the
server default.

```python theme={null}
client.videos.create(
    model="<MODEL_PATH_OR_ID>",
    prompt="...",
    extra_body={
        "skip_softmax_params": {
            "threshold_scale_factor": 500.0,
            "start_step": 14,
        }
    },
)
```

* `threshold_scale_factor` is required and must be positive. The kernel uses
  `threshold_scale_factor / context_length`; larger values skip more work and
  usually increase quality loss.
* `start_step` is the zero-based denoising step at which sparse execution
  starts. It defaults to `0`; keeping early high-noise steps dense is generally
  safer.

There is intentionally no default threshold. Calibrate the threshold and start
step against output-quality metrics for each model, resolution, step count, and
deployment backend; values tuned for one workload are not portable.

Current support is FP16/BF16, head dimension 128 or 256, and unmasked
self-attention on Hopper SM90 and Blackwell SM100/SM103/SM107. Ulysses sequence
parallelism is supported because the kernel runs after its all-to-all. Ring
Attention, attention masks, `torch.compile`, and breakable CUDA graphs reject
the request instead of silently running dense attention. Models that merely
offer an FA backend do not automatically qualify: the runtime still checks the
GPU, dtype, head dimension, attention role, and execution mode.

### Using SpargeAttention

Install the optional CUDA extension, then select the backend explicitly:

```bash theme={null}
pip install ninja
pip install git+https://github.com/thu-ml/SpargeAttn.git --no-build-isolation

sglang generate \
  --model-path <MODEL_PATH_OR_ID> \
  --prompt "..." \
  --attention-backend sparge_attn \
  --attention-backend-config topk=0.5
```

`sparge_attn` applies to compatible self-attention layers. Cross-attention uses
the existing dense fallback; short self-attention and asymmetric Q/KV also use
dense SDPA. LTX-2, LTX-2.3, and LTX-2.5 have compatible video (128) and audio
(64) head dimensions, so their sufficiently long, unmasked self-attention uses
SpargeAttention while prompt and audio-video cross-attention remain dense.
Ulysses sequence parallelism is supported, but ring attention is not because the
upstream kernel does not expose the softmax LSE needed for ring merging. K/V-gather
SP therefore follows the normal sparse-backend rule and uses Ulysses instead.

### Sage then Sol hybrid

`sol_attn` keeps the first `dense_steps` steps dense. Set
`dense_backend=sage_attn` to run that prefix on SageAttention and the tail on
Sol sparse attention. Keep the text encoder on `torch_sdpa`:

```bash theme={null}
sglang generate \
  --model-path MiniMaxAI/MiniMax-H3 \
  --model-variant fl2va \
  --attention-backend sol_attn \
  --attention-backend-config dense_backend=sage_attn,dense_steps=10 \
  --component-attention-backends text_encoder=torch_sdpa,transformer=sol_attn \
  --prompt "A cat walking on a sunny beach, gentle waves." \
  --save-output
```

Both `sage_attn` and `sol_attn` are approximate. The default DiT backend remains `fa`.

### Ascend quantized attention with MindIE-SD

On Ascend NPU, `fa` can use the public `mindiesd.quant_attention` API for
FP8, MXFP8, and MXFP4 attention. This integration targets MiniMax-H3;
Wan/FLUX support is out of scope. Omitting `precision` preserves the existing
native Ascend FA behavior, including its opt-in MXFP8 path. Set `precision=bf16`
to explicitly select native floating-point attention. Neither requires MindIE-SD.

When FA is an internal dense fallback for another selected backend, that
backend's `precision` does not enable quantized FA.
The denoising stage passes configuration through `AscendFAMetadata`; the FA
constructor does not read global server arguments. Quantization applies to DiT
self-attention. H3 refiners and cross-attention do not inherit its quantized path.

#### Install the optional SDK

Use Linux with an Ascend 950 (A5), the CANN toolkit/operator packages, and a
matching Torch/TorchNPU installation. Activate the Python environment that runs
SGLang before building: the SDK's native extension uses that environment's Torch
ABI. Keep the Torch/TorchNPU versions required by your SGLang checkout; the SDK's
root `requirements.txt` pins Torch/TorchNPU 2.9 and must not replace them.

Install the official [3.2.0 wheel](https://pypi.org/project/mindiesd/3.2.0/#files)
if its Python, architecture, glibc, and Torch ABI match your environment.

```bash theme={null}
python3 -m pip install --no-deps --only-binary=:all: "mindiesd==3.2.0"
```

`--no-deps` preserves the installed Torch/TorchNPU versions.

If no compatible wheel is available, build the `3.2.0` release in a user-owned directory.
The example sets `ASCEND_COMPUTE_UNIT=ascend950` for quantized FA on Ascend 950.
For sparse attention on a supported 910-series device, set `ASCEND_COMPUTE_UNIT`
to the target chip or leave it unset to use the SDK defaults for your CANN version.

```bash theme={null}
# Adjust this path to your CANN installation.
source /usr/local/Ascend/ascend-toolkit/set_env.sh
git clone --branch 3.2.0 --depth 1 https://gitcode.com/Ascend/MindIE-SD.git
cd MindIE-SD
# Release commit: 65bd01133998ab018052fdb6f55dea5a873e584f
python3 -m pip install "setuptools>=65.5" build wheel "cmake<4.1"

# 3.2.0 makes build/vendors read-only before the following AICPU copy.
# Restore owner write permission between those two build steps.
python3 - <<'PY'
from pathlib import Path

path = Path("build/build_ops.sh")
source = path.read_text(encoding="utf-8")
marker = "    sync_aicpu_ops_to_transformer_vendor\n"
assert source.count(marker) == 1
source = source.replace(
    marker,
    '    chmod u+w "${current_script_dir}/vendors"\n' + marker,
    1,
)
path.write_text(source, encoding="utf-8")
PY

MINDIE_SD_VERSION_OVERRIDE=3.2.0 ASCEND_COMPUTE_UNIT=ascend950 \
  python3 -m build --wheel --no-isolation
python3 -m pip install --no-deps dist/mindiesd-3.2.0-*.whl
```

The release still defaults its package version to `3.1.0`, so the build command
sets the release version explicitly. The permission workaround addresses the non-root `customize_transformer`
directory creation failure in the release's
[build script](https://gitcode.com/Ascend/MindIE-SD/blob/3.2.0/build/build_ops.sh).
It does not require root or disable operator builds. You also need the CANN
development toolchain; see the pinned
[installation guide](https://gitcode.com/Ascend/MindIE-SD/blob/3.2.0/docs/en/installation.md)
and [build guide](https://gitcode.com/Ascend/MindIE-SD/blob/3.2.0/docs/en/developer_guide/build_guide.md).

| Environment | Validation status |
| - | - |
| Ascend 950, Torch/TorchNPU 2.10.0, CANN 9.2.0-beta.2, custom SDK `3.1.0+fb774c4.c8v16` | H3 generation/performance runs for FP8, MXFP8, and MXFP4; not model-quality parity. |
| Ascend 910 / 910B / 910\_93 | These A5 quantized attention paths are not supported; use native FA. |

On the target NPU host, activate the CANN environment and check the public API:

```bash theme={null}
python3 -c 'from mindiesd import quant_attention; assert callable(quant_attention)'
```

This import check does not verify native execution. Missing SDKs, incompatible
libraries, and operator failures raise errors rather than falling back to native FA.

#### Configure attention

| Parameter | Type | Description | Default |
| - | - | - | - |
| `precision` | `str` | `bf16` selects native floating-point FA; `fp8`, `mxfp8`, or `mxfp4` selects MindIE-SD. | Unset (existing native selection) |
| `fp8_fa_mode` | `str` | FP8 only; `HIGH_PRECISION` or `C8V16_TILING512` (head dimension 128). | `HIGH_PRECISION` |
| `head_chunk_size` | `int` | MHA heads per SD call. Use `0` to disable chunking, or another positive integer. | `4` |
| `qk_rotation` | `bool` | Apply online Q/K rotation before quantization. Not used by the native BF16 path. | `true`, or `false` when the checkpoint already includes offline Q/K rotation |

`C8V16_TILING512` is an alternative FP8 compute/tiling mode for head dimension
128\. It changes the V block layout and the fused kernel's internal precision
setting; Q/K/V still pass through SDK quantization. Compare its latency and
numerical quality with `HIGH_PRECISION` on your workload before choosing it.
See the [SDK implementation](https://gitcode.com/Ascend/MindIE-SD/blob/3.2.0/mindiesd/layers/flash_attn/fused_infer_attention_score.py).

For example, run MiniMax-H3 on two NPUs with FP8 C8V16 and the default chunk size:

```bash theme={null}
sglang generate \
  --model-path /models/MiniMax-H3 \
  --model-variant fl2va \
  --performance-mode manual \
  --num-gpus 2 --tp-size 2 \
  --vae-config.use-parallel-tiling false \
  --attention-backend fa \
  --attention-backend-config '{"precision":"fp8","fp8_fa_mode":"C8V16_TILING512"}' \
  --prompt "A cat walking on a sunny beach, gentle waves." \
  --save-output
```

For MXFP8 or MXFP4, use `'{"precision":"mxfp8"}'` or
`'{"precision":"mxfp4"}'`. Use `'{"precision":"bf16"}'` for a native
floating-point attention baseline, even when native MXFP8 is enabled in the
environment. The text encoder keeps its normal backend selection. Attention
precision is independent of linear-weight quantization. Add `--quantization mxfp8`
only if online MXFP8 linear weights are also wanted.

The SD path uses `attention_backend_config`; it does not need the native
`SGLANG_DIFFUSION_ENABLE_MXFP8_ATTENTION` or
`SGLANG_DIFFUSION_MXFP8_FA_HEAD_CHUNK_SIZE` variables. Head chunking applies to
dense and packed MHA, including a smaller final chunk. GQA is delegated to the
SDK without head chunking. Packed sequences remain isolated and H3 trailing
padding is zeroed. Ordinary Ulysses is supported; causal attention, nonzero dropout,
Ring attention, and softmax LSE are unsupported.

Online rotation follows native Ascend FA's deterministic rotation and is applied
once by the SDK, before quantization. Checkpoints with offline Q/K rotation
default to no online rotation; explicitly enabling both is rejected.

> [!WARNING]
>
> MindIE-SD 3.2.0 pads MXFP4 sequence lengths to multiples of 512. The padded
> K/V positions participate in softmax. SGLang preserves this SDK behavior;
> validate numerical quality with the sequence lengths used by your workload.

#### Validate the installation

Run from an installed SGLang checkout in the target Linux environment:

```bash theme={null}
# CPU adapter tests with a mocked SDK.
pytest python/sglang/multimodal_gen/test/unit/test_ascend_fa.py
```

These tests check adapter behavior without executing NPU kernels. They do not
establish model-quality parity; inspect generated outputs for your workload.

### Using Sliding Tile Attention (STA)

`STA_INFERENCE` also reads the per-layer STA parameters from the file named by the `SGLANG_DIFFUSION_ATTENTION_CONFIG` environment variable.

```bash theme={null}
# Pass the mask strategy file path via config
SGLANG_DIFFUSION_ATTENTION_CONFIG=/abs/path/to/sta_config.json \
sglang generate \
  --model-path <MODEL_PATH_OR_ID> \
  --prompt "..." \
  --attention-backend sliding_tile_attn \
  --attention-backend-config "mask_strategy_file_path=/abs/path/to/mask_strategy.json,STA_mode=STA_INFERENCE"
```

### Notes for ROCm / MPS

* ROCm: Instinct (CDNA, gfx9) GPUs default to `aiter`; use `--attention-backend torch_sdpa` on Radeon (RDNA) GPUs or when AITER is unavailable (`fa` also resolves to `torch_sdpa` on ROCm). On gfx1151 / Strix Halo (wave32), do **not** use `aiter` — prefer `torch_sdpa` (image sets `SGLANG_USE_AITER=0`).
* MPS: the platform implementation always uses `torch_sdpa`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.