Skip to content

Qwen3.8 QSA backends and parallelism ​

Opt-in CuTe attention and static CP ​

The cute long-document backend uses the QSA kernels adapted from Megatron-LM PR #7553, pinned to b375677531eb8374769260b18458231d26763a34. Use the CUDA 13 Blackwell image built from this revision: it supplies CuTe DSL 4.6.2 and the Megatron dispatch, MTP metadata and PLE hooks. Pointing MEGATRON at an older checkout bypasses those image patches. This backend does not require the optional cuDNN PR1765 package or MoK.

CuTe is a CUDA kernel programming DSL; selecting it changes QSA attention, not the optimizer or MoE backend. The mixed adapter requires CUDA BF16, D256, a frozen Stage-1 indexer, zero indexer loss and R4 selected IDs. Local Q heads must be divisible by local KV heads, with a GQA group of 5–128. For the 24Q/2KV model this admits TP1/2/4 kernel geometry, but not TP8. The 32-GPU HybridEP recipe supports TP2/PP4/EP8/ETP1; geometry alone does not authorize other training topologies.

Start with CP1 when the workload fits. In CP1, documents of at most 4*K+3 tokens use Flash by default (K=512 gives 2051); longer documents use CuTe. There is no intermediate Flex branch for cute. Invalid shapes or missing dependencies raise an error instead of silently switching to Grouped.

bash
export MODEL_DIR=/path/to/model
export DATA_DIR=/path/to/sft-data
export SAVE_DIR=/path/to/checkpoints
export MEGATRON=/path/to/image-patched/Megatron-LM
export RAY_JOBS_ADDRESS=http://ray-head:8265
export RAY_ADDRESS="$RAY_JOBS_ADDRESS"
export RELAX_QWEN38_QSA_MIXED_LONG_BACKEND=cute
export EXP_NAME=qwen38-cute-cp1
bash examples/models/qwen3.8-flash-next/scripts/run-qwen38-qsa-sft-32xgpu-blackwell.sh

The script supplies mixed routing, disables the legacy fused attention/selector, and forwards its environment settings to training actors. It retains the image's RELAX_HYBRID_EP_COMMIT requirement. Set DRY_RUN=1 to inspect the effective arguments and actor environment before submitting.

For static CP2, keep the preceding environment and add:

bash
export QWEN38_CP_SIZE=2
export RELAX_QWEN38_QSA_CP=1
export RELAX_QWEN38_GDN_CP_PREBUILD_ROUTE=1
export RELAX_QWEN38_PLE_CP_FUSED_CONV=1
export RELAX_QWEN38_QSA_CP_TP_SELECTOR=1
export RELAX_QWEN38_QSA_SELECTOR_BACKEND=torch
export EXP_NAME=qwen38-cute-cp2
bash examples/models/qwen3.8-flash-next/scripts/run-qwen38-qsa-sft-32xgpu-blackwell.sh

Use QWEN38_CP_SIZE=4 and a distinct experiment name for CP4. At 32 GPUs with TP2/PP4, CP1/2/4 leave DP4/2/1 respectively. These paths require static, per-document zigzag THD packing, explicit TP/CP groups, zero attention dropout and unfused RoPE. The script already supplies --no-rope-fusion. Dynamic CP and trainable Stage-2 indexers are not supported by this CuTe CP adapter.

SettingDefaultEffect
RELAX_QWEN38_QSA_MIXED_LONG_BACKENDgroupedSelect cute explicitly; retain grouped as the CP1 control
QWEN38_CP_SIZE1 in this recipeSet the static CP degree; does not by itself enable CuTe CP
RELAX_QWEN38_QSA_CP0Use local-query CuTe attention and its CP selector when CP>1
RELAX_QWEN38_GDN_CP_PREBUILD_ROUTE0Build each microbatch's GDN layout route from producer CPU boundaries and reuse it across layers; keep native FLA computation
RELAX_QWEN38_PLE_CP_FUSED_CONV0Fuse the PLE convolution tail after native CP reconstruction; leaves gathers and output slicing unchanged
RELAX_QWEN38_QSA_CP_TP_SELECTOR0Partition CP selector query tiles across TP ranks and gather selected IDs; requires the torch selector
RELAX_QWEN38_QSA_SELECTOR_BACKENDtorchOptional radix selection for long documents; CP1 uses the TP-selector path, and CP TP partitioning must be disabled for radix

Radix has setup overhead and can regress short or mixed-document batches. Compare it with torch on the actual length distribution before enabling it. CP TP partitioning assigns 512-row tiles; tail tiles and short documents can leave uneven work across TP ranks. It is not a load-balancing guarantee.

