Skip to navigation

Qwen4-35B-A3B

View as MarkdownOpen in Claude

Qwen4-35B-A3B is a hybrid-attention Mixture-of-Experts (MoE) vision-language model of the Qwen3.8-Flash-Next architecture family: GatedDeltaNet and QSA sparse-attention layers, four persistent HyperConnection streams, and one Engram N-gram Embedding table, paired with a Qwen3-VL-style vision tower. Its configuration declares Qwen4MoeForConditionalGeneration; NeMo AutoModel loads it with the Qwen3_8_FlashNextForConditionalGeneration implementation, with every size and the Engram table layout taken from the checkpoint configuration.

This page covers image-text fine-tuning on MedPix-VQA, language-only fine-tuning on 128K-token packed sequences, and mock-token pretraining.

Fine-Tune Qwen4-35B-A3B

Follow the installation instructions, then run the LoRA recipe on four GPUs from the repository root:

automodel examples/vlm_finetune/qwen3_8_flash_next/qwen4_35b_a3b_medpix_4k_ep4_lora.yaml --nproc-per-node 4

The other three recipes each run on 2 nodes of 8 H100 GPUs. Use the Slurm Launcher Guide for multi-node runs; each recipe header lists the environment variables it needs.

Model Reference

Model Architecture

PropertyValue
TaskImage-text-to-text; text generation with the language model alone
ArchitectureQwen4MoeForConditionalGeneration
Parameters56.0B in total: 35.0B decoder backbone with 3B activated per token, the 20.5B Engram table, and the 0.45B vision tower
Decoder40 layers: 30 GatedDeltaNet and 10 QSA sparse-attention layers
Experts256 routed experts, top-8 routing, plus one shared expert per layer
EngramOne 20.5B-parameter N-gram Embedding table in decoder layer 2
Vision tower27 layers, 16-pixel patches merged 2x2 into one language token
Sequence length1,048,576 native; validated here at 131,072 tokens

Available Models

Architecture

  • The decoder repeats three GatedDeltaNet layers followed by one QSA sparse-attention layer. QSA compresses index keys in groups of four, selects up to 512 causal groups (2,048 tokens), appends the incomplete causal tail, and evaluates main grouped-query attention (16 query heads, 2 key/value heads) only on the selected tokens.
  • Decoder layer 2 adds Engram values derived from eight raw-token bigram hashes and eight raw-token trigram hashes. The table has 160,003,584 padded rows of width 128.
  • Four 2,048-wide HyperConnection streams are read and written by every attention and MoE block; a final learned read collapses them before the untied language-model head.

Image Input

  • The vision tower’s merged features replace the embeddings of the image placeholder tokens. QSA layers use three-axis (temporal, height, width) rotary positions: text tokens advance all three axes together, and an image that starts at position p uses p + row and p + column on the height and width axes; the token after it continues at p + max(rows, columns).
  • The Engram layer hashes the raw token IDs, image placeholders included, as the reference implementation does.

Validated Configuration

Image-Text Fine-Tuning

AreaValidated Configuration
FSDP239 decoder blocks use whole-layer activation checkpointing; the Engram owner-collective block remains eager; QSA indexers are frozen
Expert parallelismEP16 on two nodes (full-parameter SFT); EP4 on four GPUs (LoRA)
Context, pipeline, and tensor parallelismDisabled
QSA kernelmodel.backend.attn=fa4
WorkloadMedPix-VQA, one image per sample resized to 64-1,024 image tokens; unpacked batches, every sample right-padded or truncated to 4,096 tokens
Scale2 nodes / 16 H100 80GB (full-parameter SFT); 4 H100 80GB (LoRA)
Duration100 optimizer steps
RecipeBatch per GPUTraining loss, first 10 to last 10 stepsValidation loss, step 49 to step 99Step timePeak PyTorch memory
Full-parameter SFT, 16 GPUs1 sample, 4,096 tokens2.140 to 1.3891.535 to 1.4721.18 s43.8 GiB
LoRA, 4 GPUs2 samples, 4,096 tokens2.096 to 1.5681.611 to 1.5711.21 s40.0 GiB

Both runs completed without NaNs or collective errors. A step trains 16 samples in the full-parameter recipe and 8 in the LoRA recipe, and the validation passes cover 335,473 and 335,097 label tokens. MedPix-VQA samples average about 370 tokens at these image sizes, so about 9% of each 4,096-token row is content and the rest is padding. Peak GPU memory was 53.0 GiB (full-parameter) and 46.3 GiB (LoRA). The LoRA run wrote its adapter, optimizer, and RNG state at the last step. The full-parameter run used NCCL’s internal InfiniBand (IB) transport (NCCL_NET_PLUGIN=none and NCCL_NET=IB).

Text Fine-Tuning and Pretraining

AreaValidated Configuration
FSDP239 decoder blocks use whole-layer activation checkpointing; the Engram owner-collective block remains eager; QSA indexers are frozen
Expert parallelismEP16 on two nodes; two EP8 groups, one per node, under FSDP2 for two-node pretraining
Engram ownershipGlobal Shard(0) DTensor over all ranks: 16 contiguous local row shards
Context parallelismCP16 with 131,072-token packed (THD) sequences, 8,192 tokens per rank
Pipeline and tensor parallelismDisabled
QSA kernelmodel.backend.attn=fa4
WorkloadPacked (THD) Tulu-3 full-token SFT with documents shuffled before packing; fixed-length mock-token pretraining
Scale2 nodes / 16 H100 80GB

The 128K-token packed run trained 100 optimizer steps of one 131,072-token pack each (12.9M tokens, 7.9M of them supervised). Training loss fell from a mean of 0.972 over the first 10 steps to 0.741 over the last 10, and the gradient norm from 2.99 to 0.45. Steady-state throughput was 57,894 tokens per second (3,618 per GPU, 2.23 seconds per step) with a peak of 43 GiB of PyTorch memory and 58 GiB of GPU memory per GPU. The run completed without NaNs or collective errors and used NCCL’s internal InfiniBand (IB) transport (NCCL_NET_PLUGIN=none and NCCL_NET=IB).

The pretraining recipe was run with --benchmark on 2 nodes / 16 H100 80GB, from random initialization on mock tokens: two 8,192-token sequences per GPU and step, FSDP2 over the 16 GPUs with two EP8 groups (one per node), and model.backend.compile_hc=true. Over 30 steps after 20 warm-up steps it reached 130,634 tokens per second (8,165 per GPU, 2.01 seconds per step), a model FLOPs utilization (MFU) of 17.5%, with a peak of 56 GiB of PyTorch memory and 66 GiB of GPU memory per GPU. The first run on a node, with empty compile caches, peaked at 74 GiB of GPU memory. --benchmark turns on balanced routing, so the number excludes routing imbalance and is not a measurement of learned routing.

Example Recipes

RecipeDescription
qwen4_35b_a3b_medpix_4k_ep16.yamlFull-parameter SFT on MedPix-VQA with a frozen vision tower and 4,096-token samples; 2 nodes, 16 GPUs, EP16
qwen4_35b_a3b_medpix_4k_ep4_lora.yamlLoRA on the QSA attention projections and the routed experts with 4,096-token samples; 4 GPUs, EP4
qwen4_35b_a3b_tulu3_packed128k_cp16_ep16.yamlFull-parameter SFT on Tulu-3 with 131,072-token packed sequences; 2 nodes, 16 GPUs, EP16 and CP16
qwen4_35b_a3b_fa4_ep8.yamlPretraining from random initialization on mock tokens; 2 nodes, 16 GPUs, FSDP2 with two EP8 groups

Current Scope

  • Apart from image input, the feature scope and limits of the implementation are those listed on the Qwen3.8-Flash-Next page.
  • Image inputs are supported for padded [batch, sequence] batches. Video inputs, and image inputs combined with context parallelism, pipeline parallelism, or packed sequences, are rejected with an error.
  • model.backend.attn=fa4 builds a route byte mask of shape [local queries, global keys] that is limited to 2^31 entries per call. A 131,072-token pack therefore needs at most 8,192 tokens per context-parallel rank (cp_size >= 16).
  • Full-parameter SFT keeps weights, gradients, and optimizer state for 55.5B trainable parameters: about 65 GiB per GPU on 8 GPUs and 32 GiB on 16. The full-parameter recipes therefore use two nodes.