nemo_rl.models.generation.score_centering#
vLLM request preparation and sample extraction for score centering.
The current strategy collects the top-k head. Future strategies must keep request preparation, validation and extraction consistent, and return the same pair of sampler token IDs and their sampler logprobs. Staging consumes this tensor contract regardless of how the candidates were selected.
Module Contents#
Classes#
HTTP request fields used by the current top-k collection strategy. |
Functions#
Build request overrides for collecting score-centering candidates. |
|
Check that the HTTP request advertises the configured collection strategy. |
|
Extract sampler candidate IDs and logprobs from one vLLM completion. |
|
Vectorized |
Data#
API#
- nemo_rl.models.generation.score_centering.VLLM_LOGPROB_FLOOR#
None
- class nemo_rl.models.generation.score_centering.ScoreCenteringRequestOverrides#
Bases:
typing.TypedDictHTTP request fields used by the current top-k collection strategy.
Initialization
Initialize self. See help(type(self)) for accurate signature.
- logprobs: bool#
None
- top_logprobs: int#
None
- nemo_rl.models.generation.score_centering.build_score_centering_request_overrides(
- *,
- num_candidates: int,
Build request overrides for collecting score-centering candidates.
Gym applies these fields to each outgoing policy request. Extend this function together with validation and extraction for another selection strategy, keeping the HTTP request consistent with engine sampling.
- Parameters:
num_candidates – Number of sampler candidates to collect per token.
- Returns:
HTTP request overrides. Callers merge them with other request settings.
- nemo_rl.models.generation.score_centering.validate_score_centering_request(
- request: Any,
- *,
- num_candidates: int,
Check that the HTTP request advertises the configured collection strategy.
- Parameters:
request – Resolved OpenAI-compatible chat request on the vLLM worker.
num_candidates – Candidate count configured for capture.
- nemo_rl.models.generation.score_centering.extract_score_centering_samples(
- output: Any,
- *,
- num_candidates: int,
Extract sampler candidate IDs and logprobs from one vLLM completion.
The current strategy takes the lowest-ranked candidates from each engine logprob mapping, excluding an extra sampled token outside the top-k head. Candidate logprobs retain their original mass rather than being normalized over the selected set. Candidates the sampler filtered out (top-k, top-p) keep their
-infprocessed logprob.- Parameters:
output – One engine CompletionOutput, including per-position logprobs.
num_candidates – Number of sampler candidates to retain per position.
- Returns:
CPU
(sampler_ids, sampler_logprobs)tensors, both shaped[generated_len, num_candidates], with int32 IDs and float32 logprobs. Callers retain the existingsampler_topk_token_idsandsampler_topk_logprobstransport fields.
- nemo_rl.models.generation.score_centering.extract_flat_score_centering_samples(
- output: Any,
- *,
- num_candidates: int,
Vectorized
extract_score_centering_samplesfor vLLMFlatLogprobs.With flat logprobs vLLM stores
num_candidates + 1entries per generated position: the sampled token first, then the top-k head by rank (a sampled token inside the head appears twice). Reshaping the flat lists replaces the per-position dict walk and applies the same checks to whole tensors.- Parameters:
output – One engine CompletionOutput whose
logprobsis avllm.logprobs.FlatLogprobs.num_candidates – Number of sampler candidates to retain per position.
- Returns:
CPU
(sampler_ids, sampler_logprobs)tensors, both shaped[generated_len, num_candidates], with int32 IDs and float32 logprobs, matchingextract_score_centering_samples.