CP retains only local Q rows and attention output, gathers complete K/V and raw indexer keys, then reduce-scatters K/V gradients with summation. Packed documents keep separate positions and causal tails. It does not implement a ring attention exchange or fetch only selected remote K/V. GDN continues to use its chunkwise CP layout, while PLE reconstructs a full stream before convolution by default (the local computation option below reduces this cost). Consequently, CP reduces some activation/workspace costs but adds communication, reduces DP, and need not improve end-to-end throughput on short packed data. CP support alone does not establish 1M training capacity or long-context model quality.

For a CP1 Grouped control, restore QWEN38_CP_SIZE=1, RELAX_QWEN38_QSA_CP=0, and RELAX_QWEN38_QSA_MIXED_LONG_BACKEND=grouped; disable the three CP optimization flags and retain SELECTOR_BACKEND=torch. For a CP2/4 ablation, keep QSA_CP=1 and MIXED_LONG_BACKEND=cute, then switch each CP optimization flag independently. Always use distinct checkpoint directories or experiment names for comparison arms. Preserve the data, token budget, batch size, recomputation and profiling settings when comparing throughput.

This guide covers training-side QSA in the Megatron image, with source baseline 97210aaf5b40db54eb63e80748b5f34b3433fb78 (PR1). Local kernel geometry, Relax adapter acceptance, and a validated training topology are separate contracts. The NV recipes later in this guide are configuration examples, not a guarantee for every backend or parallel layout.

Execution layers ​

The selector chooses historical complete blocks; the attention kernel consumes that selection and adds the incomplete causal tail. TP/SP/CP adapt projections, token layouts and communication around these operations. HybridEP handles MoE communication independently.

text
Model projections / TP-SP-CP layout
  -> selector -> QSASelection -> QSACoreAttention
       -> all-selected causal shortcut (unless forced sparse / mixed)
       -> dense_masked -> PyTorch SDPA with an explicit mask
       -> flex -> optional fused candidate -> Triton / triton_v2 / triton_v3
               -> otherwise native Flex / optimized BlockMask Flex
       -> id_sparse -> native selected-ID Triton
                    -> community=mixed -> Flash / Flex / Grouped
                                       -> Flash / cuDNN PR1765

Fused attention replaces the Flex calculation; it does not replace the selector. Mixed wraps the selector and replaces the selected-ID attention entry. A fused candidate that fails supports() returns to Flex; mixed NV does not fall back to Grouped. Native all-selected CP1 inputs can use the configured dense core; CP>1 has an explicit gathered causal path. Mixed binds all_selected=False to preserve its own short-document route. See native core, dispatch, operator integration and mixed entry.

Selecting a route ​

Defaults below refer to the framework, before model/recipe scripts export overrides. Configure driver and training actors consistently. The patched Megatron implementation is supplied by Docker build, rather than by an arbitrary installed Megatron checkout.

Route / layerConfigurationEntry and default
Native dense referenceEmpty RELAX_QWEN38_QSA_COMMUNITY_BACKEND; MCORE_QSA_SPARSE_BACKEND=dense_maskedQSACoreAttention._dense_masked_forward; opt-in
Native FlexEmpty community; MCORE_QSA_SPARSE_BACKEND=flex; fused attention off_flex_forward; native backend default is flex
Optimized BlockMask builderNative Flex plus RELAX_QWEN38_QSA_SPARSE_BLOCKMASK=1qsa_block_mask._sparse_flex_forward; framework default off; changes mask construction
Fused attention implementationsNative Flex plus RELAX_QWEN38_QSA_FUSED_ATTENTION=triton, triton_v2, or triton_v3qsa_fused.backend; framework default off; 1/true also select Triton v1
Native selected-ID kernelEmpty community; MCORE_QSA_SPARSE_BACKEND=id_sparse_relax_native_id_sparse_forward; opt-in
Mixed compositionRELAX_QWEN38_QSA_COMMUNITY_BACKEND=mixed, fused attention off, native backend id_sparseqsa_community and qsa_mixed_ops; nonempty community selects id_sparse by default and rejects a conflicting explicit backend

The shared model script defaults BlockMask, local-query, replay, fused selector and fused attention on; these differ from environment registry defaults. It disables fused selector when community is nonempty, but does not also disable fused attention. Consequently, setting only community to mixed while inheriting fused attention 1 triggers the mixed producer's explicit rejection. Use the complete mixed recipe, or explicitly set the combination below before model construction:

bash
export RELAX_QWEN38_QSA_COMMUNITY_BACKEND=mixed
export MCORE_QSA_SPARSE_BACKEND=id_sparse
export RELAX_QWEN38_QSA_FUSED_ATTENTION=0
export RELAX_QWEN38_QSA_FUSED_SELECTOR=0
export RELAX_QWEN38_QSA_MIXED_LONG_BACKEND=grouped

