Repository navigation
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Code cleanups enabled by this change:
skip_dpflag, since we never skip_dp anymoresince model state dict always contains DTensors now
Potential concerns with this approach:
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.
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.reshardflags.