Skip to content

Add cached PLE support to Flash-Next generation - #6203

Open
liangel-02 wants to merge 1 commit into
qwen38-rl-2-indexerfrom
qwen38-rl-3-ple
Open

liangel-02 wants to merge 1 commit into
qwen38-rl-2-indexerfrom
qwen38-rl-3-ple

Conversation

@liangel-02

@liangel-02 liangel-02 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

PLE needs the preceding token IDs for n-gram hashing and the preceding normed
activations for its dilated convolution. A decode call supplies only new tokens,
so running the training PLE path independently on each call loses that history.
Row-owned PLE parameters also sit outside FSDP load groups and need explicit
handling during policy updates.

For a request split into 3 + 14 + 10 tokens, cached PLE must match one full
27-token evaluation. Reordering requests or reusing a finished request's state
must not mix their histories.

  • Add VLLMPLELayer (torchtitan/rl/generator/vllm/model/ple.py). Each request's
    history is the last (kernel_size - 1) * dilation normed rows (BF16) and the
    last ngram_size - 1 token IDs (int64), indexed circularly. It lives in
    model-owned buffers that the worker allocates after vLLM binds the KV cache,
    indexed by the state slots of the same layer's GDN attention, so it follows
    that request's slot through reordering and slot reuse. Packed steps store
    only each request's final window.
  • PLE registers no KV-cache spec of its own. vLLM's hybrid KV-cache manager
    gives every group the layer count of the smallest spec bucket, so a
    one-layer PLE state forced one layer per group for all of Flash-Next: 73
    KV-cache groups, each building attention metadata every step, instead of 6.
    A TODO marks this workaround until vLLM supports per-bucket group sizes. A
    PLE layer without GDN attention raises ValueError.
  • The generator reuses the trainer's math. NGramEmbedding.mix_hashes,
    NGramEmbedding.lookup/gather_features, PLELayer.gate_score/gate_apply
    and PLELayer.conv_shifts/conv_output are split out of the training
    forward; trainer outputs and gradients are bitwise unchanged.
  • Decode-sized steps (at most max_num_seqs tokens on every DP rank)
    all-gather hash IDs over the row mesh, look up locally owned rows (non-owned
    rows read as -0.0) and reduce-scatter, which is bitwise equal to a plain
    gather. Larger steps keep the row-sharded slot route, now sized by the step's
    DP-max token count instead of max_num_batched_tokens.
  • local_compile regions: the trainer's PLE hashing, gate and convolution
    register as ple_hash_ids, ple_gate and ple_conv. They are not added to
    the Flash-Next defaults, so recipes keep running PLE eagerly; enabling them by
    default needs trainer loss, step-time and memory evidence and is left to a
    follow-up. The generator's gate (as two functions so its BF16 rounding
    matches the trainer's training-mode graph) and tiled convolution register
    under ple_gate and ple_conv, so they compile exactly when the trainer's
    do. History reads with hashing, the owned-row
    lookup and the per-token request indices (vllm_query_requests in
    attention/query_positions.py) register under the shared
    inference_batch_invariant region.
  • _replace_vllm_layer_configs swaps PLELayer.Config for
    VLLMPLELayer.Config, the same path that swaps in the QSA, GDN, and KDA
    generation layers.
  • Load non-FSDP parameters into their existing storage, while preserving frozen
    parameters and requiring every published trainable parameter to be filled.
  • VLLMPLELayer rejects prefix caching, mamba_cache_mode other than
    "none" (its history follows a fixed GDN state slot), and speculative
    decoding.
  • The history buffers take about 180 KiB per GDN state slot for the 125B
    model's PLE layer (9 x 10240 BF16 rows plus 2 int64 IDs). GDN has one state
    slot per KV-cache block, so the total scales with vLLM's KV-cache size, not
    with max_num_seqs: at DP4/EP4 on GB300 (4,081,987 KV-cache tokens in
    1568-token blocks, about 2,600 slots) they take about 0.45 GiB per GPU. They
    are allocated after vLLM sizes the KV cache, so they come out of the memory
    headroom left for CUDA graph capture. At most max_num_seqs slots are live at
    once; accounting for the buffers before KV sizing, or sizing them to live
    requests through a slot-to-row map, is a possible follow-up.

The generator passes PLE its token IDs and positions through the stock vLLM model wrapper; #6206 lets the Flash-Next model default them.

Before After
PLE loses history between generation calls Chunked prefill/decode keeps per-request history, keyed by the layer's GDN state slot
Loader requires every parameter to belong to FSDP Row-owned parameters load in place; frozen rows stay resident
pytest -q tests/rl/unit_tests/gpu/test_vllm_ple.py
pytest -q tests/rl/unit_tests/cpu/test_vllm_wrapper.py \
  tests/rl/unit_tests/cpu/test_vllm_registry.py \
  tests/rl/unit_tests/cpu/test_generator_model.py \
  tests/rl/unit_tests/cpu/test_model_defaults.py

test_vllm_ple.py passes, including the 2-GPU owned-row gather test. Generator
PLE output is bitwise equal to the trainer PLELayer through chunk boundaries,
EOS resets, request reordering, state-slot reuse and padded single-token decode
steps, with eager, partial and full local_compile regions. The owned-row
gather is bitwise equal to the slot route with uneven DP token counts. The CPU
RL and Flash-Next suites pass (67 passed, 2 skipped).

Against the trainer's training-mode compiled PLE at production dimensions, the
generator output is 99.57% bitwise at batch 8 decode (max abs 0.031; the rest
comes from the M=8 split-K GEMM, which also differs eager vs eager), 100% at
batch 64 decode, and at least 99.995% for packed steps. Compiling the gate as
one region, as before, matched only about 84%.

PLE layer cost per step (4-layer Flash-Next slice, dummy weights, 2 GB300 at
DP2/EP2, FULL_DECODE_ONLY graphs, summed kernel time between marker kernels,
contexts = DAPO prompt + uniform(1, 4096) generated tokens):

Shape This PR SGLang (Miles, TP2/EP2)
Decode, batch 8 63.3 us 68 us
Decode, batch 16 61.9 us 72.1 us
Decode, batch 64 70.0 us 111 us
8 decoding + 8x210 arriving 514 us 1318 us
64 decoding + 8x210 arriving 543 us 1309 us

Two ranks only; at 8 ranks both sides' communication costs change. Loading a
production checkpoint end to end and an RL convergence run are not part of this
PR. Validation used an Attention Gym development build with the paged sparse
APIs; the pinned attn-gym==0.0.20 alone does not supply them.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 19, 2026
@liangel-02
liangel-02 changed the base branch from qwen38-rl-2-indexer to qwen3-8-fn-6-pipeline November 19, 2026 01:38
liangel-02 added a commit that referenced this pull request Nov 19, 2026
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why

PLE needs preceding token IDs for n-gram hashing and preceding activations for
its dilated convolution. A decode call supplies only new tokens, so running the
training PLE path independently on each call loses that history. Row-owned PLE
parameters also sit outside FSDP load groups and need explicit handling during
policy updates.

For a request split into `3 + 14 + 10` tokens, cached PLE must match one full
27-token evaluation. Reordering requests or reusing a completed request's pages
must not mix their histories.

## What changed

- Add a Flash-Next wrapper and PLE implementation retaining request-local token
  and convolution history in vLLM rings. Token IDs are stored as integer bits.
- Reuse the existing row-sharded embedding route with rank-uniform exchange
  capacity, including idle/padded ranks.
- Load non-FSDP parameters into their existing storage, while preserving frozen
  parameters and requiring every published trainable parameter to be filled.
- Add a text-only, disaggregated DAPO/GRPO recipe with 32 trainer GPUs and two
  8-GPU generators, GPU-resident frozen PLE, frozen indexers, and explicit initial
  HF checkpoint loading. It selects optional BF16 Dist-MoE and decode graphs.
- Reject prefix caching because attention KV alone cannot restore PLE history.

Keeping PLE rows on GPU avoids per-decode host lookups. Existing row sharding and
RL transport remain responsible for distribution and parameter transfer.

## User-facing changes

| Before | After |
| --- | --- |
| PLE loses history between generation calls | Chunked prefill/decode retains per-request history |
| Loader requires every parameter to belong to FSDP | Row-owned parameters load in place; frozen rows stay resident |
| No Flash-Next RL recipe | `qwen3_8_flash_next_dapo_disaggregated(...)` |

## Testing

```bash
pytest -q tests/rl/unit_tests/gpu/test_vllm_qsa.py \
  tests/rl/unit_tests/gpu/test_vllm_ple.py \
  tests/rl/unit_tests/cpu/test_vllm_wrapper.py \
  tests/rl/unit_tests/cpu/test_vllm_registry.py \
  tests/rl/unit_tests/cpu/test_generator_model.py
```

38 passed. PLE output is bitwise equal to full-request evaluation through chunk
boundaries, EOS resets, request reordering, page reuse, enlarged ring pages, and
large token IDs (including a NaN bit pattern when viewed as BF16). Loader tests
check storage identity, missing updates, and frozen-parameter exclusion.

Four-GPU eager generation with DP2/TP2/EP4 and sequence parallelism passed using
the real indexer and paged attention. Single-GPU eager and `FULL_DECODE_ONLY`
generation produced identical tokens in the ranked, chunked-prefill case.
These smoke runs used initialized debug weights; loading a full released HF
checkpoint was not exercised.

The existing Flash-Next CPU model suite has 23 passing tests. One exact CPU
convolution/gradient comparison was excluded after reproducing its small rounding
failure on the unchanged PR base:
`test_ple_dilated_convolution_and_gradients_respect_documents`.

## Remaining validation

Dist-MoE execution validation is deferred. The full 48-GPU recipe, production
checkpoint/data run, and matched end-to-end performance comparison have not been
run. No throughput improvement is claimed from the debug smoke tests.

## Validation scope

Validation used local B200 GPUs and an Attention Gym development build preserving
the original cuDNN linear kernels, with the paged sparse APIs added. The pinned
`attn-gym==0.0.20` alone does not supply these APIs. No GDN/KDA migration is included.

The complete stack passed `pre-commit run --all-files`. A deterministic seed-42
BF16 debug-model forward/backward (32 tokens) was compared against
`44ff1567196fe91ba8a8f96a1aeefbc6715dda8c`: loss `4.4367218017578125`, gradient
norm `22.315799713134766`, logits, and all 192 parameter gradients were bitwise
identical using `torch.equal`. This is one-GPU training evidence, not a
representative-data convergence run or a 125B performance measurement.

stack-info: PR: #6203, branch: qwen38-rl-3-ple
@liangel-02
liangel-02 changed the base branch from qwen3-8-fn-6-pipeline to qwen38-rl-2-indexer November 19, 2026 01:39
@liangel-02
liangel-02 changed the base branch from qwen38-rl-2-indexer to qwen3-8-fn-6-pipeline November 19, 2026 01:45
liangel-02 added a commit that referenced this pull request Nov 19, 2026
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why

PLE needs preceding token IDs for n-gram hashing and preceding activations for
its dilated convolution. A decode call supplies only new tokens, so running the
training PLE path independently on each call loses that history. Row-owned PLE
parameters also sit outside FSDP load groups and need explicit handling during
policy updates.

For a request split into `3 + 14 + 10` tokens, cached PLE must match one full
27-token evaluation. Reordering requests or reusing a completed request's pages
must not mix their histories.

## What changed

- Add a Flash-Next wrapper and PLE implementation retaining request-local token
  and convolution history in vLLM rings. Token IDs are stored as integer bits.
- Reuse the existing row-sharded embedding route with rank-uniform exchange
  capacity, including idle/padded ranks.
- Load non-FSDP parameters into their existing storage, while preserving frozen
  parameters and requiring every published trainable parameter to be filled.
- Add a text-only, disaggregated DAPO/GRPO recipe with 32 trainer GPUs and two
  8-GPU generators, GPU-resident frozen PLE, frozen indexers, and explicit initial
  HF checkpoint loading. It selects optional BF16 Dist-MoE and decode graphs.
- Reject prefix caching because attention KV alone cannot restore PLE history.

Keeping PLE rows on GPU avoids per-decode host lookups. Existing row sharding and
RL transport remain responsible for distribution and parameter transfer.

## User-facing changes

| Before | After |
| --- | --- |
| PLE loses history between generation calls | Chunked prefill/decode retains per-request history |
| Loader requires every parameter to belong to FSDP | Row-owned parameters load in place; frozen rows stay resident |
| No Flash-Next RL recipe | `qwen3_8_flash_next_dapo_disaggregated(...)` |

## Testing

```bash
pytest -q tests/rl/unit_tests/gpu/test_vllm_qsa.py \
  tests/rl/unit_tests/gpu/test_vllm_ple.py \
  tests/rl/unit_tests/cpu/test_vllm_wrapper.py \
  tests/rl/unit_tests/cpu/test_vllm_registry.py \
  tests/rl/unit_tests/cpu/test_generator_model.py
```