This selects the route only; model, frozen-indexer, layout and parallel prerequisites still apply.

Attention input contracts ​

Hq/Hkv/D below describe attention heads. They do not describe the selector's separate projection. Native adapters receive THD [T,H,D] or SBHD [S,B,H,D] and convert them for their kernel. Check native methods, fused adapter, fused kernel, and mixed entry before changing a shape.

Attention implementationLocal geometry / selectionExecution constraints
Native dense_maskedGQA by K/V replication; bitset selection; no Relax 12/1/D256 specializationExplicit [B,S,S] boolean mask plus SDPA; quadratic mask memory. Device/dtype depend on the chosen PyTorch SDPA implementation; the Qwen recipe uses CUDA BF16
Native Flex / BlockMask FlexGQA via enable_gqa; bitset with document IDs and positions; no Relax 12/1 specializationPyTorch FlexAttention/Torch compilation support required. Optimized BlockMask requires CUDA, nonempty R4 bitset; otherwise native Flex. Small (S<=4096) Dynamo compile failures can use dense-masked fallback
Native id_sparse TritonInteger GQA, power-of-two D<=256; int32 IDs/positions; positive top-k; ratio divides 32 and is at most 32Contiguous CUDA Q/K/V, matching shapes. IDs must be distinct visible complete blocks, fill min(visible,K) slots, and use -1 padding. No explicit dtype whitelist in this prototype; this is not arbitrary-dtype numerical validation
Fused Triton v1 / v2 / v3Shared supports: CUDA, native flex, one selection row, nonempty R4 bitset, D in {64,128,256}, integer GQATHD kernel input; non-THD adapter accepts batch 1, otherwise returns to Flex. Plan carries forward/reverse 128-token tiles and optional global query_ids. supports has no dtype or Blackwell-only whitelist; compilation/numerical portability is separate
Mixed Flash / Flex / GroupedR4 native IDs, expanded to tokens with document offsets and partial tail; geometry belowCUDA BF16, CP1, frozen Stage-1 indexer and zero indexer loss. Grouped uses BF16 products and FP32 K/V atomic accumulation; do not transfer fused deterministic-backward claims to it
Mixed Flash / cuDNNR4 int32 IDs, exactly 512 columns per token (2048-token selection budget); geometry belowCUDA BF16; same mixed producer requirements. Long branch imports the optional pinned package; short branch still obeys NV adapter geometry. See NV runtime requirements below

The fused v2/v3 implementations reuse the base supports() and plan. SM103/BF16/D256 tile choices are specializations, not a universal Blackwell requirement. The v3 shared-dS backward optimization has narrower guards: SM103, BF16, D256, R4, no local query_ids, positive Q/K lengths at most 131072 and bounded int32 addressing. Its workspace policy caps shared scratch at 24 GiB; ineligible inputs or insufficient scratch retain the regular backward. These guards do not prohibit all CP use of v3. See _can_share_ds in v3 and its shared_backward.py.

Selection, packing and training stage ​

QSASelection holds document-local positions, doc_ids and either a byte bitset (selected_bits) or compact complete-block IDs (selected_ids). A budget of 2048 tokens at R4 means at most 512 complete blocks, not 2048 block IDs. Causal masking adds at most three tokens of the current incomplete block; it must not cross a packed document boundary.

Producer / adapterConfiguration and requirementsBoundary / stage contract
Native selectorQSAIndexer parameters come from the provider's indexer configuration; supports bits or IDs according to attention backendReconstructs CP sequence and handles SP gather. Do not infer selector heads from attention's global 24Q/2KV
Fused selector postprocessingRELAX_QWEN38_QSA_FUSED_SELECTOR=1 (framework off); qsa_select.select_blocksCUDA four-head selector, bits output, usable CPU offsets and other shape guards; ineligible cases use the ordinary selector. This is separate from fused attention
Mixed TP selectorRELAX_QWEN38_QSA_TP_SELECTOR=1 (default 0), mixed backend; optional RELAX_QWEN38_QSA_SELECTOR_COMPILE=1 (default off)CP1, frozen, IDs, selector 4Q/1KV/D128, R4, positive budget divisible by 4 and at most 2048; zero-centered RMSNorm, BF16 CUDA [S,1,hidden], RoPE, explicit TP/singleton-CP groups; gathered sequence nonempty and divisible by TP. Shards query work, all-gathers selected IDs
Mixed packed metadataqsa_mixed_ops.forward, bind_document_boundsExact producer CPU boundaries (qsa_physical_layout_cpu binding or qsa_select_offsets_cpu); copied selection preserves boundaries during checkpoint replay. Nonpacked rows are independent documents
Stage-2 indexer lossNative id_sparse, positive qsa_indexer_loss_coeffSeparate bounded KL path: gathered S*B<=4096, attention dropout zero, explicit TP group when TP>1; THD needs true-length qsa_stage2_layout_cpu. Mixed rejects this stage; frozen-indexer replay must not detach its projections

