Qwen/Qwen3.8-Flash-Next
A pi harness adapter for the 180B Qwen3.8-Flash-Next, thinking on, trained with async GRPO on agentic coding and terminal tasks (scale800 + TermGrade). One 8-GPU B300 node: vLLM tensor + expert parallel on 4 GPUs, the LoRA trainer sharded with FSDP2 over the other 4. SLURM scripts only.
Fetch recipe files
SLURM scripts only — see Guide below for cluster commands
hf download trl-lib/trl-recipes --repo-type space --include "recipes/harness-adapters/*" --local-dir trl-recipes
cd trl-recipes/recipes/harness-adapters/Qwen3.8-Flash-Next
Guide
A LoRA adapter that makes Qwen/Qwen3.8-Flash-Next (180B, thinking
on) work better inside the pi coding agent, trained with async GRPO on the 750
scale800 tasks interleaved with 300 TermGrade tasks, every tool call checked by
safeagents. Full settings: recipe.yaml.
This recipe runs on a SLURM cluster only: it needs a whole node with 8 B300 GPUs (288 GB each). The model is 360 GB in BF16, so vLLM serves it tensor- and expert-parallel over 4 GPUs, and the trainer shards it with FSDP2 over the other 4 (266 of 268 GiB used per trainer GPU).
| command | GPUs | |
|---|---|---|
| Train | sbatch -p <partition> train_slurm.sh |
8 (one node, exclusive) |
| Eval | BENCH=tbfull\|sbp POLICIES="<checkpoint or Qwen/Qwen3.8-Flash-Next>@pi" sbatch -p <partition> eval_slurm.sh |
2 |
Files: train_slurm.sh,
eval_slurm.sh,
async_grpo_harbor.py (the training script, with the FSDP2 loading),
make_launcher_fsdp.py,
modeling_qwen4_exp.flashnext.py,
trl.patch,
and the shared scripts/
(launcher_train.py, launcher_eval.py, evaluate_harbor.py, atif_harbor.py, slurm_setup.sh).
What differs from the other harness-adapter recipes #
- FSDP2 trainer. The training script loads the model with FSDP2 over the trainer GPUs (one process per GPU, started
by
torch.distributed.run) instead of splitting it with a device map. Two embedding tables stay outside FSDP: the 95 GiB n-gram table on CPU, and the token embedding replicated on each GPU. With this, the trainer's log-probs stay within 0.06 of vLLM's. - Tree packing for Qwen4-Exp. Rollouts that share a prefix are packed as a tree. The model's query-sparse attention, n-gram shift and short convolution are routed through three module-level functions of a patched modeling file, which trl.patch replaces with tree-aware versions.
- Thinking on, as the model's default: up to 32,768 output tokens per call in a 65,536-token window.
- vLLM settings:
--enable-expert-parallel,--disable-custom-all-reduce,--model-loader-extra-config '{"enable_weights_track": false}', prefix caching in--mamba-cache-mode align, andVLLM_ALLREDUCE_USE_FLASHINFER=0(FlashInfer's all-reduce crashed at tensor parallel above 1 on B300).
One-time setup #
Everything lives under ROOT (default $HOME/harness-adapters); put it on storage every node sees.
export ROOT=$HOME/harness-adapters
# 1. This project: the recipe folder and the shared scripts, at $ROOT/Qwen3.8-Flash-Next and $ROOT/scripts
hf download trl-lib/trl-recipes --repo-type space --include "recipes/harness-adapters/*" --local-dir /tmp/recipes
cp -r /tmp/recipes/recipes/harness-adapters/. $ROOT/
# 2. The launcher's venv ($ROOT/venv): the dependencies in the header of scripts/launcher_train.py, with transformers at
# the commit this recipe was run with
uv venv $ROOT/venv --python 3.12
uv pip install --python $ROOT/venv/bin/python "transformers @ git+https://github.com/huggingface/transformers@66f51e76" <the header's other dependencies>
# 3. TRL: upstream at the patch's base, with the patch applied ($ROOT/trl)
git clone https://github.com/huggingface/trl $ROOT/trl && git -C $ROOT/trl checkout d115286bc5aef8d346e8510bfe312803c7881c4a
git -C $ROOT/trl apply $ROOT/Qwen3.8-Flash-Next/trl.patch
# 4. The modeling overlay ($ROOT/overlay-flashnext): the venv's transformers with Qwen4-Exp's modeling file replaced
T=$($ROOT/venv/bin/python -c "import os, transformers; print(os.path.dirname(transformers.__file__))")
mkdir -p $ROOT/overlay-flashnext && cp -r "$T" $ROOT/overlay-flashnext/transformers
cp $ROOT/Qwen3.8-Flash-Next/modeling_qwen4_exp.flashnext.py $ROOT/overlay-flashnext/transformers/models/qwen4_exp/modeling_qwen4_exp.py
# 5. vLLM in its own venv ($ROOT/venv-vllm), a version that serves Qwen3.8-Flash-Next with runtime LoRA
# 6. The multi-GPU launcher, written next to launcher_train.py
$ROOT/venv/bin/python $ROOT/Qwen3.8-Flash-Next/make_launcher_fsdp.py $ROOT/scripts/launcher_train.py
Both scripts read HF_TOKEN (or ~/.cache/huggingface/token), which the HF sandboxes the tasks run in also use.
TRL_SRC, OVERLAY, VLLM_VENV and HF_HUB_CACHE override the default locations.
Training #
MAX_STEPS=3 sbatch --time=3:00:00 -p <partition> train_slurm.sh # smoke run: check the log-prob gap first
sbatch -p <partition> train_slurm.sh # full run, a checkpoint every 5 steps
Checkpoints are written to $ROOT/data/runs/<run>/checkpoint-N (adapter only). To resume, pass
TRAIN_EXTRA="--resume-from-checkpoint $ROOT/data/runs/<run>/checkpoint-N".
Evaluation #
Each policy is served alone on 2 GPUs: the base, or a LoRA checkpoint served at runtime next to it (merging would write a 360 GB model per checkpoint).
BENCH=tbfull POLICIES="Qwen/Qwen3.8-Flash-Next@pi" sbatch -p <partition> eval_slurm.sh
BENCH=sbp POLICIES="$ROOT/data/runs/<run>/checkpoint-100@pi $ROOT/data/runs/<run>/checkpoint-140@pi" sbatch -p <partition> eval_slurm.sh
Results land in $ROOT/data/eval/<policy>_<tag>/. Infrastructure failures (no turns, or an error within 2 model calls)
are set aside and rerun, up to 3 attempts. Set BUCKET=<owner>/<name> to copy the eval folders to an HF bucket as they
fill.
Results so far #
Terminal-Bench 2.1 (87 graded tasks) and SWE-bench Pro hard 51, thinking on, one attempt per task, paired with the base; output tokens and tool calls on the tasks both solved.
| TB 2.1 | SWE-bench Pro | output tokens (TB, SBP) | tool calls (TB, SBP) | |
|---|---|---|---|---|
| base | 64/87 (73.6%) | 46/51 (90.2%) | ||
| checkpoint 100 | 60/87 | 44/51 | -41%, -31% | -32%, -25% |
| checkpoint 140 | 59/87 | 41/51 | -48%, -39% | -39%, -33% |
The adapter solves nearly the same tasks with far less work; later checkpoints save more tokens but lose more accuracy, and checkpoint 140 sometimes stops after one or two model calls. Training is still running.
Hyperparameters
Serving (vLLM)
Datasets
Training
Evaluation
TRL version
This recipe runs on a TRL fork. trl.patch holds the changes to trl/ relative to the upstream base commit.
huggingface/trl@d115286bgit clone https://github.com/huggingface/trl && cd trl
git checkout d115286bc5aef8d346e8510bfe312803c7881c4a
curl -sL https://huggingface.co/spaces/trl-lib/trl-recipes/resolve/main/recipes/harness-adapters/Qwen3.8-Flash-Next/trl.patch | git applyDownload trl.patch (7 files changed)
Files
async_grpo_harbor.py↗make_launcher_fsdp.py↗modeling_qwen4_exp.flashnext.py↗eval_slurm.sh↗train_slurm.sh↗index.mdrecipe.json