Skip to content

Qwen3.8 512K / 1M training ​

Two 32-GPU native SFT recipes consume real training data up to 512K or 1M tokens. They require a CUDA 13 Blackwell image with HybridEP, the FlashQLA small-head fix, and the PLE local-computation patch. Scripts alone do not add these capabilities to an older checkout.

Configuration and data ​

Shared settings: 4 nodes × 8 GPUs, TP1/PP2/EP8/ETP1, 48 layers split 24+24, MTP1, GBS32/MBS1, and seed9714. Vision, projection, PLE, and indexer parameters are frozen; full uniform recomputation uses two layers per chunk, with all optimizer state offloaded.

RecipeCP / DPSequence limitOrdinary packing budget per GPUPLE transport
512K8 / 2512K64Kfull
1M16 / 11M32Kadaptive

K=1024 and M=1024². Native SFT handles rendering, supervision masks, and data recovery without repeating or filling samples. Supply data in messages format; its lengths determine whether batches contain mixed or full-length samples. Rendered samples above the sequence limit are filtered; other samples remain intact. Supply enough valid training samples; native initialization requires at least GBS records after the evaluation split.

The 1M recipe's 32K budget is not a hard per-GPU input limit. Oversized samples occupy their own microbatch; a 1M singleton at CP16 still has 64K local tokens. full retains PLE local computation; see the PLE usage guide.

Run ​

Prepare an exclusive 32-GPU Ray cluster and model, data, and output paths accessible on every node. The entrypoint does not clean up existing jobs or guarantee GPU sharing with other training. Use the new image's Megatron and HybridEP; the image supplies RELAX_HYBRID_EP_COMMIT.

bash
export MODEL_DIR=/shared/models/Qwen3.8-Flash-Next
export DATA_DIR=/shared/data/train.jsonl
export SAVE_DIR=/shared/output/qwen38
export MEGATRON=/root/Megatron-LM
# Optional: otherwise Ray resolves the existing cluster's Jobs address.
export RAY_API_SERVER_ADDRESS=http://127.0.0.1:8265

# Inspect actual argv and worker environment, without submission or output writes.
DRY_RUN=1 bash scripts/training/sft/run-qwen38-512k-cp.sh

# Default ceiling: 200 steps. Choose one entrypoint.
bash scripts/training/sft/run-qwen38-512k-cp.sh
bash scripts/training/sft/run-qwen38-1m-cp.sh

The shared entrypoint also accepts CONTEXT_LENGTH=512k or CONTEXT_LENGTH=1m.

To reproduce the validated 512K DoSA boundary selector on SM103 GPUs, set the following variables before launching the recipe. Both entrypoints forward them to the Ray job and training workers and record them in logs/effective-config.json.

bash
export RELAX_QWEN38_QSA_SELECTOR_BACKEND=dosa
export QWEN38_DOSA_VARIANT=boundary
export QWEN38_DOSA_INTERVAL_CONFIG='{"coarse_rows":128,"coarse_keys":128,"chunk_rows":1024,"compact_tile":1024,"refine_tile":64,"capacity":256,"half_scores":true,"boundary_reuse_topk":true}'

Submission waits for the job to finish and follows its logs by default; set RAY_NO_WAIT=1 for asynchronous submission. The two recipes have separate default EXP_NAME values; each SUBMISSION_ID is unique. Submission logs and effective arguments are saved under $SAVE_DIR/$EXP_NAME/logs/. Common overrides include NUM_STEPS, EXP_NAME, SAVE_INTERVAL, MAX_TOKENS_PER_GPU, and QWEN38_PLE_INPUT_HALO_TRANSPORT. Checkpoint paths must use SAVE_DIR, EXP_NAME, and SAVE_INTERVAL; extra --load / --save arguments are rejected. Additional training arguments can be appended; changed configurations require revalidation.

Recipes do not explicitly clear the CUDA cache (--empty-unused-memory-level 0), including the first step. Checkpoint saving is disabled by default. NUM_STEPS controls optimizer updates; the native iterator reads across data epochs as needed. Do not count incomplete final batches as GBS32 validation.