Selector entry priority is mixed wrapper → fused-selector wrapper if enabled → replay → TP-selector → CPU-layout/native stages. “CPU layout” refers to metadata handling, not a CPU attention kernel. The branches are gated functions, not all executed for every batch. Sources: dispatch, selector fusion, TP selector, mixed entry, native loss attachment.

Parallel layouts and independent guards ​

DimensionQSA/model behaviorScope of the restriction
TPGlobal attention heads are partitioned; when TP exceeds two KV heads, KV groups are replicated and Q/gate slices are narrowed within each groupModel projection layout, not an attention-kernel topology test. See projection patch and qsa_routed_qkv.route_table
CPNative sparse core reconstructs full Q and differentiable K/V, then splits output back to the local sliceBaseline communication path; full activations still exist on each CP rank. Grouped/cuDNN mixed producers require CP1; CuTe has the opt-in static CP path above
CP local-queryRELAX_QWEN38_QSA_LOCAL_QUERY=1 keeps Q local and gathers K/V with gradient summationOnly CP>1, THD, CUDA, Flex, nonempty R4 bitset, Stage-1/no differentiable indexer tensors, suitable sparse selection. Ineligible calls return to native core; it does not enable Grouped/cuDNN mixed CP>1
SPNative/TP selector gathers hidden states from the explicit TP group when sequence parallelism is activeOrthogonal to attention GQA. TP selector still requires gathered length divisible by TP; a script's --sequence-parallel is not a kernel-only capability
PPQSA executes in its owning pipeline layer; MTP can add a QSA layer on the last stageNo general PP4 guard in the attention kernel. Layer partition, MTP and recomputation integration must be checked separately
EP / ETPMoE communication is independent of attention head groupingThe selected dispatcher can impose physical topology and package constraints even if local QSA shapes pass

For the global 24Q/2KV/D256 model, the projection code yields:

TPLocal attention Q/KVKV placement
124/2Both KV groups local
212/1One KV group per rank
46/1Each KV group shared by two TP ranks
83/1Each KV group shared by four TP ranks

The projection patch gathers projection shards when query groups are fewer than TP ranks, selects the KV group by rank, and slices Q/gate within that group. The optional routed QKV path replaces that gather with explicit TP all-to-all and sums shared-KV gradients in the adjoint. It is guarded to gated QSA, global 24/2/D256, TP4/8, CP1, BF16 or FP32 and no FP8/FP4/test mode; other cases use the original projection. This table describes layout derivation, not successful TP1/2/4/8 training. In particular, an NV adapter remains limited by the mixed geometry table below.

MoE topology and recomputation are separate contracts ​

HybridEP preflight checks the MoE dispatcher independently of QSA. The Grouped and cuDNN Mixed routes require CP1. With QSA CP enabled, Mixed CuTe also allows the documented static CP2/4 layouts and 32-GPU CP8/16 layouts. HybridEP requires ETP1, EP4 or EP8, and a compatible world size for the selected layout. The EP×ETP group must contain distinct ranks on one host, and every member must see the expected number of peers. The installed package and loaded modules must match RELAX_HYBRID_EP_COMMIT.

RELAX_QWEN38_QSA_RECOMPUTE_REPLAY=1 caches frozen selection/mask/plan metadata on an invocation-local checkpoint tape. Trainable indexers use the ordinary path; K/V remain differentiable. It is distinct from RELAX_QWEN38_RETAIN_QSA_ATTENTION=1, which retains attention and checkpoints the MLP. The latter's guard is deliberately narrow: BF16, full/uniform/one-layer recomputation, TP8/PP4/CP1/EP8/ETP1; no FP8/FP4, activation offload, distributed saved activations, VPP or CUDA graphs, with validated layer owners and frozen indexers. These are optimization guards, not universal QSA limits.

Mixed geometry and document-length routing ​

The shared geometry.validate_geometry check in geometry.py is used by the public mixed entry, Grouped long adapter and direct NV adapter.

Grouped/cuDNN mixed QSA requires CUDA BF16, D256, CP1, and a frozen Stage-1 indexer. CuTe also supports the static CP path above. Local head geometry depends on the selected long-document backend:

