protomotions.agents.common.autoregressive module#
Common autoregressive modules for categorical token sequences.
- protomotions.agents.common.autoregressive.sampling_log_probs(logits, p=0.9, temperature=1.0)[source]#
Log-probabilities of the actual temperature/top-p sampling distribution.
- protomotions.agents.common.autoregressive.prior_constrained_sampling_log_probs(
- logits,
- prior_logits,
- p=0.99,
- temperature=1.0,
- overlap_threshold=0.001,
Log-probs after constraining model support to the prior top-p nucleus.
- protomotions.agents.common.autoregressive.nucleus_sampling(logits, p=0.9, temperature=1.0)[source]#
Sample categorical indices from the top-p nucleus.
- protomotions.agents.common.autoregressive.nucleus_sampling_prior_constraint(
- logits,
- prior_logits,
- p=0.99,
- temperature=1.0,
- overlap_threshold=0.001,
Sample from logits while restricting support to the prior top-p nucleus.
If the model assigns effectively no probability mass to the prior nucleus, sample from the prior nucleus instead of falling back to unconstrained model probabilities. That keeps prior-constraint mode active after policy drift.
- protomotions.agents.common.autoregressive.kl_divergence_categorical(logits, prior_logits, reduction='mean')[source]#
KL divergence between categorical distributions parameterized by logits.
- protomotions.agents.common.autoregressive.kl_divergence_from_log_probs(log_p, log_q, reduction='mean')[source]#
KL divergence for already transformed categorical log-probabilities.
- protomotions.agents.common.autoregressive.kl_divergence_sampling_distribution(
- logits,
- prior_logits,
- *,
- p=0.9,
- temperature=1.0,
- prior_constraint=False,
- reduction='mean',
KL between the actual transformed token sampling distributions.
- protomotions.agents.common.autoregressive.generate_causal_mask(num_target, num_context=0, device=None)[source]#
Build a float causal attention mask with an optional context prefix.
- protomotions.agents.common.autoregressive.resolve_discrete_autoregressive_config(
- config,
- *,
- num_tokens,
- vocab_size,
Return a copy of
configwith token count and vocabulary resolved.
- class protomotions.agents.common.autoregressive.DiscreteAutoregressiveTransformer(*args, **kwargs)[source]#
Bases:
ProtoMotionsTensorDictModuleCategorical autoregressive transformer with configurable projections.
- muon_adam_fallback_modules()[source]#
Categorical input/output projections should use the auxiliary Adam path.
- compute_model_loss(
- tensordict,
- current_epoch,
- zero_loss,
- log_prefix='model',
Optional module-owned auxiliary loss for agent optimization loops.
Most modules do not own an auxiliary loss. Models that do, such as a VAE-backed policy head, override this and return
(loss, log_dict).
- forward_from_tokens(
- context,
- tokens,
- *,
- transformer=None,
- pos_emb=None,
- transformer_kwargs=None,
- forward(tensordict)[source]#
Run teacher forcing when tokens are supplied, otherwise generate tokens.