Llama3VisionProjectionHead¶
- class torchtune.models.llama3_2_vision.Llama3VisionProjectionHead(layers: Module, output: Module, num_hidden_inputs: int = 0)[来源]¶
投影 transformer,用于将预训练的冻结编码器 (CLIP) 的输出适配到预训练的解码器模型。例如,nn.Sequential(CLIP(), Llama3VisionProjectionHead())。
- 参数:
layers (nn.Module) – Transformer 解码器层
output (nn.Module) – 输出线性层。输入维度为 (num_hidden + 1) * encoder_dim,输出为 decoder_dim。
num_hidden_inputs (int) – 预期隐藏状态输入的数量
- forward(x: Tensor, hidden_states: Optional[List[Tensor]] = None) Tensor [来源]¶
- 参数:
x (torch.Tensor) – 输入张量,形状为 [b x i x t x e x d]
hidden_states (Optional[List[torch.Tensor]]) – 编码器的隐藏状态列表。每个隐藏状态与 x 具有相同的形状。
- 返回:
- 输出张量,一个嵌入序列 [b x s x d]
其中序列长度为 num_imgs*num_tiles+num_embeds
- 返回类型:
Tensor
- 张量形状的符号说明
b: batch size (批量大小)
i: number of images (图像数量)
t: number of tiles (where a single image is broken into multiple tiles) (tile 数量 (单张图片被分成多个 tile))
e: number of embeds per tile (e.g. CLS embed + patch embeds, etc.) (每个 tile 的嵌入数量 (例如 CLS 嵌入 + patch 嵌入等))
s: sequence length computed by i*t*e (序列长度,由 i*t*e 计算得出)
d: embed dim (嵌入维度)