Long backendAccepted local geometry
groupedPositive Q and KV head counts with Q divisible by KV, including 12Q/1KV, 24Q/2KV, 6Q/1KV, and 3Q/1KV; these examples are not a whitelist
cudnn_pr176524Q/2KV/D256 (TP1) and 12Q/1KV/D256 (TP2), including batches routed entirely to Flash

The framework defaults to RELAX_QWEN38_QSA_MIXED_LONG_BACKEND=grouped. The NV recipes select cudnn_pr1765. Use RELAX_QWEN38_QSA_MIXED_LONG_BACKEND=grouped for local 6Q/1KV (TP4) or 3Q/1KV (TP8).

Passing the local geometry check does not establish GPU output/gradient correctness or validate a complete TP/CP/EP training topology. Megatron and HybridEP topology constraints still apply. Packed inputs require the producer's CPU document boundaries; token positions and the incomplete causal tail remain local to each document.

The framework defaults are MIXED_LONG_BACKEND=grouped, MIXED_FLASH_MAX_LEN=-1, and MIXED_FLEX_MAX_LEN=16384 (all with prefix RELAX_QWEN38_QSA_). Let K be ID columns and B=4*K the complete-token budget after expansion:

Mixed routeShort / intermediate / long documentsConfigurable boundary
Flash/Flex/GroupedAt production K=512: typically Flash through 2051, Flex from 2052 through 16384, Grouped above 16384Automatic Flash limit is B+3; Flex maximum is 0..16384. Explicit Flash limit must be 0..B+3 and requires Flex maximum 0
Flash/cuDNNAt mandatory K=512: Flash through 2051, NV from 2052, with no Flex branchFlash limit -1 resolves to 2051; explicit range 0..2051. NV_MAX_PACK_TOKENS=0 calls NV once per long document; 0..16384 permits bounded mini-packs

These are per-document lengths, not concatenated pack sizes. The Grouped composition rebases selections and restores output order; Flex subsets can be padded to 16384 internally. NV constructs a document-local byte mask from native IDs and includes the partial tail. See Grouped dispatcher, flex.attention, NV adapter and routes.token_routes. The common QSA training script sets Flex maximum to 0, so even its Grouped recipe differs from the framework's three-way default. NV wrappers further set Flash maximum to 2051; the table later in this guide lists those recipe values.

Evidence and validation boundaries ​

This table distinguishes implementation, test coverage and recorded execution at the source baseline above. “Cases” means tests exist, not that they ran. No source-version/hardware/config-bound GPU numerical report or complete distributed-training acceptance record was located in the repository audit; those columns remain unconfirmed. PR1's session-level CPU results are recorded in the change description, not promoted to GPU evidence here.

Route / capability (implemented)CPU contract coverageGPU numerical / communication casesRecorded GPU execution / distributed training
Native dense / FlexLayout and dispatch contracts only; no CUDA numerical execution prooftest_qsa_block_mask_patch.py, test_qsa_cp_patch.py cover mask/Flex behavior and reference comparisons; not complete native dense/Flex dispatch or training coverageUnconfirmed / unconfirmed
Native id_sparseCommunity dispatch contractsNo standalone native ID-kernel numerical suite identified in this audit; mixed tests exercise its replacement, not this kernelUnconfirmed / unconfirmed
Fused v1/v2/v3Switches, tile configuration, v3 workspace guardstest_qsa_fused_attention.py: outputs/gradients, v1/v2 geometry, v3 SM103 shared-dS and fallback casesUnconfirmed / unconfirmed
Mixed Groupedtest_qsa_mixed_{routes,threshold,checkpoint,cudnn}.py: geometry, routing, boundaries/replaytest_qsa_mixed.py: packed layouts, 12/1, 24/2, 6/1, 3/1 and sparse budgetsUnconfirmed / unconfirmed
Mixed NVtest_qsa_mixed_cudnn.py: geometry rejection, metadata and mocked execution gradientsGPU file of the same name: SM100/SM103, pinned package, 12/1/D256/BF16, FP32 output/QKV-gradient referenceUnconfirmed / unconfirmed
SelectorDynamic-kernel CPU interpreter/offline compilation and dispatch casestest_qsa_select_patch.py; test_qsa_tp_selector.py includes a real two-rank NCCL TP2/CP1 testUnconfirmed / unconfirmed
CP local-query / replayReplay and layout contractsCP query-ID tests include single-GPU simulated rank slices; these do not establish multi-rank communicationUnconfirmed / unconfirmed
Routed QKV / HybridEPtest_qsa_routed_qkv.py, test_qwen38_hybridep.py: CPU routing/adjoint and mocked transport/preflightCPU mock tests are not NCCL or physical peer-discovery execution recordsUnconfirmed / unconfirmed

