nemo_rl.modelopt.models.generation.vllm_quant_backend#
Module Contents#
Classes#
ModelOpt worker extension with checkpoint-engine refit support. |
Functions#
Validate complete fused-MoE families and resolve their W13 layout. |
|
Map fused ModelOpt payloads to vLLM per-projection checkpoint names. |
|
Own deferred weights before a transport buffer may be reused. |
|
Return modules whose runtime layout is owned by vLLM ModelOpt methods. |
|
Select disjoint roots that require vLLM’s native reload lifecycle. |
|
Reject ModelOpt layers that vLLM would otherwise finalize partially. |
Data#
API#
- nemo_rl.modelopt.models.generation.vllm_quant_backend._FUSED_MODELOPT_MOE_SUFFIXES#
None
- nemo_rl.modelopt.models.generation.vllm_quant_backend._match_fused_modelopt_moe_weight(name: str) tuple[str, str] | None#
- nemo_rl.modelopt.models.generation.vllm_quant_backend._w13_num_shards_from_state_dict_info(
- state_dict_info: dict[str, Any],
- *,
- require_input_scales: bool = False,
Validate complete fused-MoE families and resolve their W13 layout.
- nemo_rl.modelopt.models.generation.vllm_quant_backend._batch_fused_modelopt_moe_weights(
- weights: list[tuple[str, torch.Tensor]],
- *,
- w13_num_shards_by_prefix: dict[str, int],
Map fused ModelOpt payloads to vLLM per-projection checkpoint names.
w2weights and block scales stay batched so vLLM can tensor-parallel-shard the full[E, ...]tensor at once. Its scalar loader still requires an expert id, so only the tiny per-expert global scales are exposed as scalar views.Gated
w13payloads are the exception on vLLM >= 0.25: they are emitted as per-expert 2-D shards instead, becauseRoutedExperts.load_weights’ fused-3D branch mis-transposes packed NVFP4. See the comment at the emission site below.
- nemo_rl.modelopt.models.generation.vllm_quant_backend._detach_pending_layerwise_weights(
- reload_roots: tuple[torch.nn.Module, ...],
- source_storage_ptrs: set[int],
Own deferred weights before a transport buffer may be reused.
Completed layers have already released their buffered arguments, so this clones only tensors from a layer split across transport batches. Only the cached layerwise-reload subgraphs are inspected.
- nemo_rl.modelopt.models.generation.vllm_quant_backend._iter_modelopt_quant_modules(
- model: torch.nn.Module,
Return modules whose runtime layout is owned by vLLM ModelOpt methods.
- nemo_rl.modelopt.models.generation.vllm_quant_backend._modelopt_layerwise_reload_roots(
- model: torch.nn.Module,
- *,
- include_fp8_kv_cache: bool,
Select disjoint roots that require vLLM’s native reload lifecycle.
Ordinary parameters are already updated in place by vLLM’s checkpoint loaders. Restricting layerwise reconstruction to ModelOpt runtime layouts and attention scale owners avoids materializing unrelated non-persistent buffers. In vLLM 0.20, whole-model reconstruction can otherwise break a derived buffer that aliases a child parameter (for example Nemotron-H’s
conv_weightsview ofconv1d.weight).
- nemo_rl.modelopt.models.generation.vllm_quant_backend._require_complete_modelopt_layerwise_reload(
- model: torch.nn.Module,
Reject ModelOpt layers that vLLM would otherwise finalize partially.
- class nemo_rl.modelopt.models.generation.vllm_quant_backend.VllmQuantInternalWorkerExtension#
Bases:
nemo_rl.models.generation.vllm.vllm_backend.VllmInternalWorkerExtension- _nrl_w13_num_shards_by_prefix: dict[str, int]#
None
- _nrl_modelopt_reload_roots: tuple[torch.nn.Module, ...] | None#
None
- maybe_init_zmq() None#
Use a longer timeout only for ModelOpt real-quant refits.
- _is_real_quant_model() bool#
- _get_modelopt_reload_roots() tuple[torch.nn.Module, ...]#
Return the invariant ModelOpt layerwise-reload subgraphs.
- _weight_update_lifecycle( ) collections.abc.Iterator[nemo_rl.models.generation.vllm.vllm_backend.WeightUpdateFinalizer]#
Use vLLM’s native layerwise reload lifecycle for real quantization.
- _weight_update_errors_are_fatal() bool#
- _synchronize_before_ipc_data_ack() None#
Fence all accelerator streams used by ModelOpt post-load methods.
- prepare_refit_info(state_dict_info: dict[str, Any]) None#
- _patch_named_parameters_to_include_buffers(model)#
Temporarily patches model.named_parameters() to also yield input_quantizer buffers.
Weights arrive pre-folded from the Megatron side, so only input_quantizer amax buffers need to be loaded. Weight quantizer buffers are skipped.
- _attach_input_quantizer_amax_loaders(model)#
Eagerly attach weight_loaders to input_quantizer amax buffers.
vLLM >= 0.25 loads refit weights through per-module
load_weights(e.g.LinearBase.load_weights), which resolves targets viagetattrand callsparam.weight_loader(param, loaded_weight, shard_id)directly — it never iteratesmodel.named_parameters(), so the lazy attach in_patch_named_parameters_to_include_buffersno longer fires and quantizer amax buffers arrive without a loader (AttributeError: ‘Tensor’ object has no attribute ‘weight_loader’).
- _load_weights(weights)#
Load pre-folded weights and input_quantizer amax buffers.
Weights arrive already folded from the Megatron side (weight_quantizer applied during export), so no fold_weight step is needed here.
- get_weight_snapshot(name: str) torch.Tensor#
Return a CPU copy of a named parameter for before/after comparison.
- get_quantizer_stats() dict#
Return summary statistics for all TensorQuantizer modules.
Matches the interface of MegatronQuantPolicyWorker.get_quantizer_stats().
- class nemo_rl.modelopt.models.generation.vllm_quant_backend.VllmQuantInternalWorkerExtensionWithCheckpointEngine#
Bases:
nemo_rl.models.generation.vllm.checkpoint_engine.VllmCheckpointEngineMixin,nemo_rl.modelopt.models.generation.vllm_quant_backend.VllmQuantInternalWorkerExtensionModelOpt worker extension with checkpoint-engine refit support.