Repository navigation
Conversation
This was referenced 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
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):
Generator MXFP8 linears retain BF16 parameter shards during decoding and quantize after FSDP gathers them. Store E4M3 weight data and E8M0 scales instead, and gather those bytes into the existing MXFP8 compute buffers.
The generator replaces existing MXFP8Linear configs with an inference subclass. It installs quantized storage after TP sharding and before fully_shard. Training continues to use the existing MXFP8Linear. This covers ordinary and stacked projections; grouped experts keep their existing implementation.
State dicts expose temporary BF16 DTensors with the generator's mesh and placements, so checkpoint loading and TorchStore keep the existing BF16 transfer contract. Loading quantizes those receive buffers into the FP8 shards; the generator releases the buffers before unsharding. Data and scales share one flat byte payload per parameter, which also supports FSDP's degree-1 fast path. The existing forward kernels and quantization recipe are reused. Repeated updates refill the same FSDP compute tensors so captured CUDA graphs see the new weights.
Each converted persistent shard uses 33/32 bytes per weight: one E4M3 byte plus a row-major E8M0 scale per 32 columns. Scales repeat across the 32 rows of a quantization tile to preserve FSDP slicing. This is 48.4% less persistent shard storage than BF16, excluding unchanged compute buffers and temporary update buffers. Each TP/FSDP shard must contain complete 32x32 tiles; unsupported layouts fail explicitly.
This stack uses an independent copy of #4838. It does not update the original PR or its branch.
Draft prerequisites
reshard(free_unsharded=False, force=True), as the base PR does.Validation
pre-commit run --all-files: passed, including type checking.pytest tests/unit_tests/cpu/test_mxfp8_inference.py tests/unit_tests/cpu/test_quantized_fsdp_tensor.py tests/unit_tests/cpu/test_quantization.py -q: 61 passed.pytest tests/unit_tests/gpu/test_mxfp8_inference.py -q: 5 passed, 2 skipped. Two/four-GPU storage, FSDP degree 1/2 and TP placement, mixed FP8/BF16 parameters, initial graph capture, and three weight updates. Tests compare gathered data/scales byte-for-byte and require stable compute addresses and exact graph replay outputs.