Test paths are under CPU contracts and GPU/backend tests. CUDA skips or missing-package skips are not passes. For future evidence, retain the source commit, image/package revisions, GPU architecture, actual TP/CP/SP/PP/EP/ETP layout, backend and selection budget, packed shapes, recomputation settings, numerical/gradient comparisons, and original logs. Distinguish a distributed numerical test from full training and optimizer/checkpoint validation.

The supplied performance chart describes a Blackwell GPU, TP2, local 12Q/1KV/D256/BF16 and explicitly excludes selector/TP from core timing. Its source commit and raw numerical/training logs are unavailable here. It can describe that external benchmark only. mixed0 and mixed16k are not current community-backend values; do not infer their exact settings from their names. pr7553 and TileLang are external benchmark labels, not enabled implementations in this checkout; community validation rejects the old pr7553/tilelang7060 values. Flash is an internal short-document kernel, not an independent global QSA selector.

Source map ​

These links identify repository implementations; function names above identify the relevant guards. Update this guide together with the source when a guard changes. Native QSA comes from the base model patch plus operator/projection integration, not from the base patch alone.

NV runtime requirements ​

Use a compatible CUDA 13 Blackwell training environment, including Megatron/Bridge, HybridEP and Flash Attention. The optional dependency is NVIDIA cuDNN Frontend PR1765, pinned to commit 627c23f62e860fe2f76d6b38d2efcc2ee84c70cd, with CuTeDSL 4.8.1.

The repository's CUDA 13 Blackwell image pins CuTeDSL to 4.6.2 through PIP_CONSTRAINT. A direct installation of 4.8.1 conflicts with that constraint, and creating a venv alone does not remove the inherited environment variable. Build a dedicated Qwen3.8 NV image instead of changing the running base environment. Save the following as Dockerfile.qsa:

dockerfile
# syntax=docker/dockerfile:1.7
ARG RELAX_BASE_IMAGE
FROM ${RELAX_BASE_IMAGE}

RUN python - <<'PY'
import os
import re
from pathlib import Path

source = Path(os.environ["PIP_CONSTRAINT"])
replaced = re.compile(
    r"^\s*nvidia[-_.](?:cutlass[-_.]dsl|cudnn[-_.]frontend)\s*(?:[<=>!~@]|$)",
    re.IGNORECASE,
)
lines = [line for line in source.read_text().splitlines() if not replaced.match(line)]
lines.append("nvidia-cutlass-dsl==4.8.1")
Path("/etc/relax-qsa-runtime-constraints.txt").write_text("\n".join(lines) + "\n")
PY

ENV PIP_CONSTRAINT=/etc/relax-qsa-runtime-constraints.txt
RUN python -m pip install --no-cache-dir --upgrade \
      'nvidia-cutlass-dsl[cu13]==4.8.1' \
      'nvidia-cudnn-frontend @ git+https://github.com/NVIDIA/cudnn-frontend.git@627c23f62e860fe2f76d6b38d2efcc2ee84c70cd' && \
    python -c 'import importlib.metadata as m; assert m.version("nvidia-cutlass-dsl") == "4.8.1"; from cudnn.QSA.api import qsa_forward, qsa_backward'

This copies the base constraints and replaces only the CuTeDSL and frontend distribution pins: CuTeDSL has an explicit version, and the frontend has an explicit source commit in the installation command. All other constraints, including Torch, NumPy and Transformer Engine, remain in effect. Do not unset PIP_CONSTRAINT globally or edit the original constraints file.

bash
docker build --build-arg RELAX_BASE_IMAGE='<your-cu13-blackwell-image>' \
  -f Dockerfile.qsa -t relax-qsa:pr1765 .

Use the derived image on every Ray node, including the head. Building the pinned frontend also requires its upstream build dependencies and a compatible cuDNN installation; follow the upstream installation instructions. A different package that only exports a module named cudnn is insufficient. Relax does not install or replace the dependency automatically. Grouped remains the framework default and does not import this optional backend.

The build and import checks cover dependency resolution, the selected CuTeDSL version and the QSA entry points. They do not establish GPU numerical correctness, TP/PP recomputation or compatibility of other kernels with the newer CuTeDSL. Validate those paths in the derived image before training; do not treat this Qwen3.8-specific variant as a validated replacement for every Blackwell recipe.

Select the recipe ​

Both recipes default to 4 nodes × 8 GPUs, 48 layers, global 24Q/2KV heads, TP2/PP4/CP1/EP8/ETP1 with sequence parallelism, BF16, GBS512/MB1, full uniform recomputation over two layers and one MTP layer.