38 passed. PLE output is bitwise equal to full-request evaluation through chunk
boundaries, EOS resets, request reordering, page reuse, enlarged ring pages, and
large token IDs (including a NaN bit pattern when viewed as BF16). Loader tests
check storage identity, missing updates, and frozen-parameter exclusion.

Four-GPU eager generation with DP2/TP2/EP4 and sequence parallelism passed using
the real indexer and paged attention. Single-GPU eager and `FULL_DECODE_ONLY`
generation produced identical tokens in the ranked, chunked-prefill case.
These smoke runs used initialized debug weights; loading a full released HF
checkpoint was not exercised.

The existing Flash-Next CPU model suite has 23 passing tests. One exact CPU
convolution/gradient comparison was excluded after reproducing its small rounding
failure on the unchanged PR base:
`test_ple_dilated_convolution_and_gradients_respect_documents`.

## Remaining validation

Dist-MoE execution validation is deferred. The full 48-GPU recipe, production
checkpoint/data run, and matched end-to-end performance comparison have not been
run. No throughput improvement is claimed from the debug smoke tests.

## Validation scope

Validation used local B200 GPUs and an Attention Gym development build preserving
the original cuDNN linear kernels, with the paged sparse APIs added. The pinned
`attn-gym==0.0.20` alone does not supply these APIs. No GDN/KDA migration is included.

The complete stack passed `pre-commit run --all-files`. A deterministic seed-42
BF16 debug-model forward/backward (32 tokens) was compared against
`44ff1567196fe91ba8a8f96a1aeefbc6715dda8c`: loss `4.4367218017578125`, gradient
norm `22.315799713134766`, logits, and all 192 parameter gradients were bitwise
identical using `torch.equal`. This is one-GPU training evidence, not a
representative-data convergence run or a 125B performance measurement.

stack-info: PR: #6203, branch: qwen38-rl-3-ple
@liangel-02
liangel-02 changed the base branch from qwen3-8-fn-6-pipeline to qwen38-rl-2-indexer November 19, 2026 01:45
@liangel-02 liangel-02 changed the title Add PLE request history and disaggregated Flash-Next RL recipe Add cached PLE support to Flash-Next generation Nov 19, 2026
@liangel-02
liangel-02 changed the base branch from qwen38-rl-2-indexer to qwen3-8-fn-6-pipeline November 19, 2026 01:52
liangel-02 added a commit that referenced this pull request Nov 19, 2026
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why

Stacked on #6203, which provides cached PLE and the Flash-Next generator wrapper.
The generator needs a matching trainer, rollout workload, and initial checkpoint
configuration for disaggregated RL.

```python
from torchtitan_recipes.rl.qwen3_8_flash_next import (
    qwen3_8_flash_next_dapo_disaggregated,
)

config = qwen3_8_flash_next_dapo_disaggregated(
    hf_assets_path="/checkpoints/qwen3_8_flash_next",
    dapo_math_repo_id="your-org/dapo-math",
)
```

## What changed

- Add a text-only, disaggregated DAPO/GRPO recipe with 32 trainer GPUs and two
  8-GPU generators, GPU-resident frozen PLE, frozen indexers, and explicit initial
  HF checkpoint loading. It selects optional BF16 Dist-MoE and decode graphs.
- Configure 30 training iterations with 16 prompts and 8 samples per prompt,
  an 8192-token context, and a 4096-token response limit.
- Use BF16 compute with FP32 master parameters, AdamW, and the DAPO loss.
- Keep the frozen n-gram table specialization local to the recipe.

This PR contains only `torchtitan_recipes/rl/qwen3_8_flash_next.py`. Model
integration, parameter loading, and their tests are in #6203.

## User-facing changes

| Before | After |
| --- | --- |
| No Flash-Next RL recipe | `qwen3_8_flash_next_dapo_disaggregated(...)` |

## Testing

`pre-commit run --all-files` passed.

The recipe file is byte-for-byte identical to the one previously included in
commit `346c33ba435bcee83bfd62bf14c027abc4a0509d`. This split changes commit
boundaries only; the complete stack's source tree is unchanged. No new runtime
tests were run for the split.

## Numerics and performance

The supporting stack has deterministic debug-model parity and generation smoke
results recorded in #6203. Those checks do not validate this full recipe's loss,
reward curve, or throughput.

Dist-MoE execution validation is deferred. The full 48-GPU recipe, production
checkpoint/data run, and matched end-to-end performance comparison have not been
run. No throughput improvement is claimed from the debug smoke tests.

The recipe requires the same Attention Gym development build as the supporting
stack: the original cuDNN linear kernels with the paged sparse APIs added. The
pinned `attn-gym==0.0.20` alone does not supply these APIs. No GDN/KDA migration
is included.

stack-info: PR: #6206, branch: qwen38-rl-4-recipe
@liangel-02
liangel-02 changed the base branch from qwen3-8-fn-6-pipeline to qwen38-rl-2-indexer November 19, 2026 01:52
@liangel-02
liangel-02 changed the base branch from qwen38-rl-2-indexer to qwen3-8-fn-6-pipeline November 19, 2026 01:55
liangel-02 added a commit that referenced this pull request Nov 19, 2026
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why

Stacked on #6203, which provides cached PLE and the Flash-Next generator wrapper.
The generator needs a matching trainer, rollout workload, and initial checkpoint
configuration for disaggregated RL.

```python
from torchtitan_recipes.rl.qwen3_8_flash_next import (
    qwen3_8_flash_next_dapo_disaggregated,
)

config = qwen3_8_flash_next_dapo_disaggregated(
    hf_assets_path="/checkpoints/qwen3_8_flash_next",
    dapo_math_repo_id="your-org/dapo-math",
)
```

## What changed

- Add a text-only, disaggregated DAPO/GRPO recipe with 32 trainer GPUs and two
  8-GPU generators, GPU-resident frozen PLE, frozen indexers, and explicit initial
  HF checkpoint loading. It selects optional BF16 Dist-MoE and decode graphs.
- Configure 30 training iterations with 16 prompts and 8 samples per prompt,
  an 8192-token context, and a 4096-token response limit.
- Use BF16 compute with FP32 master parameters, AdamW, and the DAPO loss.
- Keep the frozen n-gram table specialization local to the recipe.

This PR contains only `torchtitan_recipes/rl/qwen3_8_flash_next.py`. Model
integration, parameter loading, and their tests are in #6203.

## User-facing changes

| Before | After |
| --- | --- |
| No Flash-Next RL recipe | `qwen3_8_flash_next_dapo_disaggregated(...)` |

## Testing

`pre-commit run --all-files` passed.

The recipe file is byte-for-byte identical to the one previously included in
commit `346c33ba435bcee83bfd62bf14c027abc4a0509d`. This split changes commit
boundaries only; the complete stack's source tree is unchanged. No new runtime
tests were run for the split.

## Numerics and performance

The supporting stack has deterministic debug-model parity and generation smoke
results recorded in #6203. Those checks do not validate this full recipe's loss,
reward curve, or throughput.

Dist-MoE execution validation is deferred. The full 48-GPU recipe, production
checkpoint/data run, and matched end-to-end performance comparison have not been
run. No throughput improvement is claimed from the debug smoke tests.

The recipe requires the same Attention Gym development build as the supporting
stack: the original cuDNN linear kernels with the paged sparse APIs added. The
pinned `attn-gym==0.0.20` alone does not supply these APIs. No GDN/KDA migration
is included.

stack-info: PR: #6206, branch: qwen38-rl-4-recipe
@liangel-02
liangel-02 changed the base branch from qwen3-8-fn-6-pipeline to qwen38-rl-2-indexer November 19, 2026 01:55
liangel-02 added a commit that referenced this pull request Nov 19, 2026
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why

Stacked on #6203, which provides the cached PLE generation layer. This PR is the
final step that connects the stack into a runnable RL job:

- Flash-Next's decoder takes `ple_input_ids` and `document_positions` in
  addition to the token IDs and positions every TorchTitan model receives. The
  generic `VLLMModelWrapper.forward` passes only `positions`, so a Flash-Next
  generator fails before PLE runs.
- The generator needs a matching trainer, rollout workload, and initial
  checkpoint configuration for disaggregated RL.

```python
from torchtitan_recipes.rl.qwen3_8_flash_next import (
    qwen3_8_flash_next_dapo_disaggregated,
)

config = qwen3_8_flash_next_dapo_disaggregated(
    hf_assets_path="/checkpoints/qwen3_8_flash_next",
    dapo_math_repo_id="your-org/dapo-math",
)
```

## What changed

Generator integration:

