Repository navigation
Experts and TP: per-instance experts flags, load-time-only experts, scalars and per-expert scales in TP and EP - #49775
Open
IlyasMoutawwakil wants to merge 12 commits into
Open
IlyasMoutawwakil wants to merge 12 commits into
IlyasMoutawwakil wants to merge 12 commits into
Conversation
IlyasMoutawwakil
force-pushed
the
fg-split/3-experts-tp
branch
from
October 20, 2026 11:08
dc6c12d to
1b8bd6a
Compare
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
IlyasMoutawwakil
force-pushed
the
fg-split/3-experts-tp
branch
from
October 20, 2026 11:20
1b8bd6a to
bf49e7e
Compare
IlyasMoutawwakil
force-pushed
the
fg-split/3-experts-tp
branch
from
October 20, 2026 13:33
bf49e7e to
caf0319
Compare
IlyasMoutawwakil
force-pushed
the
fg-split/3-experts-tp
branch
from
October 20, 2026 16:04
caf0319 to
a1e72b9
Compare
IlyasMoutawwakil
force-pushed
the
fg-split/3-experts-tp
branch
from
October 20, 2026 16:25
a1e72b9 to
2a513c3
Compare
vasqu
reviewed
Oct 20, 2026
vasqu
left a comment
Collaborator
There was a problem hiding this comment.
Let's wait on @3outeille PRs first no? Same for your EP stack then
IlyasMoutawwakil
force-pushed
the
fg-split/3-experts-tp
branch
from
October 20, 2026 16:43
2a513c3 to
602bdd3
Compare
IlyasMoutawwakil
force-pushed
the
fg-split/3-experts-tp
branch
from
October 20, 2026 17:34
602bdd3 to
84d4b70
Compare
IlyasMoutawwakil
force-pushed
the
fg-split/3-experts-tp
branch
from
October 21, 2026 07:24
0f29329 to
305cfa9
Compare
IlyasMoutawwakil
force-pushed
the
fg-split/3-experts-tp
branch
from
October 21, 2026 07:36
305cfa9 to
0d16e73
Compare
IlyasMoutawwakil
force-pushed
the
fg-split/3-experts-tp
branch
from
October 21, 2026 07:52
0d16e73 to
a222daa
Compare
IlyasMoutawwakil
marked this pull request as ready for review
October 21, 2026 09:38
IlyasMoutawwakil
force-pushed
the
fg-split/3-experts-tp
branch
from
October 23, 2026 13:03
a222daa to
d451c22
Compare
…perts requirements - use_experts_implementation sets its layout flags as class attributes; a flag the class body or the instance sets wins, so one wrapper class serves experts of many models. - ExpertsRequirements (switchable, parallel_styles) registered with an implementation's name in ExpertsInterface; set_experts_implementation consults it instead of special-casing deepgemm_megamoe, and checks the weight layout experts were loaded in (experts_weight_layout). - modeling_utils lists implementation names through ALL_EXPERTS_FUNCTIONS.valid_keys() and no longer imports finegrained_fp8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- tp_uses_local_tensors: a public marker, read in one place, replacing _hf_quantized_needs_local_tp (torchao and legacy FP8 switched). - moe_experts_colwise / moe_experts_packed_colwise / moe_experts_rowwise shard each expert of a stacked (E, out, in) param; MoEParamShard refuses to split experts with a post-expert norm. - resolve_parallel_plans swaps in an experts implementation's parallel styles and replicates every 0-dim parameter a plan covers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…anisms The legacy FP8 quantizer replicated 0-dim params and swapped the Mega MoE styles itself. `resolve_parallel_plans` does both, so its override and `FP8Experts._impl_tp_layer_overrides` go. Make the plan helpers private and in place, inline the local-tensors marker check, and trim the comments. Test the intra-expert placements, the plan resolution and a non-switchable implementation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewrite the comments, docstrings and docs prose this PR adds in short, plain sentences. Drop comments that restate the code and history or benchmark narration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…inery PR Their first user is FineGrainedExperts, which the machinery PR adds: the experts weight-layout check in set_experts_implementation, and the moe_experts_colwise / packed_colwise / rowwise styles with the post-expert-norm guard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lice Main only did so for exactly one dim fewer, so per-expert 0-dim scales were kept on every rank. The quantized experts of the fine-grained stack hit this under expert parallelism. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IlyasMoutawwakil
force-pushed
the
fg-split/3-experts-tp
branch
from
October 23, 2026 13:35
d451c22 to
c255487
Compare
…g-split/3-experts-tp
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: finegrained_fp8 |
IlyasMoutawwakil
added a commit
that referenced
this pull request
Nov 12, 2026
…the grouped GEMM - NVFP4Experts registers parameters, which the EP styles shard along the expert axis; the plan gives the swizzled scales their weight's style. Tensor parallelism of NVFP4 layers still raises, unless they are kept whole. - Both experts forwards skip the routes expert parallelism marks for other ranks. - A per-expert slice can have fewer dims than its parameter, e.g. a 0-dim per-expert scale (as in #49775). - generate switches grouped_mm to batched_mm while decoding: NVFP4 runs the grouped GEMM for it. - Weight-only experts run eager whatever the experts class wrapping, which use_experts_implementation does in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IlyasMoutawwakil
added a commit
that referenced
this pull request
Nov 12, 2026
…weight-only, generate (#50670) * Quantization plan: param_needs_quantization asks the param's quantizer The plan inherited HfQuantizer's default (False), so the shape check reported every bitsandbytes weight mismatched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * NVFP4: refuse tensor and expert parallelism again instead of replicating the layers Replicating kept the packed weights whole on every rank, not just the scales. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ModelOpt schema: warn that W4A16 NVFP4 runs with FP4 activations and that KV cache quantization is dropped Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Quantization plan: drop the __class__ and __reduce__ overrides Nothing checks a loaded model's quantizer class: the plan is the quantizer, a single one reached through it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * NVFP4: weight-only (W4A16) checkpoints run their dequantized weights on full precision activations ModelOpt's W4A16_NVFP4 loaded with the W4A4 config, which quantizes activations. NVFP4Config(weight_only=True) keeps the weights packed and dequantizes them in each forward, in pure PyTorch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Quantization plan: drop __getattr__, GGUF's loading calls its quantizer explicitly Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * NVFP4: expert parallelism for NVFP4 experts; batched_mm decodes with the grouped GEMM - NVFP4Experts registers parameters, which the EP styles shard along the expert axis; the plan gives the swizzled scales their weight's style. Tensor parallelism of NVFP4 layers still raises, unless they are kept whole. - Both experts forwards skip the routes expert parallelism marks for other ranks. - A per-expert slice can have fewer dims than its parameter, e.g. a 0-dim per-expert scale (as in #49775). - generate switches grouped_mm to batched_mm while decoding: NVFP4 runs the grouped GEMM for it. - Weight-only experts run eager whatever the experts class wrapping, which use_experts_implementation does in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * NVFP4 EP test: run the W4A4 experts too, on the fake kernel, through both implementations The fake grouped GEMM leaves rows past the last group NaN like the real one leaves them unwritten, so the test catches a forward that doesn't zero other ranks' routes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * NVFP4: refuse tensor parallelism from the distributed config alone The plan inspection duplicated how the plans resolve. Tensor parallelism of NVFP4 layers isn't supported, so a tensor-parallel run refuses NVFP4 linears, and NVFP4 experts without expert parallelism to shard them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Quantizers: fix the type checker's errors - The FP8 and MXFP4 modules declare their local tensor-parallel forward as a class attribute instead of each instance. - The plan's module swap no longer writes `source_cls`, which only bitsandbytes reads, on modules it swaps itself. - NVFP4 reads `ep_size` like `tp_size`, from a distributed config that may be absent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * NVFP4: load ModelOpt linears' static input_scale A pre-quantized NVFP4Linear declared an empty input_scale placeholder, while ModelOpt saves a scalar, so loading any W4A4 checkpoint with quantized linears (e.g. nvidia/Qwen3-30B-A3B-NVFP4's attention) failed on a size mismatch. The placeholder now holds one value for pre-quantized loads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * NVFP4: pass the global scales torch's grouped NVFP4 GEMM requires F.scaled_grouped_mm has no NVFP4 implementation for block scales alone ("No gemm implementation was found" on B200, torch 2.12 and 2.13): it takes [BlockWise1x16, TensorWise] per operand. The global scales are ones, as they are applied to the output. The fake GEMM in the tests now refuses the old call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * NVFP4: grouped experts forward with bf16 routing weights The grouped forward scattered its rows into a float32 buffer without a cast: with a bf16 model's bf16 routing weights the rows stay bf16 and index_put fails on the dtype mismatch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * NVFP4: multi-device device_map for pre-quantized checkpoints Only quantizing on the fly needs one device (it packs every weight on quantization_device). A pre-quantized checkpoint now loads across several GPUs, each checked for Blackwell. On B200, nvidia/Qwen3-30B-A3B-NVFP4 split over 2 GPUs matches the one-GPU load exactly (logits and greedy tokens, eager and grouped_mm); the hub kernel runs on its inputs' device, not the current one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Address review: weight-only is a forward choice, docstrings, spacing - NVFP4 modules always carry the swizzled scales, whose shape is plain arithmetic: weight-only modules hold the same tensors as W4A4 ones, the deserialization is the same, and only the forward differs. - Only one NVFP4 dequantization, `dequantize_nvfp4`. - The local tensor-parallel flag is set when the modules are swapped again, the type checker told to ignore it. - Triple-quoted docstrings, the per-expert slice note next to its check, more blank lines. - The NVFP4 EP test is parameterized and requires torch; the docs list multi-device loading of pre-quantized checkpoints. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
What and why.
use_experts_implementationsets its layout flags as class attributes instead of writing them in__init__.A flag set by the class body or the instance wins. This lets one wrapper class serve the experts of many models
and set the flags per instance. Writing them in
__init__would overwrite those values. First user:FineGrainedExperts(Fine-grained block-scaled quantization: the shared machinery #49776).ExpertsInterface._load_time_onlynames the implementations chosen at load time only. Their weights take alayout the others cannot read. It holds
deepgemm_megamoe.set_experts_implementationchecks that set instead of main's hard-coded"deepgemm_megamoe"string.get_correct_experts_implementationreads it to know the name. Somodeling_utilsno longer importsfinegrained_fp8.HfQuantizer.update_parallel_planreplicates every 0-dim parameter a plan covers, e.g. the per-tensor FP8activation_scale, since a scalar has no axis to shard. It moves there from the legacy FP8 quantizer, as Arthurasked on Finegrained kernels: unified quantization kernels api (separate quantizers) #49015, so every quantizer gets it. The fine-grained quantizer is the second user (Fine-grained block-scaled quantization: the shared machinery #49776).
DtensorShardOperationtreats any list entry with fewer dims than its param as a per-expert slice. Main only didso for exactly one dim fewer, so per-expert 0-dim scales were kept on every rank. The quantized experts hit this
under expert parallelism (Fine-grained block-scaled quantization: the shared machinery #49776).
FP8Experts._impl_tp_layer_overrides.test_megamoe_takes_over_the_experts_ep_rulealready fails on main: it calls a removedupdate_tp_plan. It isfixed here because it tests the quantizer's
update_parallel_plan, which this PR changes.This PR keeps main's
_hf_quantized_needs_local_tpand leavestensor_parallel.pyunchanged, so it does not overlapwith #49527 or #49679.
Depends on. #49774.
How tested.
tests/integrations/test_moe.py,tests/tensor_parallel/test_tensor_parallel.py,tests/utils/test_distributed_sharding_utils.py, and main'stest_megamoe_takes_over_the_experts_ep_rule.The comments and docstrings that say why each change exists are there for readability. Feel free to ask for any of them to go if it's self-evident.
🤖 Generated with Claude Code