nemo_automodel.components.models.clm
nemo_automodel.components.models.clm
Contrastive Language Model (CLM) decision heads (https://huggingface.co/Contrastive-LM/CLM-v0.1-8B).
Submodules
Package Contents
Classes
Functions
API
Declarative configuration for a CLM state/action head pair.
Parameters:
Width of each frozen backbone embedding.
Hidden width of each projection MLP.
Number of linear layers in each projection MLP; at least two.
Width of the normalized decision embedding.
One of "gelu", "relu", or "silu".
Apply LayerNorm before intermediate hidden layers.
Add residual connections around intermediate hidden layers.
Build the configured head pair.
Parameters:
Positive InfoNCE softmax temperature.
Returns: CLMHeadPair
Trainable CLM state/action projection heads.
Bases: Module
Published CLM state and action projections plus learned temperature.
Return the scalar inverse temperature, capped at the released value 100.
Validate the encoder width without modifying its embeddings.
Parameters:
Tensor of shape [rows, hidden], with hidden equal to config.hidden_size.
Input name used in validation errors.
Score every state against every candidate action.
Parameters:
Tensor of shape [batch, hidden].
Tensor of shape [candidates, hidden].
Returns: torch.Tensor
Tensor of shape [batch, candidates] containing scaled cosine logits.
Load the official Contrastive-LM .pt head checkpoint.
Parameters:
Local CLM_v0.1-8B.pt-compatible checkpoint path.
Returns: CLMHeadPair
Head pair with the published state, action, and temperature tensors.
Project and normalize action embeddings.
Parameters:
Tensor of shape [candidates, hidden].
Returns: torch.Tensor
Tensor of shape [candidates, projection].
Project and normalize state embeddings.
Parameters:
Tensor of shape [batch, hidden].
Returns: torch.Tensor
Tensor of shape [batch, projection].
Score ragged question options in question-major order.
Parameters:
Tensor of shape [questions, hidden].
Tensor of shape [sum_options, hidden].
Positive option count for each question, summing to sum_options.
Returns: list[torch.Tensor]
Question-major tensors, each of shape [options].
Apply the decision-head temperature training policy before optimization.
Parameters:
Whether the scalar log inverse temperature receives gradients.
Text -> row lookup into a table of L2-normalised encoder embeddings.
Load a previously published cache using restricted tensor deserialization.
Return a tensor of shape [len(texts), hidden] (a copy, optionally moved to device).
Publish the cache atomically, preserving any prior cache on failure.
Load a CLM head checkpoint (defaults to the released CLM-v0.1-8B heads from the Hugging Face Hub).
Save heads in the contrastive-lm checkpoint format (loadable by clm-serve and load_clm_heads).