- Add `VLLMFlashNextModelWrapper` (`torchtitan/rl/generator/vllm/qwen3_8_flash_next.py`),
  which overrides only `forward`: vLLM's token IDs feed PLE hashing and its
  positions feed PLE document positions. The per-layer PLE replacement stays in
  `_replace_vllm_layer_configs` (#6203).
- `register_to_vllm` selects the wrapper for `Qwen38FlashNextModel.Config`, the
  same way it selects `VLLMMultimodalModelWrapper` for image-serving generators,
  and raises `ValueError` for multimodal Flash-Next generation.

Recipe (`torchtitan_recipes/rl/qwen3_8_flash_next.py`):

- Add a text-only, disaggregated DAPO/GRPO recipe with 32 trainer GPUs and two
  8-GPU generators, GPU-resident frozen PLE, frozen indexers, and explicit initial
  HF checkpoint loading. It selects optional BF16 Dist-MoE and decode graphs.
- Configure 30 training iterations with 16 prompts and 8 samples per prompt,
  an 8192-token context, and a 4096-token response limit.
- Use BF16 compute with FP32 master parameters, AdamW, and the DAPO loss.
- Keep the frozen n-gram table specialization local to the recipe.

## User-facing changes

| Before | After |
| --- | --- |
| Flash-Next generators use the generic wrapper and omit PLE inputs | Flash-Next generators run text generation through vLLM |
| No check for Flash-Next multimodal generation | Raises `ValueError` for multimodal Flash-Next generation |
| No Flash-Next RL recipe | `qwen3_8_flash_next_dapo_disaggregated(...)` |

## Testing

```bash
pytest -q tests/rl/unit_tests/gpu/test_vllm_qsa.py \
  tests/rl/unit_tests/gpu/test_vllm_ple.py \
  tests/rl/unit_tests/cpu/test_vllm_wrapper.py \
  tests/rl/unit_tests/cpu/test_vllm_registry.py \
  tests/rl/unit_tests/cpu/test_generator_model.py
```

38 passed.

Debug-model generation with initialized weights, the real paged indexer, and
paged QSA attention, using two requests (a 3-token prompt, and a 37-token prompt
split by chunked prefill) that finish at different steps:

| Configuration | Result |
| --- | --- |
| 1 GPU, eager | `[53, 27, 17]`, `[25, 39, 56, 18, 59]` |
| 1 GPU, `FULL_DECODE_ONLY` CUDA graphs | identical to eager |
| 4 GPUs, DP2/TP2/EP4 + SP, eager | completes on every rank |

Each configuration produced the same tokens as the earlier revision of this
stack, in which the PLE layer replacement lived in the wrapper. Loading a full
released HF checkpoint was not exercised.

## Numerics and performance

The supporting stack has deterministic debug-model parity recorded in #6202.
These checks do not validate this full recipe's loss, reward curve, or
throughput.

Dist-MoE execution validation is deferred. The full 48-GPU recipe, production
checkpoint/data run, and matched end-to-end performance comparison have not been
run. No throughput improvement is claimed from the debug smoke tests.

The recipe requires the same Attention Gym development build as the supporting
stack: the original cuDNN linear kernels with the paged sparse APIs added. The
pinned `attn-gym==0.0.20` alone does not supply these APIs. No GDN/KDA migration
is included.

stack-info: PR: #6206, branch: qwen38-rl-4-recipe
@liangel-02
liangel-02 changed the base branch from qwen38-rl-2-indexer to main November 19, 2026 04:31
liangel-02 added a commit that referenced this pull request Nov 19, 2026
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why

Stacked on #6203, which provides the cached PLE generation layer. This PR is the
final step that connects the stack into a runnable RL job:

- Flash-Next's decoder takes `ple_input_ids` and `document_positions` in
  addition to the token IDs and positions every TorchTitan model receives. The
  generic `VLLMModelWrapper.forward` passes only `positions`, so a Flash-Next
  generator fails before PLE runs.
- The generator needs a matching trainer, rollout workload, and initial
  checkpoint configuration for disaggregated RL.

```python
from torchtitan_recipes.rl.qwen3_8_flash_next import (
    qwen3_8_flash_next_dapo_disaggregated,
)

config = qwen3_8_flash_next_dapo_disaggregated(
    hf_assets_path="/checkpoints/qwen3_8_flash_next",
    dapo_math_repo_id="your-org/dapo-math",
)
```

## What changed

Generator integration:

- Add `VLLMFlashNextModelWrapper` (`torchtitan/rl/generator/vllm/qwen3_8_flash_next.py`),
  which overrides only `forward`: vLLM's token IDs feed PLE hashing and its
  positions feed PLE document positions. The per-layer PLE replacement stays in
  `_replace_vllm_layer_configs` (#6203).
- `register_to_vllm` selects the wrapper for `Qwen38FlashNextModel.Config`, the
  same way it selects `VLLMMultimodalModelWrapper` for image-serving generators,
  and raises `ValueError` for multimodal Flash-Next generation.

Recipe (`torchtitan_recipes/rl/qwen3_8_flash_next.py`):

- Add a text-only, disaggregated DAPO/GRPO recipe with 32 trainer GPUs and two
  8-GPU generators, GPU-resident frozen PLE, frozen indexers, and explicit initial
  HF checkpoint loading. It selects optional BF16 Dist-MoE and decode graphs.
- Configure 30 training iterations with 16 prompts and 8 samples per prompt,
  an 8192-token context, and a 4096-token response limit.
- Use BF16 compute with FP32 master parameters, AdamW, and the DAPO loss.
- Keep the frozen n-gram table specialization local to the recipe.

## User-facing changes

| Before | After |
| --- | --- |
| Flash-Next generators use the generic wrapper and omit PLE inputs | Flash-Next generators run text generation through vLLM |
| No check for Flash-Next multimodal generation | Raises `ValueError` for multimodal Flash-Next generation |
| No Flash-Next RL recipe | `qwen3_8_flash_next_dapo_disaggregated(...)` |

## Testing

```bash
pytest -q tests/rl/unit_tests/gpu/test_vllm_qsa.py \
  tests/rl/unit_tests/gpu/test_vllm_ple.py \
  tests/rl/unit_tests/cpu/test_vllm_wrapper.py \
  tests/rl/unit_tests/cpu/test_vllm_registry.py \
  tests/rl/unit_tests/cpu/test_generator_model.py
```

38 passed.

Debug-model generation with initialized weights, the real paged indexer, and
paged QSA attention, using two requests (a 3-token prompt, and a 37-token prompt
split by chunked prefill) that finish at different steps:

| Configuration | Result |
| --- | --- |
| 1 GPU, eager | `[53, 27, 17]`, `[25, 39, 56, 18, 59]` |
| 1 GPU, `FULL_DECODE_ONLY` CUDA graphs | identical to eager |
| 4 GPUs, DP2/TP2/EP4 + SP, eager | completes on every rank |

Each configuration produced the same tokens as the earlier revision of this
stack, in which the PLE layer replacement lived in the wrapper. Loading a full
released HF checkpoint was not exercised.

## Numerics and performance

The supporting stack has deterministic debug-model parity recorded in #6202.
These checks do not validate this full recipe's loss, reward curve, or
throughput.

Dist-MoE execution validation is deferred. The full 48-GPU recipe, production
checkpoint/data run, and matched end-to-end performance comparison have not been
run. No throughput improvement is claimed from the debug smoke tests.

The recipe requires the same Attention Gym development build as the supporting
stack: the original cuDNN linear kernels with the paged sparse APIs added. The
pinned `attn-gym==0.0.20` alone does not supply these APIs. No GDN/KDA migration
is included.

stack-info: PR: #6206, branch: qwen38-rl-4-recipe
@liangel-02
liangel-02 changed the base branch from main to qwen38-rl-2-indexer November 19, 2026 04:36
liangel-02 added a commit that referenced this pull request Nov 19, 2026
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why

Stacked on #6203, which provides the cached PLE generation layer. This PR is the
final step that connects the stack into a runnable RL job:

- Flash-Next's decoder takes `ple_input_ids` and `document_positions` in
  addition to the token IDs and positions every TorchTitan model receives. The
  generic `VLLMModelWrapper.forward` passes only `positions`, so a Flash-Next
  generator fails before PLE runs.
- The generator needs a matching trainer, rollout workload, and initial
  checkpoint configuration for disaggregated RL.

```python
from torchtitan_recipes.rl.qwen3_8_flash_next import (
    qwen3_8_flash_next_dapo_disaggregated,
)

config = qwen3_8_flash_next_dapo_disaggregated(
    hf_assets_path="/checkpoints/qwen3_8_flash_next",
    dapo_math_repo_id="your-org/dapo-math",
)
```

## What changed

Generator integration:

- Add `VLLMFlashNextModelWrapper` (`torchtitan/rl/generator/vllm/qwen3_8_flash_next.py`),
  which overrides only `forward`: vLLM's token IDs feed PLE hashing and its
  positions feed PLE document positions. The per-layer PLE replacement stays in
  `_replace_vllm_layer_configs` (#6203).
- `register_to_vllm` selects the wrapper for `Qwen38FlashNextModel.Config`, the
  same way it selects `VLLMMultimodalModelWrapper` for image-serving generators,
  and raises `ValueError` for multimodal Flash-Next generation.

Recipe (`torchtitan_recipes/rl/qwen3_8_flash_next.py`):

- Add a text-only, disaggregated DAPO/GRPO recipe with 32 trainer GPUs and two
  8-GPU generators, GPU-resident frozen PLE, frozen indexers, and explicit initial
  HF checkpoint loading. It selects optional BF16 Dist-MoE and decode graphs.
- Configure 30 training iterations with 16 prompts and 8 samples per prompt,
  an 8192-token context, and a 4096-token response limit.
- Use BF16 compute with FP32 master parameters, AdamW, and the DAPO loss.
- Keep the frozen n-gram table specialization local to the recipe.

## User-facing changes

| Before | After |
| --- | --- |
| Flash-Next generators use the generic wrapper and omit PLE inputs | Flash-Next generators run text generation through vLLM |
| No check for Flash-Next multimodal generation | Raises `ValueError` for multimodal Flash-Next generation |
| No Flash-Next RL recipe | `qwen3_8_flash_next_dapo_disaggregated(...)` |

## Testing

```bash
pytest -q tests/rl/unit_tests/gpu/test_vllm_qsa.py \
  tests/rl/unit_tests/gpu/test_vllm_ple.py \
  tests/rl/unit_tests/cpu/test_vllm_wrapper.py \
  tests/rl/unit_tests/cpu/test_vllm_registry.py \
  tests/rl/unit_tests/cpu/test_generator_model.py
```

38 passed.

Debug-model generation with initialized weights, the real paged indexer, and
paged QSA attention, using two requests (a 3-token prompt, and a 37-token prompt
split by chunked prefill) that finish at different steps:

| Configuration | Result |
| --- | --- |
| 1 GPU, eager | `[53, 27, 17]`, `[25, 39, 56, 18, 59]` |
| 1 GPU, `FULL_DECODE_ONLY` CUDA graphs | identical to eager |
| 4 GPUs, DP2/TP2/EP4 + SP, eager | completes on every rank |

Each configuration produced the same tokens as the earlier revision of this
stack, in which the PLE layer replacement lived in the wrapper. Loading a full
released HF checkpoint was not exercised.

## Numerics and performance

The supporting stack has deterministic debug-model parity recorded in #6202.
These checks do not validate this full recipe's loss, reward curve, or
throughput.

BF16 Dist-MoE debug generation passed with TP2/EP2 and sequence parallelism
in eager mode and with decode graphs. The full 48-GPU recipe, production
checkpoint/data run, and matched end-to-end performance comparison have not
been run. No throughput improvement is claimed from the debug smoke tests.

The recipe requires the same Attention Gym development build as the supporting
stack: the original cuDNN linear kernels with the paged sparse APIs added. The
pinned `attn-gym==0.0.20` alone does not supply these APIs. No GDN/KDA migration
is included.

Additional cache-reuse validation: 38 focused tests pass, including native
metadata, padded cache strides, and extra sequence-parallel model rows.
Across three rounds of two requests, generated tokens and log probabilities
are exactly equal to published stack 02f9eb9 in BF16 Dist-MoE TP2/EP2 + SP,
both eager and FULL_DECODE_ONLY, on both ranks. Full pre-commit checks pass.

stack-info: PR: #6206, branch: qwen38-rl-4-recipe
@liangel-02
liangel-02 changed the base branch from qwen3-8-fn-6-pipeline to qwen38-rl-2-indexer November 19, 2026 22:46
@liangel-02
liangel-02 changed the base branch from qwen38-rl-2-indexer to qwen3-8-fn-6-pipeline November 20, 2026 18:12
@liangel-02
liangel-02 changed the base branch from qwen3-8-fn-6-pipeline to qwen38-rl-2-indexer November 20, 2026 18:13
@liangel-02
liangel-02 changed the base branch from qwen38-rl-2-indexer to qwen3-8-fn-6-pipeline November 20, 2026 18:23
@liangel-02
liangel-02 changed the base branch from qwen3-8-fn-6-pipeline to qwen38-rl-2-indexer November 20, 2026 18:23
@liangel-02

Copy link
Copy Markdown
Contributor Author

@claude review again ignore issues w/ attn gym dependencies

@claude

claude Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @liangel-02's task in 3m 9s —— View job


Request changes: three PLE compile regions were added to the Flash-Next trainer defaults without trainer loss, step-time or memory numbers, and tianyu-l's question about how vLLM handles PLE still has no answer. See the review.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Request changes -- the new commit also turns on three PLE compile regions in the Flash-Next trainer defaults with no trainer measurements, and tianyu-l's question about how vLLM handles PLE is still unanswered. (Attention Gym dependency issues are ignored, as asked.)

What this PR does. It adds VLLMPLELayer, which keeps each request's last (k-1)*dilation normed rows and last ngram_size-1 token IDs. These live in model-owned buffers indexed by the same layer's GDN state slot, so chunked prefill and decode reproduce one full PLE pass. Decode-sized steps look up row-owned n-gram rows with an all-gather and a reduce-scatter. The hash, lookup, gate, and conv math is shared with the trainer's PLELayer.

Example. One 27-token request on GDN slot 4, scheduled as 3 + 14 + 10:

step 2 row "token 3": shifted IDs <- id_history[4, (3-s) % 2]
                      conv taps  <- conv_history[4, (3-shift) % 9]
after the conv:       the last 9 rows / 2 IDs of the chunk are written back to slot 4
result:               bitwise equal to one 27-token PLELayer call

Resolved since the last review

  • Hardcoded ring size 16 and C-wide token-ID slots: resolved. The ring is gone, and the buffers are sized from conv_shifts() and ngram_size, with IDs stored as int64.
  • persistent_param_keys now has a Returns: docstring.
  • The PLE test now has its own file, tests/rl/unit_tests/gpu/test_vllm_ple.py.

Must fix

  1. The "Summary (human-written)" section is still the empty template placeholder. Only the author can write it.
  2. tianyu-l's question on ple.py:21 (does vLLM offer a PLE extension point, and how does vLLM itself do PLE?) has no answer. Some context: as far as I know, vLLM's Gemma 3n per-layer embeddings are a stateless per-token lookup. vLLM's only hook for per-request state is a KV-cache spec, which this PR avoids because of the group-size issue. The author should confirm this and say it in the thread.
  3. torchtitan/models/qwen3_8_flash_next/model.py:218-220 -- the trainer default regions change; see the inline comment.
  4. torchtitan/rl/generator/model.py:741-743 (still open): any parameter missing from sharded_param_to_group still turns into a persistent key, and the old assert is gone. Accept only FSDP-ignored parameters and keep the assert for everything else.
  5. torchtitan/rl/generator/vllm/ple.py:158 (still open): add a comment saying the zero return comes after the lookup on purpose, so that idle ranks still join gather_owned_rows's all-gather/reduce-scatter and the row-sharded exchange.
  6. ple.py:73 -- the TODO has no upstream issue link (see inline).

Should consider

  • ple.py:84 -- the history buffers scale with num_blocks and sit outside vLLM's memory budget (see inline).
Details
  • Null-slot handling checked by hand: linear_attention.py pads decode and prefill state indices with slot 0 (L245-265), so state_T != 0 masks the padded rows. Masked writes land in null slot 0.
  • Read-before-write checked by hand: _decode_hashes and _decode_conv read the history before forward writes it back. In a packed step, _window_writes keeps only each request's last window rows, so their position % window destinations are unique.
  • gather_owned_rows computes row_start = local_rank * local_rows. That is safe because NGramTable requires num_embeddings to be divisible by the row mesh size (embedding.py:83).

Not verified: the owned-row gather inside FULL_DECODE_ONLY graphs at more than 2 ranks; gpu_fetch filling the DTensor table in place when the generator's row mesh differs from the trainer's; and the absolute size of the history buffers for the 125B config.

Comment on lines +218 to +220
"ple_hash_ids",
"ple_gate",
"ple_conv",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These three lines change the trainer, not the generator. Every Flash-Next recipe that keeps the model's default regions (e.g. qwen38_flash_next_125b_dist_moe) now compiles PLE hashing, the gate, and the conv. That changes numerics (compiled vs. eager isn't bitwise) and possibly step time and memory, and the description says none of this was measured. Loss, grad_norm, and main-path perf/memory must not change silently (CLAUDE.md principle 6), and this is a separate concern from cached generation.

The generator doesn't need them. Its regions are named ple_gate / ple_conv so they compile whenever the trainer's do, and with the defaults left alone both sides stay eager and still match. Smallest fix: drop these three lines and enable the regions in a follow-up PR that includes trainer loss/step-time/memory numbers.

Comment on lines +73 to +80
# TODO: File a vLLM issue for per-bucket KV-cache group sizes. vLLM's hybrid
# KV-cache manager puts the same number of layers in every KV-cache group
# (the smallest spec bucket), so a one-layer PLE state bucket would force one
# layer per group for the whole model (73 groups for Flash-Next, each building
# attention metadata every step). Until vLLM supports per-bucket group sizes,
# PLE keeps its history in these model-owned buffers indexed by the state
# slots of the linear-attention layer named by state_metadata_prefix, and
# should move back to a vLLM KV-cache state once it does.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"File a vLLM issue" means no issue exists yet. CLAUDE.md asks for workarounds of an upstream gap to carry a TODO with the upstream issue link. Please file it (per-bucket layer counts for hybrid KV-cache groups) and link it here, so the move back to a vLLM-managed state has something to track.

Comment on lines +81 to +84
source_state = self._static_forward_context[
self.state_metadata_prefix
].kv_cache[0]
num_slots = source_state.shape[0]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

num_slots is the first dimension of GDN's conv state, so it equals vLLM's KV-cache num_blocks, not max_num_seqs. These buffers therefore grow with the KV-cache budget (about 180 KiB x num_blocks). They're also allocated after vLLM has spent its gpu_memory_utilization budget, so the more KV cache vLLM reserves, the less headroom CUDA graph capture has left.

Please state the total for the production config in the description. If that total is large, either account for it before vLLM sizes the KV cache, or drop unused slots: with mamba_cache_mode="none", at most max_num_seqs slots are live at once. Unverified: I didn't measure num_blocks for the 125B config.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we address this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think its ok, the cost of the workaround is small and we can followup if/when vllm supports per-bucket group sizes i can file an issue

@liangel-02
liangel-02 changed the base branch from qwen38-rl-2-indexer to qwen3-8-fn-6-pipeline November 20, 2026 18:44
@liangel-02
liangel-02 changed the base branch from qwen3-8-fn-6-pipeline to qwen38-rl-2-indexer November 20, 2026 18:44
@liangel-02

Copy link
Copy Markdown
Contributor Author

@claude review again, ignore attn gym dependencies

@claude

claude Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @liangel-02's task in 2m 21s —— View job


Approve -- please address the remaining small items before merging: a reply to tianyu-l, the loader FSDP guard, a comment on the idle-rank return, and the vLLM issue link. See the review.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- please address the items below before merging. The trainer defaults are no longer changed, and the history-buffer memory is now documented. What's left is a reply to tianyu-l, a small loader guard, a comment, and a TODO link. A maintainer still needs to review, because this PR touches the generator weight loader. (Attention Gym dependency issues are ignored, as asked.)

What this PR does. It adds VLLMPLELayer. For each request it keeps the last (k-1)*dilation normed rows and the last ngram_size-1 token IDs in model-owned buffers, indexed by the same layer's GDN state slot. With those, chunked prefill and decode reproduce one full PLE pass. Decode-sized steps read row-owned n-gram rows with an all-gather and a reduce-scatter. The hash, lookup, gate and conv math is shared with the trainer's PLELayer. The loader fills non-FSDP parameters in place.

Example. One 27-token request on GDN slot 4, scheduled as 3 + 14 + 10:

step 2 row "token 3": shifted IDs <- id_history[4, (3-s) % 2]
                      conv taps  <- conv_history[4, (3-shift) % 9]
after the conv:       the last 9 rows / 2 IDs of the chunk are written back to slot 4
result:               bitwise equal to one 27-token PLELayer call

Resolved since the last review

  • Trainer default regions: resolved. qwen3_8_flash_next/model.py is no longer in the diff, so ple_hash_ids/ple_gate/ple_conv exist only as opt-in regions, and Flash-Next recipes stay eager.
  • History-buffer size: resolved. The description gives about 0.45 GiB per GPU at DP4/EP4 and names the follow-up.

Must fix

  1. The description still has no "Summary (human-written)" section. Only the author can write it.
  2. tianyu-l's question on ple.py:21 (is there a vLLM PLE extension point, and how does vLLM do PLE?) still has no reply in the thread. The new description paragraph on KV-cache groups covers part of it. Please answer in the thread itself, including how vLLM's stateless Gemma 3n per-layer embeddings differ from PLE's history-dependent n-gram and conv.
  3. torchtitan/rl/generator/model.py:741-743 (still open): any parameter missing from sharded_param_to_group still becomes a persistent key. The new "fetch did not fill" check doesn't catch the case the old assert caught: an FSDP group that is unsharded when _fsdp_load_groups runs. In that case its unsharded params get loaded "in place", and the next reshard/unshard silently overwrites them. Smallest fix, about 6 lines: build the set of FQNs that FSDP manages, from each group's fsdp_param._module_info (module + param_name), and assert that no persistent key is in that set.
  4. torchtitan/rl/generator/vllm/ple.py:159 (still open): add a one-line comment saying the zero return comes after the lookup on purpose. Idle ranks must still join gather_owned_rows's all-gather/reduce-scatter and the row-sharded exchange.
  5. torchtitan/rl/generator/vllm/ple.py:73 (still open): "File a vLLM issue" still has no upstream link. Please file the issue (per-bucket layer counts for hybrid KV-cache groups) and link it in the TODO.

Not verified: the owned-row gather inside FULL_DECODE_ONLY graphs at more than 2 ranks, and gpu_fetch filling the row-sharded DTensor in place when the generator's row mesh differs from the trainer's.

@liangel-02
liangel-02 changed the base branch from qwen38-rl-2-indexer to qwen3-8-fn-6-pipeline November 20, 2026 19:49
@liangel-02
liangel-02 changed the base branch from qwen3-8-fn-6-pipeline to qwen38-rl-2-indexer November 20, 2026 19:49
@liangel-02
liangel-02 marked this pull request as ready for review November 20, 2026 19:54
Comment on lines +81 to +84
source_state = self._static_forward_context[
self.state_metadata_prefix
].kv_cache[0]
num_slots = source_state.shape[0]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we address this?

Comment thread torchtitan/rl/generator/vllm/ple.py Resolved
Comment thread torchtitan/rl/generator/vllm/worker.py Resolved
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

PLE needs the preceding token IDs for n-gram hashing and the preceding normed
activations for its dilated convolution. A decode call supplies only new tokens,
so running the training PLE path independently on each call loses that history.
Row-owned PLE parameters also sit outside FSDP load groups and need explicit
handling during policy updates.

For a request split into `3 + 14 + 10` tokens, cached PLE must match one full
27-token evaluation. Reordering requests or reusing a finished request's state
must not mix their histories.

- Add `VLLMPLELayer` (`torchtitan/rl/generator/vllm/model/ple.py`). Each request's
  history is the last `(kernel_size - 1) * dilation` normed rows (BF16) and the
  last `ngram_size - 1` token IDs (int64), indexed circularly. It lives in
  model-owned buffers that the worker allocates after vLLM binds the KV cache,
  indexed by the state slots of the same layer's GDN attention, so it follows
  that request's slot through reordering and slot reuse. Packed steps store
  only each request's final window.
- PLE registers no KV-cache spec of its own. vLLM's hybrid KV-cache manager
  gives every group the layer count of the smallest spec bucket, so a
  one-layer PLE state forced one layer per group for all of Flash-Next: 73
  KV-cache groups, each building attention metadata every step, instead of 6.
  A TODO marks this workaround until vLLM supports per-bucket group sizes. A
  PLE layer without GDN attention raises `ValueError`.
- The generator reuses the trainer's math. `NGramEmbedding.mix_hashes`,
  `NGramEmbedding.lookup`/`gather_features`, `PLELayer.gate_score`/`gate_apply`
  and `PLELayer.conv_shifts`/`conv_output` are split out of the training
  forward; trainer outputs and gradients are bitwise unchanged.
- Decode-sized steps (at most `max_num_seqs` tokens on every DP rank)
  all-gather hash IDs over the row mesh, look up locally owned rows (non-owned
  rows read as -0.0) and reduce-scatter, which is bitwise equal to a plain
  gather. Larger steps keep the row-sharded slot route, now sized by the step's
  DP-max token count instead of `max_num_batched_tokens`.
- `local_compile` regions: the trainer's PLE hashing, gate and convolution
  register as `ple_hash_ids`, `ple_gate` and `ple_conv`. They are not added to
  the Flash-Next defaults, so recipes keep running PLE eagerly; enabling them by
  default needs trainer loss, step-time and memory evidence and is left to a
  follow-up. The generator's gate (as two functions so its BF16 rounding
  matches the trainer's training-mode graph) and tiled convolution register
  under `ple_gate` and `ple_conv`, so they compile exactly when the trainer's
  do. History reads with hashing, the owned-row
  lookup and the per-token request indices (`vllm_query_requests` in
  `attention/query_positions.py`) register under the shared
  `inference_batch_invariant` region.
- `_replace_vllm_layer_configs` swaps `PLELayer.Config` for
  `VLLMPLELayer.Config`, the same path that swaps in the QSA, GDN, and KDA
  generation layers.
- Load non-FSDP parameters into their existing storage, while preserving frozen
  parameters and requiring every published trainable parameter to be filled.
- `VLLMPLELayer` rejects prefix caching, `mamba_cache_mode` other than
  `"none"` (its history follows a fixed GDN state slot), and speculative
  decoding.
- The history buffers take about 180 KiB per GDN state slot for the 125B
  model's PLE layer (9 x 10240 BF16 rows plus 2 int64 IDs). GDN has one state
  slot per KV-cache block, so the total scales with vLLM's KV-cache size, not
  with `max_num_seqs`: at DP4/EP4 on GB300 (4,081,987 KV-cache tokens in
  1568-token blocks, about 2,600 slots) they take about 0.45 GiB per GPU. They
  are allocated after vLLM sizes the KV cache, so they come out of the memory
  headroom left for CUDA graph capture. At most `max_num_seqs` slots are live at
  once; accounting for the buffers before KV sizing, or sizing them to live
  requests through a slot-to-row map, is a possible follow-up.

The generator passes PLE its token IDs and positions through the stock vLLM model wrapper; #6206 lets the Flash-Next model default them.

| Before | After |
| --- | --- |
| PLE loses history between generation calls | Chunked prefill/decode keeps per-request history, keyed by the layer's GDN state slot |
| Loader requires every parameter to belong to FSDP | Row-owned parameters load in place; frozen rows stay resident |

```bash
pytest -q tests/rl/unit_tests/gpu/test_vllm_ple.py
pytest -q tests/rl/unit_tests/cpu/test_vllm_wrapper.py \
  tests/rl/unit_tests/cpu/test_vllm_registry.py \
  tests/rl/unit_tests/cpu/test_generator_model.py \
  tests/rl/unit_tests/cpu/test_model_defaults.py
```

`test_vllm_ple.py` passes, including the 2-GPU owned-row gather test. Generator
PLE output is bitwise equal to the trainer `PLELayer` through chunk boundaries,
EOS resets, request reordering, state-slot reuse and padded single-token decode
steps, with eager, partial and full `local_compile` regions. The owned-row
gather is bitwise equal to the slot route with uneven DP token counts. The CPU
RL and Flash-Next suites pass (67 passed, 2 skipped).

Against the trainer's training-mode compiled PLE at production dimensions, the
generator output is 99.57% bitwise at batch 8 decode (max abs 0.031; the rest
comes from the M=8 split-K GEMM, which also differs eager vs eager), 100% at
batch 64 decode, and at least 99.995% for packed steps. Compiling the gate as
one region, as before, matched only about 84%.

PLE layer cost per step (4-layer Flash-Next slice, dummy weights, 2 GB300 at
DP2/EP2, FULL_DECODE_ONLY graphs, summed kernel time between marker kernels,
contexts = DAPO prompt + uniform(1, 4096) generated tokens):

| Shape | This PR | SGLang (Miles, TP2/EP2) |
| --- | --- | --- |
| Decode, batch 8 | 63.3 us | 68 us |
| Decode, batch 16 | 61.9 us | 72.1 us |
| Decode, batch 64 | 70.0 us | 111 us |
| 8 decoding + 8x210 arriving | 514 us | 1318 us |
| 64 decoding + 8x210 arriving | 543 us | 1309 us |

Two ranks only; at 8 ranks both sides' communication costs change. Loading a
production checkpoint end to end and an RL convergence run are not part of this
PR. These measurements used an Attention Gym development build with the paged
sparse APIs, before the pin bump in the first commit of this stack;
`test_vllm_ple.py` passes at the new pin on GB300.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants