nemo_rl.models.generation.vllm.utils#
Module Contents#
Functions#
Reject pure-config combinations unsupported by vLLM reload refit. |
|
Return whether a checkpoint key is a grouped MoE expert slab. |
|
Reject grouped MoE MXFP8 state-dict params before refit starts. |
|
Convert backend routed-expert ids to the resolved carry dtype. |
|
Reject rollouts generated from a different prompt than the learner’s. |
|
Format a list of prompts for vllm generation (which requires a specific format for its own |
|
Return full-sequence-aligned routed experts as |
|
Attach aligned routed experts to OpenAI chat response choices. |
|
Attach engine-native token information to OpenAI chat response choices. |
|
Dump a vLLM OpenAI chat response while preserving dynamic message fields. |
|
Encode a histogram component or a label into a flat counter key. |
|
Whether a snapshot key belongs to a family the driver consumes. |
|
Aggregate vLLM engine counters from multiple workers. |
|
Return the delta for the first candidate name present, else |
|
Mean of a histogram over the step, from its |
|
Compute per-step vLLM engine token, sequence-length and outcome metrics. |
|
Compute delta and derived metrics for speculative decoding. |
|
Return the quantized vLLM generation worker FQN if |
Data#
API#
- nemo_rl.models.generation.vllm.utils.R3_MISSING_ROUTE_SENTINEL#
None
- nemo_rl.models.generation.vllm.utils.VLLM_LOGPROB_FLOOR#
None
- nemo_rl.models.generation.vllm.utils.G_ROUTED_EXPERTS_RANGE_CHECKED#
False
- nemo_rl.models.generation.vllm.utils.GROUPED_MOE_MXFP8_REFIT_ERROR#
‘MXFP8 refit does not support grouped MoE expert weights.’
- nemo_rl.models.generation.vllm.utils._GROUPED_MOE_EXPERT_WEIGHT_SUFFIXES#
(‘mlp.experts.gate_up_proj’, ‘mlp.experts.down_proj’)
- nemo_rl.models.generation.vllm.utils.assert_reload_refit_config_supported( ) None#
Reject pure-config combinations unsupported by vLLM reload refit.
- nemo_rl.models.generation.vllm.utils.is_grouped_moe_expert_weight_name(name: str) bool#
Return whether a checkpoint key is a grouped MoE expert slab.
- nemo_rl.models.generation.vllm.utils.assert_refit_unsupported_grouped_moe_params(
- config: nemo_rl.models.generation.vllm.config.VllmConfig,
- state_dict_info: dict[str, Any],
Reject grouped MoE MXFP8 state-dict params before refit starts.
- nemo_rl.models.generation.vllm.utils._as_routed_experts_tensor(
- value: Any,
- *,
- device: torch.device,
- dtype: torch.dtype,
Convert backend routed-expert ids to the resolved carry dtype.
Guards against expert ids overflowing
dtypebefore the narrowing cast, which would otherwise wrap silently (e.g. if the expert count was mis-detected when resolving the dtype).
- nemo_rl.models.generation.vllm.utils.validate_rollout_prompt(
- expected: list[int],
- actual: list[int] | None,
Reject rollouts generated from a different prompt than the learner’s.
- nemo_rl.models.generation.vllm.utils.format_prompt_for_vllm_generation(
- data: nemo_rl.distributed.batched_data_dict.BatchedDataDict[nemo_rl.models.generation.interfaces.GenerationDatumSpec],
- sample_idx: Optional[int] = None,
Format a list of prompts for vllm generation (which requires a specific format for its own
generatemethod).See https://docs.vllm.ai/en/v0.9.1/features/multimodal_inputs.html for prompt format for multimodal inputs.
- nemo_rl.models.generation.vllm.utils.pad_and_align_routed_expert_indices(
- request_output: Any,
- completion_output: Any,
- *,
- valid_length: int,
- padded_length: int,
- device: torch.device,
- require_complete_routed_experts: bool = False,
- allow_missing_routed_experts_fallback: bool = True,
- return_stats: bool = False,
- routed_experts_dtype: torch.dtype = ROUTED_EXPERTS_FALLBACK_DTYPE,
Return full-sequence-aligned routed experts as
[S, L, topk]inrouted_experts_dtype.
- nemo_rl.models.generation.vllm.utils.attach_routed_experts_to_chat_response_choices(
- response: Any,
- final_request_output: Any,
- *,
- device: torch.device,
- logger: Any = None,
- routed_experts_dtype: torch.dtype = ROUTED_EXPERTS_FALLBACK_DTYPE,
Attach aligned routed experts to OpenAI chat response choices.
- nemo_rl.models.generation.vllm.utils.attach_token_information_to_chat_response_choices(
- response: Any,
- final_request_output: Any,
Attach engine-native token information to OpenAI chat response choices.
- nemo_rl.models.generation.vllm.utils.model_dump_chat_response_with_dynamic_message_fields(
- response: Any,
Dump a vLLM OpenAI chat response while preserving dynamic message fields.
- nemo_rl.models.generation.vllm.utils.COUNTER_KEY_SEP#
‘|’
- nemo_rl.models.generation.vllm.utils.HISTOGRAM_SUM_PART#
‘sum’
- nemo_rl.models.generation.vllm.utils.HISTOGRAM_COUNT_PART#
‘count’
- nemo_rl.models.generation.vllm.utils._KEPT_COUNTER_NAMES: tuple[str, ...]#
None
- nemo_rl.models.generation.vllm.utils.encode_counter_key(name: str, part: str) str#
Encode a histogram component or a label into a flat counter key.
- nemo_rl.models.generation.vllm.utils._is_kept(metric_name: str) bool#
Whether a snapshot key belongs to a family the driver consumes.
- nemo_rl.models.generation.vllm.utils.aggregate_spec_decode_counters(
- worker_metrics: list[dict[str, float | list[float]]],
Aggregate vLLM engine counters from multiple workers.
Combines the metrics collected from DP leader workers into a single aggregated counter dictionary. Retains the spec-decode family and the engine series listed above; everything else in the snapshot is dropped.
- Parameters:
worker_metrics – List of metric dictionaries from each worker. Each dict maps metric names to float values or lists of floats (for per-position metrics).
- Returns:
Dictionary mapping metric names to their aggregated float values. Per-position metrics use (name, position) tuples as keys.
.. rubric:: Example
metrics_from_workers = policy_generation.get_metrics() counters = aggregate_spec_decode_counters(metrics_from_workers) print(counters.get(“vllm:spec_decode_num_drafts”, 0)) 1234.0
- nemo_rl.models.generation.vllm.utils._first_delta(
- delta: dict[str | tuple[str, int], float],
- candidates: tuple[str, ...],
- part: Optional[str] = None,
Return the delta for the first candidate name present, else
None.
- nemo_rl.models.generation.vllm.utils._mean_from_histogram(
- delta: dict[str | tuple[str, int], float],
- candidates: tuple[str, ...],
Mean of a histogram over the step, from its
sum/countdelta.Exact rather than bucket-interpolated: vLLM tracks both, so the mean needs no approximation.
Nonewhen the engine served no request in the step, which is a real state (a step spent entirely in training) and not a zero-length sequence.
- nemo_rl.models.generation.vllm.utils.compute_engine_step_metrics(
- start_counters: dict[str | tuple[str, int], float],
- end_counters: dict[str | tuple[str, int], float],
Compute per-step vLLM engine token, sequence-length and outcome metrics.
These are the engine’s own accounting, which is why they are worth carrying even though the driver already derives token counts from the tensors a
generate()call returns: sequence-length distributions and aborted requests leave no trace in the returned tensors at all.- Parameters:
start_counters – Counter snapshot taken before generation.
end_counters – Counter snapshot taken after generation.
- Returns:
Metrics for logging, keyed with a
vllm/prefix. Absent series are omitted rather than reported as zero, so a vLLM release that renames one leaves a gap in the dashboard instead of a plausible-looking zero.
- nemo_rl.models.generation.vllm.utils.compute_spec_decode_metrics(
- start_counters: dict[str | tuple[str, int], float],
- end_counters: dict[str | tuple[str, int], float],
Compute delta and derived metrics for speculative decoding.
Calculates the difference between two counter snapshots and derives acceptance rate and acceptance length metrics for logging.
- Parameters:
start_counters – Counter snapshot taken before generation.
end_counters – Counter snapshot taken after generation.
- Returns:
Dictionary of metrics suitable for logging to wandb/tensorboard. Keys are prefixed with “vllm/” for namespace consistency. Includes: - vllm/spec_num_drafts: Total number of draft batches - vllm/spec_num_draft_tokens: Total draft tokens generated - vllm/spec_num_accepted_tokens: Total tokens accepted - vllm/spec_acceptance_length: Average accepted tokens per draft + 1 - vllm/spec_acceptance_rate: Ratio of accepted to draft tokens - vllm/{metric}-{position}: Per-position acceptance counts - vllm/spec_acceptance_rate-pos-{position}: Per-position acceptance rates
- nemo_rl.models.generation.vllm.utils.GENERATION_WORKER_OVERRIDES#
None
- nemo_rl.models.generation.vllm.utils.resolve_generation_worker_cls(default_cls: str, config: dict) str#
Return the quantized vLLM generation worker FQN if
quant_cfgis set, elsedefault_cls.Safe to call even when ModelOpt is not installed — returns
default_clsunchanged wheneverquant_cfgisNone, so the core generation path stays import-free of ModelOpt.