Skip to content

[PyTorch] Separate grouped FP8 and NVFP4 data from metadata for activation offloading - #3954

Open
lhb8125 wants to merge 10 commits into
NVIDIA:mainfrom
lhb8125:codex/fix-bulk-allocation-offload
Open

lhb8125 wants to merge 10 commits into
NVIDIA:mainfrom
lhb8125:codex/fix-bulk-allocation-offload

Conversation

@lhb8125

@lhb8125 lhb8125 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Change

GroupedLinear packed each expert’s quantized data and scales into the same bulk storage. A small scale kept on CUDA could therefore keep the entire data block alive after offload.

  • For blockwise FP8, MXFP8 and NVFP4, each requested direction now has separate allocator-owned storage for data and metadata. NVFP4 keeps its optional amax with the scales. The existing size threshold applies to each tensor, and record_stream tracks the shared allocation during asynchronous copies.
  • Enable bulk allocation during offload for forward inputs, Hybrid grad outputs and input requantization for weight gradients. Hybrid dispatches each direction independently. Eligible NVFP4 groups keep fused quantization. Unsupported configurations such as 2D quantization and collective amax use the per-expert path.

Validation

Ran Megatron pretrain_gpt.py (c5f510b76, EP2, four MoE layers, three Adam steps). TE e970e08b adds tests to the production code in d97d8a49. At every step, loss, gradient norm, gradients and updated parameters matched the offload-disabled control on both ranks. Companion Megatron PR

Recipe TE commit / job Data blocks released / FC1 bulk calls Allocated drop per release Metadata retained on CUDA through backward
H100 blockwise FP8 e970e08b / 6677061 20 / 24 16.0005 MiB 40 scales
GB300 MXFP8 e970e08b / 2349987 20 / 24 16.0005 MiB 40 scales
GB300 NVFP4 d97d8a49 / 2346453 20 / 24 8.0005 MiB 40 scales and 40 amax values

Why 20 releases from 24 bulk calls? The FP8 traces show that after warmup, MCore keeps layer 4’s FC1 input on the GPU because backward uses it first. On steps 2 and 3, ranks 0 and 1 each skipped that layer’s device-to-host copy. All 20 groups selected for offload released their data storage.

Targeted tests passed on H100 (91) and GB300 (131), including coverage for storage release, byte-exact reload and quantization dispatch. In a GB300 NVFP4 split with 16 local experts and offload enabled, fusion reduced kernel launches from 48 to 3 and summed GPU kernel time from 253 to 23 µs. With offload disabled, the same split kept 3 launches and host call time rose from 253 to 264 µs.

Signed-off-by: hongbinl <hongbinl@nvidia.com>
@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Nov 27, 2026
…ation

Signed-off-by: hongbinl <hongbinl@nvidia.com>
@lhb8125 lhb8125 changed the title [PyTorch] Preserve allocator-owned storage in bulk allocation [PyTorch] Separate bulk FP8 data and scales for activation offloading Nov 27, 2026
Signed-off-by: hongbinl <hongbinl@nvidia.com>
Signed-off-by: hongbinl <hongbinl@nvidia.com>
Signed-off-by: hongbinl <hongbinl@nvidia.com>
Signed-off-by: hongbinl <hongbinl@nvidia.com>
Signed-off-by: hongbinl <hongbinl@nvidia.com>
Signed-off-by: hongbinl <hongbinl@nvidia.com>
@lhb8125 lhb8125 changed the title [PyTorch] Separate bulk FP8 data and scales for activation offloading [PyTorch] Separate grouped FP8 and NVFP4 data from metadata for activation offloading Nov 27, 2026
Signed-off-by: hongbinl <hongbinl@nvidia.com>
Signed-off-by: hongbinl <hongbinl@nvidia.com>
@lhb8125
lhb8125 marked this pull request as ready for review November 27, 2026 14:49
@lhb8125
lhb8125 requested a review from ksivaman as a code owner November 27, 2026 14:49
@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5 · The PR appears safe to merge, with one non-blocking correction needed in a test assertion.RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect PyTorch grouped quantization and activation offload paths.

The PR appears safe to merge, with one non-blocking correction needed in a test assertion.

Findings

  1. P2 Scale check misses offload exclusions ▶

Summary

Separates grouped FP8 and NVFP4 data from scales and optional amax values, so metadata can stay on GPU after data is offloaded.

  • Grouped quantized data now leaves GPU storage independently of its scales.
  • GroupedLinear keeps bulk allocation available during activation offload.

lhb8125 explicitly acknowledges the extra allocation and view-construction cost in the PR description and provides host-call and training measurements.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Q[Grouped quantization] --> D[Shared data storage per direction]
  Q --> M[Separate scales and optional amax storage]
  D --> O[Copy expert data to CPU]
  O --> R[Release all GPU data references]
  R --> F[Data storage can be freed]
  M --> G[Metadata can stay on GPU]
Loading

Reviews (1) · Last reviewed commit: "Exercise bulk offload lifetime and group..." · Reviewed by Greptile

Comment thread tests/pytorch/test_quantized_tensor.py Resolved

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

community-contribution PRs from external contributor outside the core maintainers, representing community-driven work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant