Skip to content

[RL] Capture GDN prefill with stable replay metadata - #4738

Merged
drisspg merged 4 commits into
mainfrom
drisspg/gdn-prefill-cudagraph
Sep 18, 2026
Merged

drisspg merged 4 commits into
mainfrom
drisspg/gdn-prefill-cudagraph

Conversation

@drisspg

@drisspg drisspg commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Agent notes

  • Capture GDN prefill, mixed batches, and specialized decode using vLLM's native FULL CUDA graphs.
  • Stage offsets, cache slots, and initialization masks in persistent buffers. Preserve decode numerics and correctly initialize fresh requests on reused slots.
  • Add a narrow dispatcher adapter to distinguish packed and decode graph keys; vLLM retains ownership of capture/replay. Requires attn-gym[linear]==0.0.10.

Performance

Actual pre-PR a3a819c67 (FULL_AND_PIECEWISE) → 1018b0b9c (FULL): Qwen3.5-0.8B AlphabetSort RL, one trainer + one generator GB200, TP1/DP1, BF16 compute, compile off. Trainer FA2 / generator FA4 b31; policy lag 3 and vLLM async ON in both.

Unprofiled end-to-end metric Before After
Seconds/update interval ↓ 15.700 1.318
Generated tokens/second ↑ 62.35 741.77

One sequential pair, two warmup updates + ten measured update intervals; initialization/capture excluded. Measured between completed weight pulls, including native generation/control/handoff waits. Each returned 376 completions (9,788 / 9,779 tokens). Observed latency reduction: 91.6%, workload-specific—not an isolated kernel speedup or convergence claim.

Perfetto: generator before/after · trainer + rollout + handoffs. Separate profiled runs; do not infer speedup from trace duration. Links are internal with 28-day upload retention.

Earlier inference-only prefill: batch 32 × 4096 input tokens, output 1, one GB200, async off: median 1.869 → 0.809 s (2.31×) over ten runs. Before/after trace. Historical c48650f06 → 1ac48cbbf, not a current-head rerun.

Correctness / limits

  • Seven regressions passed. Eager/FULL matched exactly within each regular and batch-invariant mode: 96 tokens, 480 logprob entries/ranks, cumulative logprobs, and 1,584 conv/SSM state hashes; 43 actual FULL replays per mode. Includes independent NaN-poisoned fresh-slot reuse checks.
  • Real RL runs passed finite-gradient/reward checks, policy-age bounds, versioned weight delivery, and warmup sampled weight equality.
  • Validation used Gym commit 4ac49088a, not a rerun against the pinned 0.0.10 wheel. Broader topologies remain unvalidated; no TP4 claim.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 16, 2026
@drisspg
drisspg added this pull request to stack #4739 September 16, 2026 02:26
@drisspg
drisspg force-pushed the drisspg/gdn-prefill-cudagraph branch from e46f1db to a82a129 Compare September 16, 2026 02:35
@drisspg
drisspg removed this pull request from stack #4739 September 16, 2026 02:39
@drisspg
drisspg force-pushed the drisspg/gdn-prefill-cudagraph branch from a82a129 to 81782e7 Compare September 16, 2026 02:39
@drisspg
drisspg changed the base branch from drisspg/rl-runtime-setup-20260913 to drisspg/attn-gym-0.0.9 September 16, 2026 02:39
@drisspg
drisspg added this pull request to stack #4740 September 16, 2026 02:39
Base automatically changed from drisspg/attn-gym-0.0.9 to main September 16, 2026 03:09
drisspg added a commit that referenced this pull request Sep 16, 2026
## Summary

PR chain: **this PR** -> #4738 (Qwen/FULL-graph fix) -> #4737 (FA4 b31
pin, pending publication).

Bump `attn-gym[linear]` from **0.0.8 to the published 0.0.9 release** in
`pyproject.toml` and `.ci/docker/requirements.txt`.

