nemo_automodel.components.models.baichuan.model
nemo_automodel.components.models.baichuan.model
Native Baichuan2 model implementation for NeMo Automodel.
Adapted from the Baichuan2 remote-code model on HuggingFace with the following changes:
- Removed xformers / quantization / chat / streaming dependencies.
- Added
**kwargsto forward signatures so that extra batch keys (padding_mask,loss_mask, …) pass through without error. - Uses
HFCheckpointingMixinfor unified checkpointing. - Uses
torch.nn.functional.scaled_dot_product_attentiononly.
Example (YAML)::
model: target: nemo_automodel.NeMoAutoModelForCausalLM.from_pretrained pretrained_model_name_or_path: baichuan-inc/Baichuan2-7B-Chat
Module Contents
Classes
Functions
Data
API
Bases: Module
Bases: HFCheckpointingMixin, BaichuanPreTrainedModel, GenerationMixin
Run the backbone and project the kept positions to vocabulary logits.
Parameters:
Token IDs of shape [batch, sequence].
Optional Tensor of shape [batch, past + sequence], 1 at valid tokens and 0 at padding, or a per-query mask of shape [batch, sequence, sequence]; it is combined with the causal mask, and None masks no tokens.
Optional positions of shape [batch, sequence]; None numbers them from the cached length.
Optional cache, either a DynamicCache or one (key, value) pair per layer, each of
shape [batch, heads, past, head_dim].
Optional embeddings of shape [batch, sequence, hidden] used instead of input_ids.
Optional target IDs of shape [batch, sequence] for the shifted next-token cross-entropy, which
ignores -100; config.z_loss_weight, when set, adds that weight times the mean squared max logit.
Whether to return the updated cache; None reads config.use_cache.
Passed to the backbone, whose SDPA attention returns no weights.
Whether the output carries the final hidden states; None reads
config.output_hidden_states.
Whether to return CausalLMOutputWithPast instead of a tuple.
0 keeps every position, a positive int keeps the last N positions, and an integer
Tensor of shape [kept] keeps those positions.
Extra batch keys, such as padding_mask or packed-sequence metadata, which are ignored.
Returns: Union[Tuple, CausalLMOutputWithPast]
CausalLMOutputWithPast, or the matching tuple when return_dict is False. logits have shape
Bases: PreTrainedModel
Bases: Module
Bases: Module
Bases: Module
Project hidden states with the row-normalized head weight.
Training normalizes each vocabulary row of the weight to unit L2 norm on every call. The first eval call after training normalizes the stored weight in place, and later eval calls reuse it.
Parameters:
Tensor of shape […, hidden], for example [batch, kept, hidden].
Returns:
Logits of shape […, vocab], in logits_dtype when set and otherwise in the weight dtype, which
Bases: Module
Bases: Module