nemo_automodel.components.models.kimi_k3.vision
nemo_automodel.components.models.kimi_k3.vision
Module Contents
Classes
Functions
Data
API
Bases: Module
Bases: Module
Bases: Module
Bases: Module
Parameters:
[in_dim, hidden_dim, out_dim]
whether to use bias in linear layer.
Bases: Module
Bases: PreTrainedModel
Parameters:
The input pixel values.
Temporal, height and width.
Returns: torch.Tensor
torch.Tensor: The output tokens.
Bases: Module
Parameters:
(batch_size, seqlen, hidden_dim)
Bases: Module
Parameters:
input tensor
temporal, height and width
Returns: torch.Tensor
(L, Cout) tensor
Bases: Module
Bases: Module
Bases: Module
2D rotary position embedding with multi-resolution support.
This class is intended to be used in the following way:
- Before training, create an instance of Rope2DPosEmb. This instance will hold the precomputed cis.
- Before each forward pass, call
get_freqs_cis_by_*to get thefreqs_cistensor for this iteration. - During the forward pass, pass the
freqs_cistensor to each attention layer, and callapplyjust before each attention operation. The rope is shared across all attention layers and all heads.
Refs:
- RoFormer: https://arxiv.org/abs/2104.09864
- VisionLLaMA: https://arxiv.org/abs/2403.00522
- https://github.com/Meituan-AutoML/VisionLLaMA/blob/main/dit/models.py
Parameters:
usually the multi-head attention dimension, should be divisible by 4 (TODO: relax this constraint if needed)
the maximum height of the 2D grid
the maximum width of the 2D grid
the base of the theta
the device to store the precomputed cis
Calculate the cis(freqs) for each position in the 2D grid.
Parameters:
grid time, height and width
Returns: torch.Tensor
tensor of shape (sum(t * height * width), dim//2)
Returns: xq_out, xk_out: tensors of shape (…, num_heads, head_dim)
Parameters:
query, tensor of shape (…, num_heads, head_dim)
key, tensor of shape (…, num_heads, head_dim)
tensor of shape (…, head_dim/2), dtype=torch.complex64. It contains the precomputed cis(freqs) for each position in the 2D grid.
t_size: int of the temporal size return: pos_embed: [t_size, embed_dim] or [1+t_size, embed_dim] (w/ or w/o cls_token)
From: https://github.com/OpenGVLab/InternVideo/blob/421f6d2361fc8f61a3394244571f2601a4e99e29/InternVideo2/multi_modality/models/backbones/internvideo2/pos_embed.py#L86 embed_dim: output dimension for each position pos: a list of positions to be encoded: size (M,) out: (M, D)
Multi-head attention using flash attention 2.
Parameters:
tensor of shape (batch_size, seqlen, num_heads, head_dim), or (tot_seqlens, num_heads, head_dim) if packing.
cumulative sequence lengths of q. The first element should be 0 and the last element should be q.shape[0].
cumulative sequence lengths of k. The first element should be 0 and the last element should be k.shape[0].
Returns:
shape (batch_size, seqlen, dim) or (tot_seqlens, dim) if packing, where dim = num_heads * head_dim