This is the dependency-only bottom layer for the GDN capture work in
#4738. No TorchTitan model, vLLM integration, or graph behavior changes
are included.

## Validation

- PyPI release availability and published wheel SHA256 verified.
- Published wheel is byte-identical to the release workflow artifact.
Compared with the previously validated source pin, 202 Python files are
unchanged; only three sparse-indexer files differ. GDN/gate code is
unchanged.
- Installed the published release into the existing validated Torch/vLLM
environment. Import checks from outside the checkout passed.
- Real Qwen3.5-0.8B TP1 engine validation passed on this dependency-only
layer: five batches of 32 requests x 4096 input tokens, with 64
scheduler chunks per batch. Generated outputs also match the historical
pre-bump baseline exactly. This was a compatibility check, not a new
performance measurement.
- Dependency pin consistency, scoped pre-commit, and whitespace checks
passed.

The following layer (#4738) adds FULL-graph support; #4737 updates the
FA4 recommendation afterward, pending b31 publication. This PR can be
reviewed independently as a two-line dependency bump.
@drisspg
drisspg force-pushed the drisspg/gdn-prefill-cudagraph branch 2 times, most recently from 3240bfe to ab19520 Compare September 16, 2026 03:17
@drisspg
drisspg removed this pull request from stack #4740 September 16, 2026 22:22
@drisspg
drisspg changed the base branch from main to drisspg/rl-runtime-setup-20260913 September 16, 2026 22:22
@drisspg
drisspg force-pushed the drisspg/gdn-prefill-cudagraph branch from 6081476 to f3f60ab Compare September 16, 2026 22:22
@drisspg
drisspg added this pull request to stack #4758 September 16, 2026 22:52
@drisspg
drisspg force-pushed the drisspg/gdn-prefill-cudagraph branch from f3f60ab to 66f35fe Compare September 16, 2026 23:07
Base automatically changed from drisspg/rl-runtime-setup-20260913 to main September 17, 2026 00:00
drisspg added a commit that referenced this pull request Sep 17, 2026
## Summary


Published b31 is now available and validated on GB200.


PR chain: #4736 (Gym release, merged); **this PR, based on main** ->
#4738 (GDN FULL graphs, waiting for the next Gym release).

Update the Blackwell FA4 recommendation to:

```bash
uv pip install "flash-attn-4[cu13]>=4.0.0b31"
```

Qwen3.5 head-dimension-256 paged inference needs the
sequence-length/paged-KV fixes from [FA4
#2810](Dao-AILab/flash-attention#2810) and the
output-alignment fix from [FA4
#2880](Dao-AILab/flash-attention#2880). The
inspected PyPI b30 wheel predates those changes.

**Only +2/-1 in the RL README.** Original unpinned
Torch/torchvision/vLLM/torchcomms instructions, CUDA index, and existing
FFI warning remain unchanged.

## Published b31 validation

Installed exact **`flash-attn-4[cu13]==4.0.0b31` from PyPI**, using
normal binary-only dependency resolution. All 52 installed Python files
match the published wheel. Torch, vLLM, Gym, CuTeDSL and TVM-FFI
versions were unchanged; this is not a fresh-environment
dependency-resolution claim.

- Reproduced b30's `SM100 forward with head_dim=256 does not support
seqused_q/seqused_k` failure. The identical GPU call passes on published
b31.
- **Four GPU cases passed** against an independent FP64 reference:
decode/prefill, non-page-aligned KV lengths, oversized shuffled page
tables, packed KV strides, and padded/transposed output alignment.
- **Seven existing TorchTitan tests passed** on the graph layer's
unchanged model/test sources, including real Qwen3.5-0.8B TP1/DP1
eager/FULL execution in regular and batch-invariant modes. Each mode
independently matched exactly: 96 generated tokens, 480 logprob
entries/ranks, cumulative logprobs, and 1,584 used conv/SSM state
hashes; 43 actual FULL replays per mode.
- Tests explicitly forced Flash and recorded actual FA4 calls, including
capture. Activation alone can allow cuDNN selection in this Torch build.

**Limits:** GB200/SM100, BF16 forward, TP1 only. Unused KV padding must
be finite: a separate NaN-poison probe contaminates b31 outputs. The
established environment's FFI/optional-package/platform-tag warnings are
unchanged. No performance remeasurement or equality claim against the
previous development FA4 build. Historical trace results still use
source commit `383cbcba`.

Only the README minimum changes in this PR; graph support and its Gym
release dependency remain in #4738. Requirement syntax, scoped
pre-commit and whitespace checks previously passed; the reorder
preserves the combined source tree exactly.
@drisspg
drisspg force-pushed the drisspg/gdn-prefill-cudagraph branch 2 times, most recently from 5a72100 to 4025777 Compare September 17, 2026 00:00
@drisspg
drisspg marked this pull request as ready for review September 17, 2026 02:14
@drisspg
drisspg force-pushed the drisspg/gdn-prefill-cudagraph branch from 7e3c01d to 1018b0b Compare September 17, 2026 02:14
@drisspg
drisspg requested a review from wconstab as a code owner September 17, 2026 02:14
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Sep 17, 2026

@tianyu-l tianyu-l 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.

looks super cool

Comment thread torchtitan/rl/model/gdn_backend.py Resolved
Comment thread torchtitan/rl/model/vllm_worker.py Resolved
@@ -130,6 +132,9 @@ def __init__(self, config: Config) -> None:
raise ValueError(f"Duplicate GDN layer name: {self.prefix}")
compilation_config.static_forward_context[self.prefix] = self

def get_attn_backend(self) -> type[AttentionBackend]:

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.

so seems this not required by MambaBase, rather it's a helper called by TorchTitanGPUModelRunner.load_model()?

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.

A handy visual;

image

baiscally since we have some different metadata we use this hook so that VLLM invokes our builder instead of the built in

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.

And its just to smuggle in:

class GDNExecutionPath(Enum):
     SINGLE_TOKEN = auto()
     PACKED = auto()

So when we know when its safe to do the fast fuse decode impl vs the pakced form

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.

@drisspg
drisspg force-pushed the drisspg/gdn-prefill-cudagraph branch from 1018b0b to b888796 Compare September 18, 2026 16:15
Comment thread torchtitan/rl/model/gdn_backend.py Resolved
@@ -130,6 +132,9 @@ def __init__(self, config: Config) -> None:
raise ValueError(f"Duplicate GDN layer name: {self.prefix}")
compilation_config.static_forward_context[self.prefix] = self

def get_attn_backend(self) -> type[AttentionBackend]:

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.

@drisspg
drisspg merged commit 030673f into main Sep 18, 2026
21 checks passed
# The caller-owned output has a stable address across graph replays.
# vLLM leaves attention eager under PIECEWISE and captures this same
# implementation under FULL. Metadata is prepared exclusively by the builder.
@eager_break_during_capture

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.

Why we still keep this decorator? To make "our GDN kernel + vllm prepared metadata" still PIECEWISE cudagraph-able?

I wonder if people would use this our GDN kernel + vllm prepared metadata path. If titanRL only allows our GDN kernel + titanRL prepared metadata, we can just remove this decorator?

drisspg added a commit that referenced this pull request Sep 21, 2026
## Summary

Rename `PyTorchVarlenInnerAttentionBackend` to
`TorchTitanVarlenInnerAttentionBackend`, following the naming feedback
on #4738. This is a class-name-only change; vLLM's `CUSTOM` registration
and implementation remain unchanged.

## Validation

- Verified `AttentionBackendEnum.CUSTOM.get_class()` resolves to the
renamed class and its registry name remains `CUSTOM`.
- Scoped pre-commit passed; the global mutating Pyrefly hook was
skipped.
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.

3 participants