Skip to content

[rl] Send quantized generator parameters as their quantized operands - #6152

Open
wolfcomos wants to merge 2 commits into
pytorch:mainfrom
wolfcomos:rl-packed-quantized-weight-sync
Open

wolfcomos wants to merge 2 commits into
pytorch:mainfrom
wolfcomos:rl-packed-quantized-weight-sync

Conversation

@wolfcomos

@wolfcomos wolfcomos commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human-written)

Why

A generator with quantized experts (MXFP8 Dist-MoE with mxfp8_mega_fused_inference) keeps only their operands (fp8 codes and E8M0 scales). Every sync still sends those experts in BF16 (58 of the 61 GB for Qwen3-30B-A3B). Each generator rank then reallocates, unshards and re-quantizes them. The trainer can produce exactly those operand bytes, and the generator can copy them into its operand storage: half the bytes, and nothing to re-quantize.

config.generator.receive_quantized_operands = True  # default False

What changed

  • Format hook: _ShardedFSDPTensor._packed_operands(operands) returns per-expert row views of the operands. MXFP8 Dist-MoE implements it.
  • New torchtitan/rl/quantized_operands.py (81 lines):
    • OperandFormat is the generator's format, rebuilt on the trainer with __tensor_unflatten__.
    • pack_quantized_operands quantizes this rank's rows with that format and sends them as uint8 rows, sharded like the parameter.
  • Generator: with receive_quantized_operands, ModelStateDictLoader keeps one pinned prefetch buffer per operand tensor and copies the rows into the operands in place. Those FSDP groups are never resharded. Requires model_state_dict_load_mode="cpu_prefetch".
  • Trainer:
    • One init exchange gives it generator 0's formats.
    • _trainable_model_state_dict packs the registered parameters on the push stream.
    • Both transports send the packed keys like any others. ModelStateDictTransport no longer casts non-floating-point keys, as TorchStore already does.
  • Unsupported combinations raise: gpu_fetch, a trainer FSDP that splits an expert, experts sharing an FSDP group with other parameters (generator EP 1), and formats without _packed_operands.

Numerics

The operands are bitwise the ones a BF16 load re-quantizes. The 2-GPU test checks the operands and the logprobs under FULL CUDA graphs.

MXFP8 Qwen3-30B-A3B DAPO, 50 steps, means over steps 1-50 (main / this PR):

seed logprob diff mean ratio clipped frac reward
1000 -1.339e-3 / -1.339e-3 0.00923 / 0.00912 0.294 / 0.297
2000 -1.300e-3 / -1.324e-3 0.00907 / 0.00908 0.301 / 0.300

Performance

MXFP8 Qwen3-30B-A3B, 8xB200 (trainer FSDP4/EP4, generator DP4/EP4):

main this PR
TorchStore: generator load (median) 2198 ms 341 ms
TorchStore: GB per sync 61.06 32.98
TorchStore: s/step, steps 2-10 (seed 1000) 19.3 16.4
ModelStateDictTransport (NIXL): generator load / pull 1.89 / 2.75 s 0.36 / 0.79 s
trainer peak reserved (TorchStore) 150.3 GiB 157.4 GiB

Part of the TorchStore load gain is pinned buffers: with #6129 alone, main's load is 663 ms.

Testing

  • tests/rl/unit_tests/cpu: 678 passed, 7 skipped after the rebase onto 361ae5d. pre-commit passes.
  • test_generator_dist_moe_mxfp8.py: [1] (1 GPU) and [2] pass. [2] runs on 2 GPUs with EP 2 and checks quantized-operand loads, with bitwise operands and logprobs. CI runs [2].
  • New CPU tests: test_quantized_operands_need_their_own_param_group; test_mixed_dtypes is extended.
  • The end-to-end runs above used the base a28bdb1. The branch rebased onto 361ae5d without conflicts.

Known issues

🤖 Generated with Claude Code

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 17, 2026
@pytorch-bot

pytorch-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/rl
  • ciflow/b200
  • ciflow/fake-pg

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

