Skip to content

[clone][rl] Generator FSDP base for FP8 storage - #4860

Closed
weifengpy wants to merge 1 commit into
gh/weifengpy/75/basefrom
gh/weifengpy/75/head
Closed

weifengpy wants to merge 1 commit into
gh/weifengpy/75/basefrom
gh/weifengpy/75/head

Conversation

@weifengpy

@weifengpy weifengpy commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

This is an independent copy of Andrew Or's PR #4838 at ee86dca, used as the base for a separate FP8 inference-storage draft. The code in this commit is identical to that revision. The original PR and its branch are not part of this ghstack.

Original proposal: #4838

Summary: Enable FSDP on the generator for quantization,
which reuses the FSDP tensor lifecycle mechanism introduced in
#4203 but for inference.
We always use fsdp=1 to avoid an actual all-gather.

New lifecycle:

bf16 sharded params (_LinearShardedTensorWithMXFP8Compute)
        |                                            ^
        |  fetch from TorchStore                     |
        v                                            |
updated bf16 sharded params                          |
        |                                            |
        |  unshard                                   |
        v                                            |
all-gathered mxfp8 params (_UnshardedFSDPTensor)     |
        |                                            |
        |                                            |
        |  forward (many decode steps)               |
        |                                            |
        ----------------------------------------------
                       new weight sync

Code cleanups enabled by this change:

  • Removed skip_dp flag, since we never skip_dp anymore
  • Removed spmd <-> DTensor glue code during weight sync,
    since model state dict always contains DTensors now

Potential concerns with this approach:

  1. Cudagraph compatibility: FSDP frees the unsharded storage
    today on reshard. However, cudagraph requires the unsharded
    address be the same across weight syncs. The current state in
    this PR requires an explicit reshard(free_unsharded=False)
    API, which does not exist in pytorch yet. We would need to add
    this or something similar to support cudagraphs.

  2. Extra decode memory: FSDP never frees the sharded storage
    today because it's supposed to be the source of truth. However,
    during decode, we don't actually need the bf16 copy anymore,
    since forward only needs the mxfp8 operands. At fsdp=1, this
    incurs an extra bf16 copy of the weights per layer during decode.
    We could work around this by calling private FSDP APIs to free
    this storage on unshard.

Requires pytorch/pytorch#198417 for new
FSDPModule.reshard flags.

[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 24, 2026
@weifengpy weifengpy changed the title [rl] Generator FSDP base for FP8 storage (independent draft) [clone][rl] Generator FSDP base for FP8 storage Sep 24, 2026
weifengpy added a commit that referenced this pull request Sep 24, 2026
Generator MXFP8 linears use FSDP degree 1, but retaining separate parameter and compute weights wastes memory and complicates CUDA graph weight updates. Store the existing quantizer's FP8 data and GEMM-ready scales as the parameter's persistent buffers, and let FSDP expose a compute view of those same allocations.

```
meta model -> TP -> FP8 storage -> fully_shard -> allocate/init

TorchStore BF16 receive DTensor
  -> existing MXFP8 quantizer
  -> update persistent FP8 data + GEMM-ready scales in place
  -> captured compute reads the same buffers
```

`_MXFP8StorageTensor` reuses `_quantize_mxfp8_weight`, `_MXFP8LinearOperands`, and `_UnshardedFSDPTensor`. There is one persistent storage subclass and one FP8 data allocation per converted weight. Loading BF16 weights preserves the addresses of the data and both existing scale layouts. No FSDP all-gather, packed byte payload, or scale-layout conversion is needed during unshard.

The inference variant is installed after TP and before `fully_shard`, with logical BF16 parameter metadata. State dicts expose temporary BF16 DTensors with the generator's mesh and placements, preserving checkpoint and TorchStore loading. It supports ordinary and stacked projections, requires complete TP-local 32x32 tiles, and explicitly requires FSDP degree 1. Training and grouped-expert implementations are unchanged.

Requires pytorch/pytorch#198468 for FSDP's borrowed-storage path and `fsdp_get_unsharded_view`. Generator parameters are frozen so ordinary BF16 parameters can share storage too. The generic generator prepare/finish callbacks remain for other formats with separate compute buffers and still require pytorch/pytorch#198417. Direct MXFP8 weight-loading tests exercise #198468 independently of #198417.

Validation:

- CPU quantization/storage suite: 61 passed.
- GPU storage and CUDA graph checks: 4 passed; 4 native MXFP8 cases skipped because this machine has H100 GPUs, not SM100.
- `pre-commit run --all-files`: passed, including type checking.
- GPU checks use real DTensor/FSDP with TP=1/2 and a reference quantizer plus BF16 matmul on H100. They verify exact data/scales, shared and stable addresses, and exact replay outputs after three BF16 loads without explicit reshard/unshard. Native TorchAO MXFP8/GEMM cases require SM100 GPUs; full vLLM/RL validation is not included.
- The GPU checks use the independent Python FSDP changes from #198468 on the existing built torch, without the earlier multi-rank extension-layout candidate. The CPU and multi-GPU test files are selected by the repository's existing CI workflows once that dependency is available.

Prepared with Codex as a user-requested draft. Based on the independent #4860 copy of #4838; the original #4838 is untouched.

ghstack-source-id: f959f33
Pull-Request: #4861
@tianyu-l tianyu-l closed this Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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