> This page is for version Nightly (default).
> For other versions, use one of these documentation indexes:
> - Nightly (default): https://docs.nvidia.com/nemo/automodel/nightly/llms.txt
> - Latest: https://docs.nvidia.com/nemo/automodel/latest/llms.txt
> - 0.7.0 · 26.10: https://docs.nvidia.com/nemo/automodel/v0.7/llms.txt
> - 0.5.0 · 26.06: https://docs.nvidia.com/nemo/automodel/v0.5/llms.txt
> - 0.4.0 · 26.04: https://docs.nvidia.com/nemo/automodel/v0.4/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/automodel/llms.txt.

# Qwen4-35B-A3B

> Fine-tune Qwen4-35B-A3B with NeMo AutoModel: MedPix-VQA full SFT and LoRA, 128K-token packed Tulu-3 SFT with context parallelism, and mock-token pretraining.

[Qwen4-35B-A3B](https://huggingface.co/Qwen/Qwen4-35B-A3B) is a hybrid-attention
Mixture-of-Experts (MoE) vision-language model of the
[Qwen3.8-Flash-Next](/nemo/automodel/nightly/model-coverage/large-language-models/qwen/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](/nemo/automodel/nightly/get-started/installation), then run the
LoRA recipe on four GPUs from the repository root:

```bash
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](/nemo/automodel/nightly/job-launchers/slurm-cluster) for multi-node runs; each
recipe header lists the environment variables it needs.

## Model Reference

### Model Architecture

| Property            | Value                                                                                                                  |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| **Task**            | Image-text-to-text; text generation with the language model alone                                                      |
| **Architecture**    | `Qwen4MoeForConditionalGeneration`                                                                                     |
| **Parameters**      | 56.0B in total: 35.0B decoder backbone with 3B activated per token, the 20.5B Engram table, and the 0.45B vision tower |
| **Decoder**         | 40 layers: 30 GatedDeltaNet and 10 QSA sparse-attention layers                                                         |
| **Experts**         | 256 routed experts, top-8 routing, plus one shared expert per layer                                                    |
| **Engram**          | One 20.5B-parameter N-gram Embedding table in decoder layer 2                                                          |
| **Vision tower**    | 27 layers, 16-pixel patches merged 2x2 into one language token                                                         |
| **Sequence length** | 1,048,576 native; validated here at 131,072 tokens                                                                     |

### Available Models

* [`Qwen/Qwen4-35B-A3B`](https://huggingface.co/Qwen/Qwen4-35B-A3B)

## 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

| Area                                      | Validated Configuration                                                                                                                     |
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| FSDP2                                     | 39 decoder blocks use whole-layer activation checkpointing; the Engram owner-collective block remains eager; QSA indexers are frozen        |
| Expert parallelism                        | EP16 on two nodes (full-parameter SFT); EP4 on four GPUs (LoRA)                                                                             |
| Context, pipeline, and tensor parallelism | Disabled                                                                                                                                    |
| QSA kernel                                | `model.backend.attn=fa4`                                                                                                                    |
| Workload                                  | MedPix-VQA, one image per sample resized to 64-1,024 image tokens; unpacked batches, every sample right-padded or truncated to 4,096 tokens |
| Scale                                     | 2 nodes / 16 H100 80GB (full-parameter SFT); 4 H100 80GB (LoRA)                                                                             |
| Duration                                  | 100 optimizer steps                                                                                                                         |

| Recipe                      | Batch per GPU           | Training loss, first 10 to last 10 steps | Validation loss, step 49 to step 99 | Step time | Peak PyTorch memory |
| --------------------------- | ----------------------- | ---------------------------------------- | ----------------------------------- | --------- | ------------------- |
| Full-parameter SFT, 16 GPUs | 1 sample, 4,096 tokens  | 2.140 to 1.389                           | 1.535 to 1.472                      | 1.18 s    | 43.8 GiB            |
| LoRA, 4 GPUs                | 2 samples, 4,096 tokens | 2.096 to 1.568                           | 1.611 to 1.571                      | 1.21 s    | 40.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

| Area                            | Validated Configuration                                                                                                              |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| FSDP2                           | 39 decoder blocks use whole-layer activation checkpointing; the Engram owner-collective block remains eager; QSA indexers are frozen |
| Expert parallelism              | EP16 on two nodes; two EP8 groups, one per node, under FSDP2 for two-node pretraining                                                |
| Engram ownership                | Global `Shard(0)` DTensor over all ranks: 16 contiguous local row shards                                                             |
| Context parallelism             | CP16 with 131,072-token packed (THD) sequences, 8,192 tokens per rank                                                                |
| Pipeline and tensor parallelism | Disabled                                                                                                                             |
| QSA kernel                      | `model.backend.attn=fa4`                                                                                                             |
| Workload                        | Packed (THD) Tulu-3 full-token SFT with documents shuffled before packing; fixed-length mock-token pretraining                       |
| Scale                           | 2 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

| Recipe                                                                                                                                                                       | Description                                                                                                 |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| [qwen4_35b_a3b_medpix_4k_ep16.yaml](https://github.com/NVIDIA-NeMo/Automodel/blob/main/examples/vlm_finetune/qwen3_8_flash_next/qwen4_35b_a3b_medpix_4k_ep16.yaml)           | Full-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.yaml](https://github.com/NVIDIA-NeMo/Automodel/blob/main/examples/vlm_finetune/qwen3_8_flash_next/qwen4_35b_a3b_medpix_4k_ep4_lora.yaml)   | LoRA on the QSA attention projections and the routed experts with 4,096-token samples; 4 GPUs, EP4          |
| [qwen4_35b_a3b_tulu3_packed128k_cp16_ep16.yaml](https://github.com/NVIDIA-NeMo/Automodel/blob/main/examples/llm_finetune/qwen/qwen4_35b_a3b_tulu3_packed128k_cp16_ep16.yaml) | Full-parameter SFT on Tulu-3 with 131,072-token packed sequences; 2 nodes, 16 GPUs, EP16 and CP16           |
| [qwen4_35b_a3b_fa4_ep8.yaml](https://github.com/NVIDIA-NeMo/Automodel/blob/main/examples/llm_pretrain/qwen/qwen4_35b_a3b_fa4_ep8.yaml)                                       | Pretraining 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](/nemo/automodel/nightly/model-coverage/large-language-models/qwen/Qwen3.8-Flash-Next#current-scope).
* 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.