---
id: harness-adapters/Qwen3.8-Flash-Next
title: Qwen3.8-Flash-Next harness adapter
type: recipe
project: harness-adapters
model_id: Qwen/Qwen3.8-Flash-Next
trainers:
- AsyncGRPOTrainer
platforms:
- slurm
gpus: []
verified: {}
trl_source:
- TRL fork
tags:
- lora
- agentic-rl
- harbor
- safeagents
- fsdp2
- slurm
- thinking
date_added: '2026-11-25'
url: https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/index.html
markdown_url: https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/index.md
json_url: https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/recipe.json
yaml_url: https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/recipe.yaml
hub_tree: https://huggingface.co/spaces/trl-lib/trl-recipes/tree/main/recipes/harness-adapters/Qwen3.8-Flash-Next
---

# Qwen/Qwen3.8-Flash-Next — Harness adapters

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.

## Summary & Links

- **Recipe ID:** `harness-adapters/Qwen3.8-Flash-Next`
- **Model:** [Qwen/Qwen3.8-Flash-Next](https://huggingface.co/Qwen/Qwen3.8-Flash-Next)
- **Project:** [Harness adapters](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/index.md)
- **Trainers:** `AsyncGRPOTrainer`
- **Harnesses:** `pi`
- **Platforms:** SLURM only
- **Interactive command builder:** https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/index.html
- **Structured JSON:** https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/recipe.json
- **Recipe YAML:** https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/recipe.yaml
- **Space files:** https://huggingface.co/spaces/trl-lib/trl-recipes/tree/main/recipes/harness-adapters/Qwen3.8-Flash-Next

## Quickstart Commands

This recipe ships SLURM scripts only (no local or HF Jobs launcher). Fetch the project files with:

```bash
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`](https://huggingface.co/Qwen/Qwen3.8-Flash-Next) (180B, thinking
on) work better inside the [pi](https://github.com/earendil-works/pi) coding agent, trained with async GRPO on the 750
scale800 tasks interleaved with 300 TermGrade tasks, every tool call checked by
[safeagents](https://github.com/huggingface/safeagents). Full settings: [recipe.yaml](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/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](https://huggingface.co/spaces/trl-lib/trl-recipes/blob/main/recipes/harness-adapters/Qwen3.8-Flash-Next/train_slurm.sh),
[eval_slurm.sh](https://huggingface.co/spaces/trl-lib/trl-recipes/blob/main/recipes/harness-adapters/Qwen3.8-Flash-Next/eval_slurm.sh),
[async_grpo_harbor.py](https://huggingface.co/spaces/trl-lib/trl-recipes/blob/main/recipes/harness-adapters/Qwen3.8-Flash-Next/async_grpo_harbor.py) (the training script, with the FSDP2 loading),
[make_launcher_fsdp.py](https://huggingface.co/spaces/trl-lib/trl-recipes/blob/main/recipes/harness-adapters/Qwen3.8-Flash-Next/make_launcher_fsdp.py),
[modeling_qwen4_exp.flashnext.py](https://huggingface.co/spaces/trl-lib/trl-recipes/blob/main/recipes/harness-adapters/Qwen3.8-Flash-Next/modeling_qwen4_exp.flashnext.py),
[trl.patch](https://huggingface.co/spaces/trl-lib/trl-recipes/blob/main/recipes/harness-adapters/Qwen3.8-Flash-Next/trl.patch),
and the shared [scripts/](https://huggingface.co/spaces/trl-lib/trl-recipes/tree/main/recipes/harness-adapters/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](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/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`, and
  `VLLM_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.

```sh
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

```sh
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).

```sh
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

| Parameter | Value |
|---|---|
| `lora_r` | `32` |
| `lora_target_modules` | `q_proj, k_proj, v_proj, o_proj` |
| `learning_rate` | `2e-5` |
| `num_generations` | `8` |
| `gradient_accumulation_steps` | `4` |
| `max_staleness` | `16` |
| `temperature` | `0.8` |
| `max_completion_length` | `32,768` |
| `max_model_len` | `65,536` |
| `token_budget` | `65,536` |
| `agent_step_limit` | `50` |
| `agent_timeout_s` | `1,800` |
| `max_inflight` | `64` |
| `tool_efficiency_weight` | `0.1` |
| `max_steps` | `1,000` |
| `save_steps` | `5` |
| `thinking` | `true` |

### Serving (vLLM)

| Setting | Value |
|---|---|
| `tool_call_parser` | `qwen3_coder` |
| `reasoning_parser` | `qwen3` |
| `extra_args` | `--language-model-only, --enable-prefix-caching, --mamba-cache-mode align, --tensor-parallel-size 4, --enable-expert-parallel, --disable-custom-all-reduce, --model-loader-extra-config '{"enable_weights_track": false}'` |
| `env` | `{"VLLM_ALLREDUCE_USE_FLASHINFER": "0"}` |

## Datasets

### Training

- [`harness-hub/scale800-harbor@56c7f75d01f70859ec1354e97866e32a175c1a40`](https://huggingface.co/datasets/harness-hub/scale800-harbor)
- [`harness-hub/termgrade-train-harbor`](https://huggingface.co/datasets/harness-hub/termgrade-train-harbor)

### Evaluation

| Benchmark | Details |
|---|---|
| `tbfull` | harborframework/terminal-bench-2.1@3e235dff6880252a587fa479c09bcb1e16edf2eb, all 89 tasks, 3600 s and 100 steps |
| `sbp` | harness-hub/swebench-pro-v2-hard51-harbor, 7200 s and 100 steps |

## TRL Version

- **Upstream base:** [`huggingface/trl@d115286b`](https://github.com/huggingface/trl/commit/d115286bc5aef8d346e8510bfe312803c7881c4a)
- **Patch file:** [trl.patch](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/trl.patch)

```bash
git 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 apply
```

## Files

- [`recipe.yaml`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/recipe.yaml) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/Qwen3.8-Flash-Next/recipe.yaml))
- [`trl.patch`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/trl.patch) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/Qwen3.8-Flash-Next/trl.patch))
- [`async_grpo_harbor.py`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/async_grpo_harbor.py) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/Qwen3.8-Flash-Next/async_grpo_harbor.py))
- [`make_launcher_fsdp.py`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/make_launcher_fsdp.py) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/Qwen3.8-Flash-Next/make_launcher_fsdp.py))
- [`modeling_qwen4_exp.flashnext.py`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/modeling_qwen4_exp.flashnext.py) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/Qwen3.8-Flash-Next/modeling_qwen4_exp.flashnext.py))
- [`eval_slurm.sh`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/eval_slurm.sh) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/Qwen3.8-Flash-Next/eval_slurm.sh))
- [`train_slurm.sh`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/Qwen3.8-Flash-Next/train_slurm.sh) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/Qwen3.8-Flash-Next/train_slurm.sh))