wolfcomos and others added 2 commits November 17, 2026 23:02
With Generator.Config.receive_quantized_operands (default False), the trainer
quantizes each parameter the generators hold quantized (MXFP8 Dist-MoE
experts) with the generators' own format and sends the operand bytes. The
generator copies them straight into the operand storage its forward reads:
loads no longer reallocate, unshard or re-quantize those parameters, and the
sync moves fp8 codes and scales instead of BF16 (61 -> 33 GB per sync for
Qwen3-30B-A3B). The operands are bitwise the ones a BF16 load re-quantizes.

- _ShardedFSDPTensor._packed_operands: optional format hook returning views of
  the operands with one row per row of the logical tensor's dim 0 (one per
  expert); MXFP8 Dist-MoE implements it.
- torchtitan/rl/quantized_operands.py: the format a generator reports (class
  and __tensor_flatten__ context), the byte layout sharded on dim 0 like the
  parameter, and the trainer-side packing.
- ModelStateDictLoader.receive_quantized_operands: swaps the prefetch buffers
  of quantized parameters for their packed rows; loads leave their FSDP
  parameter groups unsharded and copy the rows into the operands.
- ActorSystem.initialize_quantized_operands hands generator rank 0's formats
  to the trainer before the model state dict transport initializes; the
  trainer packs them in _trainable_model_state_dict on the push stream, and
  _preserve_dtype_keys casts only parameters.

Unsupported layouts raise: gpu_fetch, trainer shards that split an expert,
generator FSDP groups that mix quantized and other parameters (EP 1), FSDP
sharding of a quantized parameter on the generator.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Same behavior on every supported configuration; about half the diff of the
previous commit:

- ModelStateDictTransport keeps the dtype of non-floating-point tensors, as
  TorchStore's _wire_dtype does, instead of the trainer listing every
  non-parameter key as preserved; revert the _preserve_dtype_keys rewrite.
- Inline operand_format; drop the "nothing quantized" ValueError and the
  post-fetch missing-keys check (cpu_prefetch fills every key); the
  FSDP-sharding check on the generator becomes an assert (full EP).
- Shorter docs.
- Tests: the 2-GPU check parametrizes the existing MXFP8 generator test; the
  CPU tests keep only the mixed-group ValueError and the uncast bytes in
  test_mixed_dtypes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@tianyu-l

Copy link
Copy Markdown
Contributor

I didn't check code, but high level questions

  • if trainer side shards cannot be quantized before all-gather (due to sharding happens within quantization block), what would you do -- perform all-gather first and send Replicate quantized params to generator?
  • if we support delta weight sync, how important is this optimization?

@wolfcomos

Copy link
Copy Markdown
Contributor Author

I didn't check code, but high level questions

  • if trainer side shards cannot be quantized before all-gather (due to sharding happens within quantization block), what would you do -- perform all-gather first and send Replicate quantized params to generator?
  • if we support delta weight sync, how important is this optimization?

Thanks for the quick review!

  1. In this PR I simply guarded for cases where rank doesn't have full expert. The fallback for that case would be what you describe: all-gather, quantize, and send Replicate. For MXFP8 specifically, row sharding doesn’t split the 1x32 blocks along K, so rows aligned to the 128-row scale tiles could quantize locally without the all-gather.

  2. They're complementary. Delta cuts the bytes generators read, and this PR cuts the generator's pause, which delta doesn't touch. The load path is unchanged, so with BF16 deltas an MXFP8 generator still re-quantizes every expert at each load (1.89 s vs 0.36 s with this PR on Qwen3-30B-A3B). Delta also compress better with quantization. For example small update changes BF16's low mantissa bits but usually leaves the E4M3 code in the same bin, and the E8M0 scales rarely change. At lr 5e-6, 2.6% of BF16 elements change per step vs 0.25% of MXFP8 codes, so each generator rank reads ~0.09 GB per push instead of 0.47-0.58 GB. This is very beneficial for cross node as well.

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

ciflow/b200 Trigger B200 CI ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants