Skip to content

v0.11.1.dev5

  • v0.11.1.dev5
  • 8662e3b
  • Partially verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
  • Choose a tag to compare

  • v0.11.1.dev5
  • 8662e3b
  • Choose a tag to compare

  • Partially verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
@samsja samsja tagged this 23 Nov 02:59
Trainer and vLLM validations are on the real 594B checkpoint. Math and
SWE RL are validated end to end on the full model.

This adds end-to-end RL support for Thinking Machines' Inkling 2 Small
(594B total / 17B active) on 8xH200 (SM90) nodes.

## What it adds

**Trainer model (`src/prime_rl/trainer/models/inkling2/`).**
- `model_type: inkling2` / `inkling2_text` (`AutoConfig` / `AutoModel`
registration).
- 48-layer text MoE: block attention residuals, relative-bias GQA over a
1K sliding window (global every sixth layer), short convolutions on K/V
and both sublayer outputs, sigmoid top-8 router with a selection bias,
384 experts with soft-capped SwiGLU.
- Conversion chain for the release's `model.llm.*` layout, including the
interleaved gate/up expert rows; the vision tower and MTP head are
dropped.
- `SoftcappedSwiglu` in the shared activation registry.
- Two flex-attention memory fixes: the block mask is built once for a
single head, so its transient is O(S²) instead of O(H·S²); and
`flex_attention` runs compiled with `dynamic=False`, so the
relative-bias score_mod is fused into the block-sparse kernel instead of
materializing the dense [heads, seq, seq] score matrix.
- `tools/convert_inkling2_mxfp8_to_bf16.py` (positional argparse)
dequantizes the release's MXFP8 experts with exact power-of-two block
scales, drops the scale tensors and writes the bf16 checkpoint.
`--shard` converts one shard for a parallel job, `--finalize` writes the
index/config; the default converts everything.

**vLLM plugin (`src/prime_rl/inference/vllm/models/inkling2/`).**
- Out-of-tree model registered through the `vllm.general_plugins` entry
point. Loads the bf16 export and applies `fp8_per_block` to the routed
experts online.
- Pure-Triton paged relative attention (sliding-window and global
layers), block attention residuals, short convolutions, fused MoE with
SiTU.
- Short-conv state is packed into a sliding-window KV cache; the conv
page is padded to the uniform attention page. With `block_size = 128`
this raises concurrency at 32K-equivalent context ~1.7-6x depending on
chunk size and async scheduling (6.5 -> 10.9 sequences per node at chunk
2048/async on, 20.9 at chunk 1024/async on, 38.3 at chunk 1024/async
off); it does not remove the limit.
- Reasoning and tool-call parsers (`inkling2`), and
`skip_special_tokens` is allowed as a per-source sampling option so the
parsers see the framing tokens.
- The online FP8 path uses vLLM's default Triton FP8 experts; the plugin
does not change backend selection for any model.

Weight updates use prime-rl's standard NCCL broadcast. A sharded
expert-sync variant may follow in a separate PR once measured.

**Renderers.** `deps/renderers` points at `c3f1177`, the squash merge of
PrimeIntellect-ai/renderers#222: template-parity Inkling 2 rendering
with sampled/content masks for plain, reasoning and tool-call turns,
`reasoning_effort` passthrough, and the `inkling2` tool parser (without
it the orchestrator renderer reports `supports_tools=False` and
tool-calling rollouts fail).

**Example configs.** `examples/advanced/inkling2/` contains math and SWE
RL recipes: six trainer nodes with FP8 on the MoE experts only, sign-SGD
and full CPU offload, plus two single-node vLLM replicas with online
`fp8_per_block` experts over prime-rl's NCCL broadcast. Math runs 8K
sequences on an i3-math band; SWE runs the ScaleSWE bash harness with a
20-turn limit and low reasoning effort at 16K. Both load the bf16 export
of `thinkingmachines/Inkling-2-Small-MXFP8` from the Hub,
`PrimeIntellect/Inkling-2-Small-bf16`.

## Validation

