nemo_automodel.components.models.llama.model
nemo_automodel.components.models.llama.model
Custom Llama model implementation for NeMo Automodel.
This module provides a self-contained Llama implementation following HuggingFace’s implementation. Uses separate q_proj/k_proj/v_proj and gate_proj/up_proj (HF-style).
Example (YAML):
Module Contents
Classes
Data
API
Bases: Module
Multi-headed attention from ‘Attention Is All You Need’ paper.
Uses separate q_proj / k_proj / v_proj — identical to the default HuggingFace Llama implementation.
Run dense attention over padded BSHD or packed THD hidden states.
Parameters:
Hidden states [B, S, H] or packed local states
[T, H]. B is batch, S is sequence, T is local
total tokens, and H is hidden size.
RoPE tensors (cos, sin) for SDPA/eager or
(cos, sin, freqs_cis) for fused TE RoPE. Local cosine/sine
tensors follow [B, S, D] or [T, D]; freqs_cis is
global [S, 1, 1, D].
Padded attention mask for BSHD. THD requires
None and uses cumulative document lengths from kwargs.
Optional KV cache for BSHD generation. THD training does not support a cache.
Optional BSHD cache positions [S].
THD requires qkv_format='thd' and cu_seqlens
[N + 1]; CP additionally supplies cp_size and cp_rank.
Returns: torch.Tensor
Attention output shaped like hidden_states and optional BSHD
Bases: GradientCheckpointingLayer
Single Llama decoder layer with RMSNorm, attention, and MLP.
Inherits from GradientCheckpointingLayer for efficient activation checkpointing.
Bases: HFCheckpointingMixin, LlamaPreTrainedModel
Llama model with causal language modeling head.
Forward pass returning CausalLMOutputWithPast.
Parameters:
Token IDs [B, S] or packed local IDs [T].
Optional padded attention mask. THD uses document
boundaries from kwargs instead.
Position IDs [B, S] or packed local IDs [T].
Optional BSHD KV cache; unsupported for THD.
Optional hidden inputs [B, S, H] or [T, H].
Optional labels [B, S] or packed [T].
Whether to update the BSHD KV cache.
Whether to request attention outputs.
Whether to return per-layer hidden states.
Whether to return CausalLMOutputWithPast.
Optional BSHD cache positions [S].
Positions to project from hidden size H to
vocabulary size V.
THD metadata. cu_seqlens is [N + 1] and identifies
packed-document boundaries; CP adds cp_size and cp_rank.
Returns: CausalLMOutputWithPast
Causal LM output with logits [B, S, V]. Packed THD logits are
Bases: Module
SwiGLU MLP with separate gate_proj and up_proj — identical to HuggingFace default.
Bases: LlamaPreTrainedModel
Llama transformer model (embeddings + decoder layers + norm).
Run the Llama decoder in padded BSHD or packed THD layout.
Parameters:
Token IDs [B, S] or packed local IDs [T].
Optional padded mask [B, S] or broadcastable
causal mask. THD ignores this mask and uses cu_seqlens.
Position IDs [B, S] or packed local IDs [T].
Optional BSHD generation cache; unsupported for THD.
Alternative hidden inputs [B, S, H] or [T, H].
Whether to update the BSHD KV cache.
Whether to request attention outputs.
Whether to retain per-layer hidden states.
Whether to return BaseModelOutputWithPast.
Optional BSHD cache positions [S].
THD metadata including qkv_format, cu_seqlens,
max_seqlen, cp_size, and cp_rank.
Returns: BaseModelOutputWithPast
Decoder output with final states [B, S, H] or packed local
Bases: PreTrainedModel
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.