nemo_automodel.components.models.clef.joint_schema_head
nemo_automodel.components.models.clef.joint_schema_head
Clef joint schema head and record encoding.
Adapted from Cloudflare, Inc.’s Apache-2.0 joint_schema_model.py:
https://huggingface.co/Cloudflare/clef/blob/ed3eed331870db2eff4b0db01237128ede8a00ce/joint_schema_model.py
The publisher’s license is https://huggingface.co/Cloudflare/clef/blob/ed3eed331870db2eff4b0db01237128ede8a00ce/LICENSE.
Parameter names remain unchanged. NeMo adaptations add typed configuration, tensor validation,
a callable lexical-row table for sharded backbones, and fp32 head training.
Clef turns a state and a schema of typed questions into one logit per allowed option per question, in a single
forward pass of a Qwen3.5-architecture backbone followed by this small transformer head.
Module Contents
Classes
Functions
Data
API
Declarative configuration matching joint_head_config.json.
Parameters:
Backbone hidden-state and output-embedding width.
Internal decision-head width.
Number of option-to-evidence cross-attention blocks.
Number of joint field decoder blocks.
Attention head count.
Feed-forward width in attention blocks.
Dropout probability used while post-training the head.
Build a checkpoint-compatible joint schema head.
Returns: JointSchemaHead
Newly initialized CLEF decision head.
Token spans of one question and its options inside an encoded record (end-exclusive).
A tokenised record: input ids, per-question spans, and optional media tensors.
Bases: Module
Route state evidence into per-option queries.
Cross-attend option queries to the encoded record.
Parameters:
Tensor of shape [batch, options, width].
Tensor of shape [batch, sequence, width].
Returns: torch.Tensor
Tensor of shape [batch, options, width].
Bases: Module
Cloudflare CLEF joint head over one or more typed questions.
Mean-pool a non-empty token span.
Parameters:
Tensor of shape [sequence, hidden].
Half-open (start, end) token interval.
Returns: torch.Tensor
Tensor of shape [hidden].
Produce one variable-length option-logit tensor per question.
Parameters:
Tensor of shape [batch, sequence, hidden].
Tensor of shape [batch, sequence].
Tensor of shape [batch, sequence], with one for real tokens.
Batch-aligned token-span metadata.
Tensor of shape [vocab, hidden], or a callable mapping long token IDs [tokens] to rows [tokens, hidden].
Returns: list[list[torch.Tensor]]
Nested batch/question list. Each Tensor has shape [options].
Run CLEF’s backbone-to-head composition through the public hidden-state interface.
Parameters:
Language model returning hidden states of shape [batch, sequence, hidden].
Publisher-ordered token spans. Optional media contains pixel_values of shape [patches, features], pixel_values_videos of shape [video_patches, features], and image/video_grid_thw of shape [items, 3] (temporal, height, width).
Frozen token-row lookup returning tensors of shape [tokens, hidden].
Token used for right padding.
Execution device for collated input tensors.
Returns: list[list[torch.Tensor]]
Batch/question lists of fp32 logit tensors of shape [options].
Bases: Module
Frozen cache of the output-embedding rows the head needs, indexed by token id.
The released head reads lm_head.weight[token_ids] for option tokens. When the LM head is sharded we gather
the full weight once to select these rows (they never change, the LM head is frozen),
then retain only the selected rows in this table.
Look up LM-head rows.
Parameters:
Long tensor of shape [tokens].
Returns: torch.Tensor
Tensor of shape [tokens, hidden] on token_ids.device.
Cache the frozen output-embedding rows consumed by the CLEF readout.
All model-parallel ranks must participate when the output weights are sharded.
Parameters:
Backbone exposing output embeddings of shape [vocabulary, hidden].
Encoded records whose option spans determine the cached token rows.
Returns: 'LexicalTable'
Frozen table of shape [unique_option_tokens, hidden] on the embedding device.
Raises:
ValueError: If the output embeddings are trainable or no option tokens exist.
{question_id: option ids} in the order the Clef head returns logits.
Right-pad encoded records into a batch.
Parameters:
Batch-aligned token spans. Optional media contains pixel_values of shape [patches, patch_features], where patch_features flattens each pixel patch; image_grid_thw of shape [images, 3] (temporal, height, width patch counts); pixel_values_videos and video_grid_thw with corresponding video layouts; and mm_token_type_ids, a list of media-token types starting at token_offset.
Token used to fill right-padded positions.
Device for input IDs, attention masks, and media token-type tensors.
Returns: dict[str, Any]
Mapping with input_ids and attention_mask, long Tensors of shape [batch, sequence]
Tokenise a SystemOne record into Clef’s prompt layout and record question / option token spans.
The state is truncated (never the schema) so the prompt fits in max_length tokens.
Build a JointSchemaHead from a directory with joint_head_config.json / joint_head.safetensors.
path may also be a Hugging Face repo id (e.g. "Cloudflare/clef"); only the head files are downloaded.
Sorted unique token ids inside option spans (the only output-embedding rows the head reads).
(option id, description) pairs in Clef order: noul [true, false], choice sorted, score by level.
Render a state / instruction value as text (strings verbatim, everything else as compact sorted JSON).
Save a head in the release layout (joint_head_config.json + joint_head.safetensors).