### Shared by project

- [`scripts/async_grpo_harbor.py`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/scripts/async_grpo_harbor.py) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/scripts/async_grpo_harbor.py))
- [`scripts/atif_harbor.py`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/scripts/atif_harbor.py) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/scripts/atif_harbor.py))
- [`scripts/atif_smoldataenvs.py`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/scripts/atif_smoldataenvs.py) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/scripts/atif_smoldataenvs.py))
- [`scripts/atif_traj2envs.py`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/scripts/atif_traj2envs.py) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/scripts/atif_traj2envs.py))
- [`scripts/deepseek_harness.py`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/scripts/deepseek_harness.py) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/scripts/deepseek_harness.py))
- [`scripts/eval_sweep.py`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/scripts/eval_sweep.py) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/scripts/eval_sweep.py))
- [`scripts/evaluate_harbor.py`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/scripts/evaluate_harbor.py) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/scripts/evaluate_harbor.py))
- [`scripts/launcher_eval.py`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/scripts/launcher_eval.py) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/scripts/launcher_eval.py))
- [`scripts/launcher_train.py`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/scripts/launcher_train.py) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/scripts/launcher_train.py))
- [`scripts/release_adapters.py`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/scripts/release_adapters.py) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/scripts/release_adapters.py))
- [`scripts/slurm_setup.sh`](https://trl-lib-trl-recipes.static.hf.space/recipes/harness-adapters/scripts/slurm_setup.sh) ([Hub raw](https://huggingface.co/spaces/trl-lib/trl-recipes/raw/main/recipes/harness-adapters/scripts/slurm_setup.sh))
