Repository navigation
[Fix] Chunk stacked weights in tilewise FP8 scale precompute - #2337
Merged
Merged
Conversation
precompute_tilewise_float8_scale_for_fsdp stacked every same-shape weight into one tensor to compute per-block scales in a single shot, so the stack peak grew linearly with the shape group (observed: a 10 GiB spike OOMing 35B-A3B RL training when colocated with other memory consumers). Per-block amax reduces within each 128x128 block and across reduce_mesh only, never across the stacked dim, so processing the group in chunks bounded by a 1 GiB stack budget is bitwise identical. Chunk boundaries derive from deterministic traversal order and padded shapes, so every rank chunks identically; the only cost is extra reduce_mesh collectives (one per chunk). Add max_stack_bytes to precompute_tilewise_float8_scale_for_fsdp and CPU/gloo regression tests covering chunk invariance, mixed shape groups, and block-amax correctness.
ShilohYu
force-pushed
the
fix/fp8-tilewise-scale-chunked-stack
branch
from
November 24, 2026 07:49
93e7550 to
d53b951
Compare
- Thread max_stack_bytes through Float8Config -> Float8Handler -> precompute_tilewise_float8_scale_for_fsdp (default unchanged, 1 GiB). - Add 2-rank gloo tests covering the all_reduce (dout<128) and divided_64 (dout%128==64) paths: chunked vs single-shot bitwise equality, which also exercises cross-rank chunk-boundary consistency (mismatched boundaries would deadlock the collectives). - Clarify the budget comment: the bf16 roundtrip transiently holds up to ~2.5x the estimated bytes.
ShilohYu
force-pushed
the
fix/fp8-tilewise-scale-chunked-stack
branch
from
November 24, 2026 08:36
0b14c9b to
2a539c2
Compare
The flat numel*4 estimate undercharges the realistic RL case (bf16 weights with XTUNER_RL_FP8_QUANTIZE_IN_BF16=1 peaks at 6 bytes/elem, fp32 at 10). Derive the per-element peak from the actual weight dtype and the roundtrip helper, and consolidate the roundtrip itself into _rl_bf16_roundtrip (also used by fsdp_pre_all_gather) so the estimate and the implementation live next to each other. Add a probe test pinning the torch semantics the factor relies on (.bfloat16() is a no-copy self-return for bf16 sources) and a chunked vs single-shot equality test under the env enabled.
ShilohYu
force-pushed
the
fix/fp8-tilewise-scale-chunked-stack
branch
from
November 24, 2026 08:57
2a539c2 to
0718b55
Compare
jayhenry
approved these changes
Nov 25, 2026
… the stack path - Extract the stack -> roundtrip -> scale kernel -> write-back body into _stack_and_precompute_tilewise_scales, reused by both the single-shot and the chunked paths. - max_stack_bytes=None now disables chunking (one stack per shape group, the pre-chunking behavior); a set value enables chunked processing. The default stays at the 1 GiB budget.
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.
Problem
precompute_tilewise_float8_scale_for_fsdpstacked every same-shape weight into one tensor to compute per-block scales in a single shot, so the temporary stack peak grew linearly with the shape group. Observed on Qwen3.5-35B-A3B RL training (MoE-only FP8): a 10 GiBtorch.stackspike OOMed the critic step when colocated with other memory consumers.Fix
Per-block amax reduces within each 128x128 block and across
reduce_meshonly, never across the stacked dim, so processing the group in chunks bounded by a stack budget is bitwise identical to the single-shot stack. Chunk boundaries derive from deterministic traversal order and padded shapes, so every rank chunks identically; the only cost is extrareduce_meshcollectives (one per chunk).max_stack_bytestoprecompute_tilewise_float8_scale_for_fsdpand thread it throughFloat8Config->Float8Handler, so training configs can lower the budget for tighter colocation. A set value processes each shape group in budget-bounded chunks;Nonedisables chunking and restores the original single-stack behavior. The default stays at the 1 GiB budget._stack_and_precompute_tilewise_scales._rl_bf16_roundtrip/_rl_bf16_roundtrip_peak_bytesso the estimate and the implementation stay next to each other.Tests
9 CPU/gloo tests cover:
XTUNER_RL_FP8_QUANTIZE_IN_BF16=1;max_stack_bytes=Nonedisabling chunking (single kernel call per shape group) while matching the chunked result bitwise;max_stack_bytespassthrough fromFloat8ConfigthroughFloat8Handlerto the precompute call (default 1 GiB, explicit budget, explicitNone);.bfloat16()is a no-copy self-return for bf16 sources).Context
Hit during RL training with a colocated judge service on the same node; the fix removes the transient peak so colocation fits in memory.