Quantization plan fixes: bitsandbytes loading, NVFP4 parallelism and 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>