nemo_automodel.components.loss.decision
nemo_automodel.components.loss.decision
Post-training objectives for decision models (per-question distributions over a finite option set).
Every question of every record is one decision: the model emits one logit per allowed option and the answer
distribution is a softmax over them. Questions have different numbers of options, so a batch is represented as a
padded [questions, options] logit matrix plus a boolean option mask, where questions counts every question of
every record in the batch and options is the largest option count among them.
The configured decision objective supports two stages:
-
SFT - label-smoothed cross-entropy on the gold option, plus a Brier term (calibration) and a ranked-probability score (squared EMD) for ordinal
scorequestions. The optional ranked-probability term applies only to ordinal questions. -
RL - the decision is a one-step contextual bandit, so the policy gradient can be computed two ways:
expected_reward: maximiseE_{a~pi}[r(a)] = sum_a pi(a) r(a)exactly. With a finite option set this is the exact policy gradient without option-sampling variancesum_a pi(a) (r(a) - E[r]) grad log pi(a).grpo: samplenum_samplesoptions per question, use the group-mean (optionally std-normalised) reward as the baseline and apply a grouped REINFORCE surrogate for single-step decisions.
Both add a KL penalty to a frozen reference policy (normally the SFT model) and an optional proper-scoring anchor (log score of the gold option). These objectives do not guarantee calibration.
The same module owns the tutorial-specific group-masked bidirectional InfoNCE objective and experimental Gaussian-proposal RLCR continuation.
Module Contents
Classes
Functions
Data
API
Bases: Module
Decision objective; construct it with DecisionLossConfig.build.
Return per-question objective weights.
Parameters:
Supervision tensors with layouts documented by DecisionTargets.
Returns: torch.Tensor
Tensor of shape [questions], zero where required feedback is unavailable.
Per-option rewards.
Parameters:
Supervision tensors.
Float tensor of shape [questions, options] with the gold option one-hot (fallback reward).
Returns: torch.Tensor
Float tensor of shape [questions, options].
Compute the configured objective.
Parameters:
Tensor of shape [questions, options]; padding entries (targets.option_mask False) are ignored.
Supervision tensors (see DecisionTargets) on the same device as logits.
Optional RNG for GRPO sampling.
Returns: torch.Tensor
(loss, metrics): loss is a scalar weighted mean over questions; metrics maps names to detached
Return the denominator for composing microbatch or data-parallel losses.
Parameters:
Supervision tensors with layouts documented by DecisionTargets.
Returns: torch.Tensor
Scalar tensor containing the sum of eligible per-question weights. A
Hyper-parameters of the decision objectives (see the module docstring).
Weight of the supervised gold-option log-score anchor during RL.
SFT weight of the Brier score.
Weight of KL(pi || pi_ref) (needs reference log-probabilities).
SFT label smoothing over the valid options of each question.
"sft" for supervised fine-tuning or "rl" for reward-driven post-training.
Divide GRPO advantages by the group reward std.
GRPO samples per question.
SFT weight of the ranked probability score on score questions.
Optional {question_id: weight}.
"expected_reward" (exact policy gradient) or "grpo" (sampled, group baseline).
GRPO sampling temperature.
Return the loss module for this configuration.
Scalar loss terms from calibration-aware policy continuation.
Reduce eligible per-question values without inventing a zero-weight loss.
Parameters:
Tensor of shape [questions].
Tensor of shape [questions], zero where supervision is absent.
Returns: torch.Tensor
Scalar tensor; a zero-weight batch stays connected to the input graph.
Compute the CLM bidirectional in-batch InfoNCE objective.
Parameters:
Tensor of shape [batch, projection].
Tensor of shape [batch, projection] with row-aligned positives.
Scalar Tensor storing the log inverse temperature.
Optional Tensor of shape [batch]. Off-diagonal rows with the same ID are false negatives and masked.
Returns: torch.Tensor
Scalar Tensor containing the mean of state-to-action and action-to-state cross-entropy.
Log-softmax over valid options.
Parameters:
Tensor of shape [questions, options]; padding entries may hold any value (including -inf).
Bool tensor of shape [questions, options]; True marks a real option.
Returns: torch.Tensor
Float32 tensor of shape [questions, options]. Padding entries are exactly 0 (not -inf) so that products
Apply JevAny-style RLCR to closed-set decision logits.
This is an experimental adaptation, not an upstream CLEF or CLM recipe. It samples Gaussian logit proposals, uses correctness minus squared confidence error as reward, subtracts a per-example group baseline, and retains a supervised cross-entropy anchor.
Parameters:
Tensor of shape [batch, options].
Tensor of shape [batch] with zero-based correct option indices.
Number of perturbed proposals sampled for each decision.
Positive Gaussian standard deviation in logit space.
Multiplier for the score-function policy term.
Multiplier for the cross-entropy anchor.
Optional random generator controlling proposal sampling.
Returns: RLCRLossOutput
Named scalar loss terms. Every Tensor has shape [].