nemo_automodel.components.models.biencoder.biencoder_model#
Module Contents#
Classes#
NeMo AutoModel Biencoder with custom kernel support. |
Data#
API#
- nemo_automodel.components.models.biencoder.biencoder_model.logger#
βgetLogger(β¦)β
- class nemo_automodel.components.models.biencoder.biencoder_model.NeMoAutoModelBiencoder#
Bases:
nemo_automodel._transformers.auto_model._BaseNeMoAutoModelClassNeMo AutoModel Biencoder with custom kernel support.
This class extends _BaseNeMoAutoModelClass to provide biencoder functionality with NeMo AutoModel architecture, including support for Liger kernels and SDPA patching optimizations. The parent class handles all kernel patching (_patch_liger_kernel, _patch_attention), while this class only customizes the model initialization to use BiencoderModel.
- classmethod from_pretrained(
- pretrained_model_name_or_path,
- share_encoder=True,
- add_linear_pooler=False,
- out_dimension=None,
- do_gradient_checkpointing=False,
- train_n_passages: int = 1,
- eval_negative_size: int = 0,
- pooling: str = 'avg',
- l2_normalize: bool = True,
- t: float = 1.0,
- use_liger_kernel: bool = True,
- use_sdpa_patching: bool = True,
- sdpa_method: Optional[List[torch.nn.attention.SDPBackend]] = None,
- **kwargs,
Load a biencoder model from pretrained weights.
This method uses BiencoderModel.build to initialize the model, then applies kernel patching from the parent class (_patch_liger_kernel, _patch_attention). If patching fails, the method retries with adjusted parameters.
- Parameters:
pretrained_model_name_or_path β Path to pretrained model or model identifier
share_encoder β Whether to share encoder weights between query and passage
add_linear_pooler β Whether to add a linear pooler layer
out_dimension β Output dimension for linear pooler
do_gradient_checkpointing β Whether to enable gradient checkpointing
train_n_passages β Number of passages per query during training
eval_negative_size β Number of negative samples during evaluation
pooling β Pooling strategy (βavgβ, βclsβ, βlastβ, etc.)
l2_normalize β Whether to L2 normalize embeddings
t β Temperature for scaling similarity scores
use_liger_kernel β Whether to apply Liger kernel optimizations
use_sdpa_patching β Whether to apply SDPA patching
sdpa_method β SDPA backend methods to use
**kwargs β Additional arguments passed to BiencoderModel.build
- Returns:
BiencoderModel instance with loaded and patched weights
.. rubric:: Notes
If kernel patching fails, the partially constructed model is deleted and the method recurses once with use_liger_kernel=False or use_sdpa_patching=False