- Trainer vs `transformers` 5.23 on the real checkpoint: top-8
next-token predictions identical (logits mean/std agree to ~3 decimals),
NLL 19.672 vs 19.670.
- vLLM full model: GSM8K-50 49-50/50 at low reasoning effort; reload
through the prime-rl weight path is bitwise exact; prefill 21-29K tok/s
and decode ~4.2K tok/s (bs64) per 8xH200 node.
- RL smokes on a 6-layer truncated checkpoint, 1-2 nodes: `mismatch_kl`
~0.0005-0.001 per step.
- Activation checkpointing `full` mode with compiled flex attention
passes a forward/backward on a 2-layer random-weight config (1 GPU).
- All numbers are from 8xH200 nodes with `--exclusive` allocations.
- From-scratch initialization passes main's `test_scratch_init` coverage
test for both `inkling2` configs.
- Trainer vs vLLM forward parity
(`tests/unit/train/models/test_vllm_parity.py`, new `inkling2` case:
sliding + global layers, an attention-residual block boundary, short
convolutions, softcapped SiTU MoE, seeded random weights through
prime-rl's weight-update path), 1x H200: max |logprob diff| 1.86e-2,
mismatch KL 7.6e-6, top-k route agreement 97.6%; tolerances 0.05 / 2e-5.
The vLLM kernels need the sliding window to be a power of two and a
multiple of 128, so the case uses 128. The test loads vLLM plugins up
front and swaps in their config classes during engine init, since the
plugin and the trainer both register `model_type = "inkling2"`. The
other cases (qwen3, qwen3_moe, qwen3_5, qwen3_5_moe, deepseek_v4,
qwen3_8_flash_next, gpt_oss) pass unchanged.
- The trainer replays routed experts per layer (router replay), which
this case exercises.
- CPU unit tests for activation checkpointing and MoE activations pass.
`ruff check` / `ruff format` pass on the changed files.

## KL mismatch (20 math steps, `batch_size=64`)

Retested on `66597ce` (before the rebase onto main) with the full model:
`examples/advanced/inkling2/math-rl.toml` with `max_steps = 20` and
periodic checkpoints off. Setup: 6 trainer nodes (FP8 on the MoE experts
only), 2 vLLM replicas (TP8/EP8, online `fp8_per_block` experts),
standard NCCL broadcast, group size 8, 8K sequences, i3-math band [0.25,
0.5]. Every per-step mean is below 0.015: overall mean **0.0019**,
highest step **0.0026**.

| step | mean mismatch_kl | max mismatch_kl | reward (all) |
|---:|---:|---:|---:|
| 1 | 0.0016 | 1.62 | 0.611 |
| 2 | 0.0023 | 2.92 | 0.521 |
| 3 | 0.0018 | 2.41 | 0.567 |
| 4 | 0.0016 | 1.32 | 0.646 |
| 5 | 0.0022 | 3.00 | 0.396 |
| 6 | 0.0023 | 1.55 | 0.545 |
| 7 | 0.0026 | 1.45 | 0.631 |
| 8 | 0.0024 | 1.99 | 0.646 |
| 9 | 0.0018 | 3.00 | 0.740 |
| 10 | 0.0014 | 1.71 | 0.788 |
| 11 | 0.0014 | 2.73 | 0.670 |
| 12 | 0.0023 | 1.54 | 0.702 |
| 13 | 0.0019 | 2.93 | 0.835 |
| 14 | 0.0018 | 3.27 | 0.800 |
| 15 | 0.0016 | 1.48 | 0.562 |
| 16 | 0.0014 | 1.91 | 0.648 |
| 17 | 0.0021 | 3.25 | 0.662 |
| 18 | 0.0020 | 1.44 | 0.688 |
| 19 | 0.0015 | 1.99 | 0.577 |
| 20 | 0.0023 | 1.78 | 0.417 |

## Results

Full-model math RL ran for 150 steps on 6 trainer + 2 inference H200
nodes, on an i3-math band where the base model solves ~60-70% (8K
sequence, sign-SGD lr 1e-6, FP8 compute on both sides). Reward over all
episodes rose from 0.56-0.61 in the early blocks to 0.75-0.80 at the
peak (steps 91-130), and was ~0.72 at step 150; truncation fell from 29%
to 10-15%. `mismatch_kl` stayed flat at ~0.004 (range 0.0029-0.0060),
and entropy moved from 0.74 to 0.55 without collapsing. Median 107
s/step; trainer peak ~93 GiB/GPU.

Full-model SWE RL (ScaleSWE, bash harness, 20-turn limit, low reasoning
effort, 16K training sequence) also runs end to end at ~3 min/step.
`mismatch_kl` stayed flat at ~0.0047 (max 0.0070) over 85 steps. Over 85
steps, reward is noisy (all-episode 10-step blocks 0.39-0.58, mean
0.48); the clearer trend is efficiency: turns per episode fell from ~15
to ~13 and turn-limit hits from ~45% to ~28% in the last 25 steps. About
79% of rollouts came from zero-variance groups, so difficulty filtering
is the obvious next step. This is not yet a paired comparison; the task
mix may contribute.

## Related work

- #4539 (trainer model) covers the same model with a different
implementation and a CPU reference test. This branch carries the version
validated against the real checkpoint on GPU; whichever lands first, the
other can drop its copy.
- #4543 (vLLM patches for newer vLLM) will be needed when the pinned
vLLM moves; the plugin here targets the pinned vLLM 0.33.0 internals.
- Upstream vllm-project/vllm#67880 adds Hopper support for Inkling; this
is an out-of-tree port, so it can land independently.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **High Risk**
> Large new model stack spanning custom inference kernels, weight
conversion, and distributed RL; errors would affect training/inference
parity, tool parsing, and multi-node jobs despite reported validation.
> 
> **Overview**
> Adds **end-to-end RL** for Thinking Machines **Inkling 2 Small** by
introducing a trainer implementation, an out-of-tree **vLLM** model
plugin, and production-oriented **math** and **SWE** example configs on
multi-node H200.
> 
> The **trainer** path registers `inkling2` / `inkling2_text` configs
and a full text MoE stack (block attention residuals, hybrid
sliding/global attention, short convolutions, 384-expert MoE), plus an
HF↔Prime weight conversion chain (including interleaved gate/up experts)
and a new `MapValue` conversion op for dtype transforms on attn-res
queries.
> 
> The **vLLM plugin** registers via `vllm.general_plugins`, implements
the text model with Triton kernels (relative attention, attn-res, short
conv, MoE), **inkling2** reasoning/tool parsers, and optional DeepGEMM
SiTU support. Orchestrator policy sampling now permits
**`skip_special_tokens`** so tool-calling rollouts preserve framing
tokens.
> 
> **Example TOMLs** wire 6-node FP8-expert training, sign-SGD, dual vLLM
replicas with online `fp8_per_block` MoE, and task-specific settings
(i3-math band vs ScaleSWE bash harness).
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
83000423ee56799aa9b4f4d51a1381b1676a1594. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->



## Rebase update (2026-11-23)

Merged `e64ed4c` and added the corresponding activation-checkpoint and
FlexAttention API fixes. The Mini stack in #4669 passes its CPU suite,
trainer/vLLM parity, distributed invariance, and fullgraph compile
checks on H200.

---------

Co-authored-by: Konstantin Dunas <git@hallerite.com>
Co-authored-by: Vik Korrapati <vik@primeintellect.ai>
Assets 2
Loading