Save and resume ​

bash
# Save iter_0000099 / iter_0000199 after 100 / 200 updates.
EXP_NAME=qwen38-512k-save SAVE_INTERVAL=100 \
  bash scripts/training/sft/run-qwen38-512k-cp.sh

# Resume after update 100, retaining the total ceiling of 200.
EXP_NAME=qwen38-512k-save RESUME=1 SAVE_INTERVAL=100 \
  bash scripts/training/sft/run-qwen38-512k-cp.sh --ckpt-step 99

A fresh run rejects an existing checkpoint instead of resuming implicitly. Resume requires RESUME=1, the original EXP_NAME, the checkpoint tracker, and the generated recipe-config.json. The entrypoint compares context length, data/model paths, parallel configuration, packing budget, GBS, seed, learning rates, and extra arguments to prevent loading incompatible configurations. Do not edit the record to bypass validation.

Resume automatically adds --use-checkpoint-opt_param-scheduler, restoring the saved LR/WD schedule. NUM_STEPS controls the stopping point, not a new restored schedule. Model, optimizer, and data position use native checkpoint recovery. Without SAVE_INTERVAL, data position is not saved separately; this recipe has no separate data-state directory.

Validation scope ​

These are historical results from a PR3 version with benchmark data construction, not GPU revalidation of the new native SFT entrypoints. Mixed-length 512K used original samples; mixed-length 1M doubled them, and full-length inputs repeated samples to the target length. Production throughput depends on actual lengths and packing.

That version completed 20 steps per scenario on 4 nodes × 8 Blackwell GPUs (approximately 269 GiB visible memory per GPU), without explicit cache clearing at any step. TPS/card and MFU use aggregate training time over steps 5–19. Memory covers the complete 20-step prefix; free memory is sampled through NVML.

ScenarioTPS/cardMFUPeak reservedMinimum sampled free memory
mixed51226245.52%219.33 GiB24.72 GiB
filled51233147.07%229.51 GiB14.14 GiB
mixed1m24965.28%176.11 GiB66.93 GiB
filled1m27015.87%214.85 GiB25.29 GiB

All scenarios had complete GBS 32 batches, finite loss/MTP loss/grad norm, and no reported skipped updates. Per-step comparisons cover loss, MTP loss, grad norm, LR, and token/packing metrics.

mixed512 and mixed1m matched history exactly. For the first 20 steps, filled512 had maximum absolute loss difference 3.59e-6 and relative grad-norm difference 0.41%; filled1m had 3.30e-6 and 0.65%, respectively.

Extending the first filled512 run to 25 steps produced a maximum relative grad-norm difference of 2.02%; a separate 20-step repeat with the same configuration matched history exactly. Repeated runs are not guaranteed to be bitwise identical; the cause remains unresolved.

A further 100-step mixed1m run used no explicit cache clearing: steps 5–99 reached 2580 TPS/card and 5.46% MFU, with peak reserved memory of 195.21 GiB and minimum sampled free memory of 47.26 GiB. LR, token and packing metrics matched history; maximum absolute loss/MTP CE differences were 2.87e-4/3.09e-4 and relative grad-norm difference was 31.21%. All values were finite, but the cause remains unresolved and long-run numerical equivalence is not established. This run did not save checkpoints.

A same-code 10-step mixed512 cache-control comparison matched loss/MTP loss/grad norm/LR exactly. Over steps 5–9, no explicit cache clearing achieved 2884 TPS/card, versus 1444 with per-step clearing (level 1).

Earlier long runs covered 200 mixed512 steps plus 10 resumed steps, 100 mixed1m steps, and 40 steps for each filled scenario. The resumed mixed512 loss/MTP loss/grad norm/LR/data position matched continuous training exactly; save/resume was not separately validated for the other scenarios. This 20-step revalidation did not repeat GPU checkpoint recovery or rebuild the image.

The native SFT entrypoints reject resume manifests from the old benchmark-data recipes; use a new experiment name.

Released under the Apache 2.0 License.