To select TP1, append --tensor-model-parallel-size 1 to either NV recipe. Megatron disables sequence parallelism at TP1.

RecipePipeline layer countsLR decay iterationsInput
Pure text14 / 12 / 12 / 10996Text messages and tool calls
Multimodal12 / 14 / 14 / 82023Messages with image references

The text partition places three backbone QSA layers on each pipeline stage. The last stage also owns the MTP QSA layer and output head, so the total QSA counts are 3/3/3/4. The multimodal recipe keeps its separate partition; changing its PP layout is a separate tuning decision.

Run from the repository root. MODEL_DIR is the complete HF checkpoint directory, DATA_DIR is a JSONL file or directory, and SAVE_DIR is a persistent checkpoint root visible on all nodes:

bash
export MODEL_DIR=/models/qwen38
export DATA_DIR=/datasets/text
export SAVE_DIR=/checkpoints/qwen38
export MEGATRON=/workspace/Megatron-LM
export RELAX_HYBRID_EP_COMMIT='<installed-hybridep-commit>'
export RAY_JOBS_ADDRESS='http://<ray-head>:8265'

EXP_NAME=qsa-text-nv NUM_STEPS=50 \
  bash examples/models/qwen3.8-flash-next/scripts/run-qwen38-qsa-nv-text-sft-32xgpu-blackwell.sh

For image-plus-text SFT, supply a multimodal HF checkpoint and data, then use:

bash
EXP_NAME=qsa-mm-nv NUM_STEPS=50 \
  bash examples/models/qwen3.8-flash-next/scripts/run-qwen38-qsa-nv-sft-32xgpu-blackwell.sh

Both use messages and tools fields. The multimodal recipe additionally maps image to images, limits each image to 128 tokens and preprocesses images on training ranks. The text recipe omits those three multimodal options; it does not turn image data into text. Choose a text-only dataset for that recipe.

The scripts delegate cluster setup to scripts/entrypoint/ray-job.sh and then submit a Ray Job. They require an exclusive Ray Serve workspace and refuse an already-running job when invoked directly. They do not provide concurrent-job isolation. Submission blocks by default; set RAY_NO_WAIT=1 only when you want to monitor the returned job separately.

To inspect the effective command without Ray setup, network access, GPU imports or output-directory creation:

bash
DRY_RUN=1 \
  bash examples/models/qwen3.8-flash-next/scripts/run-qwen38-qsa-nv-text-sft-32xgpu-blackwell.sh

Routing and controlled comparisons ​

Each recipe sets the same routing on the driver and training actors:

SettingRecipe valueEffect
RELAX_QWEN38_QSA_COMMUNITY_BACKENDmixedKeep the existing selector and packed-input path
RELAX_QWEN38_QSA_MIXED_LONG_BACKENDcudnn_pr1765Use NV for long documents
RELAX_QWEN38_QSA_MIXED_FLASH_MAX_LEN2051Documents of at most 2051 tokens use Flash
RELAX_QWEN38_QSA_MIXED_FLEX_MAX_LEN0Disable the intermediate Flex branch
RELAX_QWEN38_QSA_NV_MAX_PACK_TOKENS0Call NV separately for each long document
NVTE_USE_CUTLASS_GROUPED_GEMM0Keep the independent MoE GEMM option off
CUDA_DEVICE_MAX_CONNECTIONS1Match the TP/sequence-parallel runtime

The 2051 boundary includes 512 complete four-token blocks and at most three partial-tail tokens. A document of length 2052 enters the sparse long branch. Use the producer's real document lengths, not the total concatenated pack length.

For a Grouped control with the same text recipe, set only the long backend and a distinct experiment identity:

bash
RELAX_QWEN38_QSA_MIXED_LONG_BACKEND=grouped EXP_NAME=qsa-text-grouped \
  bash examples/models/qwen3.8-flash-next/scripts/run-qwen38-qsa-nv-text-sft-32xgpu-blackwell.sh

Use distinct EXP_NAME or SAVE_DIR values for separate arms so one does not resume the other's checkpoint. NVTE_USE_CUTLASS_GROUPED_GEMM=1 can be supplied independently for a MoE comparison; it does not select the QSA implementation or prove that a particular MoE kernel ran. The NV mini-pack setting is experimental and remains disabled in these recipes.

Checkpoints and throughput ​

The recipes configure load and save at the stable SAVE_DIR/EXP_NAME path, save every SAVE_INTERVAL steps (default 50), and retain two Actor checkpoints. Keep that path stable to resume; do not append a fresh timestamp. ClearML task names and logs get a timestamp for each launch. The scripts configure checkpointing through the existing Megatron backend; a dry run only checks configuration, not successful optimizer/RNG restoration.

