nemo_rl.modelopt.utils#

Lightweight quantization config resolver usable by both Megatron and vLLM workers.

Module Contents#

Functions#

_iter_quant_ignore_suffix_variants

Yield name and, if it ends in a known quant suffix, the stripped form.

iter_quant_ignore_name_candidates

Yield name variants matched by ModelOpt real-quant ignore patterns.

matches_quant_ignore_pattern

Return whether name matches any ModelOpt real-quant ignore pattern.

build_vllm_modelopt_nvfp4_config

Build the HuggingFace quantization_config consumed by vLLM ModelOpt NVFP4.

resolve_quant_cfg

Resolve a quantization config string into a dict consumable by mtq.quantize.

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 name and, 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 name matches any ModelOpt real-quant ignore pattern.

nemo_rl.modelopt.utils.build_vllm_modelopt_nvfp4_config(
*,
ignore: list[str] | None = None,
) dict[str, Any][source]#

Build the HuggingFace quantization_config consumed by vLLM ModelOpt NVFP4.

NeMo-RL’s quant_cfg recipes are ModelOpt PTQ/QAT configs consumed by mtq.quantize. vLLM expects the deployment/export-side quantization_config shape 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:

  1. Built-in ModelOpt config constant exposed on modelopt.torch.quantization (e.g. "NVFP4_DEFAULT_CFG", "FP8_DEFAULT_CFG").

  2. 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 / .yaml suffix is optional) or the path to a user-authored YAML recipe. Resolution is performed by modelopt.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 that mtq.quantize expects. A bare {"quant_cfg": [...], "algorithm": ...} document (without a wrapping quantize: key) is also accepted for convenience. If algorithm is omitted, it defaults to "max" so ModelOpt’s calibration helpers see the same normalized config as mtq.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 and examples/modelopt/quant_configs/ for a user-authored example.