nemo_rl.modelopt.utils#
Lightweight quantization config resolver usable by both Megatron and vLLM workers.
Module Contents#
Functions#
Yield |
|
Yield name variants matched by ModelOpt real-quant ignore patterns. |
|
Return whether |
|
Build the HuggingFace quantization_config consumed by vLLM ModelOpt NVFP4. |
|
Resolve a quantization config string into a dict consumable by |
Data#
API#
- nemo_rl.modelopt.utils._QUANT_IGNORE_NAME_SUFFIXES#
(‘.weight’, ‘.weight_scale’, ‘.weight_scale_2’)
- nemo_rl.modelopt.utils.DEFAULT_NVFP4_IGNORE#
[‘lm_head’, ‘output_layer’, ‘*mlp.gate’, ‘router’, ‘block_sparse_moe.gate’, ‘self_attention’…
- nemo_rl.modelopt.utils._iter_quant_ignore_suffix_variants(name: str) Iterator[str][source]#
Yield
nameand, if it ends in a known quant suffix, the stripped form.
- nemo_rl.modelopt.utils.iter_quant_ignore_name_candidates(name: str) Iterator[str][source]#
Yield name variants matched by ModelOpt real-quant ignore patterns.
- nemo_rl.modelopt.utils.matches_quant_ignore_pattern(name: str, patterns: list[str]) bool[source]#
Return whether
namematches any ModelOpt real-quant ignore pattern.
- nemo_rl.modelopt.utils.build_vllm_modelopt_nvfp4_config(
- *,
- ignore: list[str] | None = None,
Build the HuggingFace quantization_config consumed by vLLM ModelOpt NVFP4.
NeMo-RL’s
quant_cfgrecipes are ModelOpt PTQ/QAT configs consumed bymtq.quantize. vLLM expects the deployment/export-sidequantization_configshape instead.
- nemo_rl.modelopt.utils.resolve_quant_cfg(quant_cfg: str) dict[str, Any][source]#
Resolve a quantization config string into a dict consumable by
mtq.quantize.Resolution order:
Built-in ModelOpt config constant exposed on
modelopt.torch.quantization(e.g."NVFP4_DEFAULT_CFG","FP8_DEFAULT_CFG").A ModelOpt PTQ recipe — either the name of a built-in recipe shipped under
modelopt_recipes/(e.g."general/ptq/nvfp4_default-fp8_kv"; the.yml/.yamlsuffix is optional) or the path to a user-authored YAML recipe. Resolution is performed bymodelopt.recipe.load_config, which searches the filesystem first and then the built-in recipe library. For Ray/container workers, use an absolute path for user-authored recipe files; NeMo-RL repo-relative recipe paths are not resolved here.
YAML recipes are expected to follow the standard ModelOpt PTQ recipe layout with a top-level
quantize:section in the{"quant_cfg": [...], "algorithm": ...}shape thatmtq.quantizeexpects. A bare{"quant_cfg": [...], "algorithm": ...}document (without a wrappingquantize:key) is also accepted for convenience. Ifalgorithmis omitted, it defaults to"max"so ModelOpt’s calibration helpers see the same normalized config asmtq.quantize. The extracted dict — not the full recipe — is returned.See
modelopt_recipes/general/ptq/in the NVIDIA/Model-Optimizer repo (https://github.com/NVIDIA/Model-Optimizer) for the canonical format andexamples/modelopt/quant_configs/for a user-authored example.