Both recipes disable custom record-function tags and autotune logging and do not enable the PyTorch profiler. They use a 120-minute producer queue timeout and zero automatic global restarts. See Performance Tuning for explicit diagnostic profiling.

Compare Actor throughput using sum of logical training tokens / sum of Actor training seconds / GPU count over the same step window. End-to-end throughput uses total step seconds instead. Preserve slow steps, list cold compilation and checkpoint saves separately, and compare equal data/topology/packing/recomputation settings. A faster QSA kernel does not imply the same speedup for the full training pipeline.

Runtime prerequisites for long-context CP ​

The 32-GPU HybridEP preflight supports TP1/PP2/EP8/ETP1 with CP8 or CP16. This requires QSA CP, the mixed community backend, and the CuTe long backend to be explicitly enabled. Physical EP membership, hostname, and accessible NVLink-domain checks still apply.

With CP16, GDN can have three local V heads. The CUDA13 image applies a FlashQLA chunk64 cumsum head-alignment patch to avoid compilation failure for this shape. It does not change the training configuration or enable an optimization policy.

Local computation for frozen PLE ​

Enable this for static CP, TP1, packed THD inputs, and fully frozen PLE parameters. This 32-GPU example uses TP1/PP2/CP8/EP8/ETP1 with a 128K sequence limit. The script forwards both PLE settings to the Ray job and training actors without script edits. Use the image with HybridEP installed as described above, and run from the repository root:

bash
export MODEL_DIR=/path/to/model
export DATA_DIR=/path/to/sft-data
export SAVE_DIR=/path/to/checkpoints
export MEGATRON=/path/to/image-patched/Megatron-LM
export RAY_JOBS_ADDRESS=http://ray-head:8265
export RAY_ADDRESS="$RAY_JOBS_ADDRESS"
export RAY_API_SERVER_ADDRESS="$RAY_JOBS_ADDRESS"
export QWEN38_PLE_INPUT_HALO_CP=1
export QWEN38_PLE_INPUT_HALO_TRANSPORT=adaptive
export RELAX_QWEN38_QSA_MIXED_LONG_BACKEND=cute
export RELAX_QWEN38_QSA_CP=1
export QWEN38_CP_SIZE=8
export QWEN38_PP_LAYOUT='Et*24|t*24mL'
export QWEN38_SFT_MODALITY=text
export QWEN38_CUDA_DEVICE_MAX_CONNECTIONS=1
export EXP_NAME=qwen38-ple-halo-cp8
NUM_STEPS=20 bash examples/models/qwen3.8-flash-next/scripts/run-qwen38-qsa-sft-32xgpu-blackwell.sh \
  --tensor-model-parallel-size 1 --pipeline-model-parallel-size 2 \
  --linear-cp-mode headwise --global-batch-size 32 --rollout-batch-size 32 \
  --max-tokens-per-gpu 16384 \
  --chunked-optimizer-state-offload --optimizer-state-offload-fraction 1.0

The trailing TP/PP arguments override the script's TP2/PP4 defaults; Megatron disables sequence parallelism at TP1. The script already freezes every PLE parameter. Add DRY_RUN=1 first to inspect the final configuration. This is a PLE launch example, not a 512K/1M capacity validation.

The feature is off by default. Each rank computes its own output rows and the left input context needed by convolution, preserving zero padding at document boundaries. Batch preparation records padded document boundaries automatically; the QSA CPU layout flag is not required. Native GPT and VL Bridge preserve PLE state per microbatch during recomputation. Requires per-document zigzag partitioning; allgather CP, dynamic CP, TP greater than one, and trainable PLE parameters are unsupported.

TransportInput communicationPLE computation
fullGather the complete inputOwned output rows and their left convolution context
halo (default when enabled)Exchange required boundary input rowsOwned output rows and their left convolution context
adaptiveUse halo if every document's CP chunk covers the left convolution context; otherwise use full for the entire batchOwned output rows and their left convolution context

full is useful for comparisons with identical inputs; it still uses local PLE computation. Boundary gradients are reduced back to the input owner. Changed reduction order can introduce BF16 differences, so validate with the intended data. This path takes precedence over the existing PLE streamed/fused-conv flags.

Building docker/Dockerfile or docker/Dockerfile.cu13 installs the required Megatron patch. External Megatron checkouts also need the patch. The 512K/1M training recipes are delivered separately.

See the long-context training recipes for 32-GPU 512K/1M entrypoints, data construction, and save/resume instructions.

Released under the Apache 2.0 License.