lfm3VisionTensorShapes function
Required vision/projector checkpoint tensor names and shapes for I/O.
Implementation
Map<String, List<int>> lfm3VisionTensorShapes(Lfm3VlConfig config) {
final c = config.vision;
final h = c.hiddenSize;
const v = Lfm3VlConfig.visionPrefix, p = Lfm3VlConfig.projectorPrefix;
final result = <String, List<int>>{
'${v}patchifier.weight': [
h,
c.inChannels * c.temporalPatchSize * c.patchSize * c.patchSize,
],
'${v}embedding_norm.weight': [h],
'${p}layer_norm.weight': [h],
'${p}layer_norm.bias': [h],
'${p}linear_1.weight': [
config.projectorHiddenSize,
config.projectorInputSize,
],
'${p}linear_1.bias': [config.projectorHiddenSize],
'${p}linear_2.weight': [config.text.hiddenSize, config.projectorHiddenSize],
'${p}linear_2.bias': [config.text.hiddenSize],
};
for (var i = 0; i < c.numLayers; i++) {
final b = '${v}layers.$i.';
result['${b}operator_norm.weight'] = [h];
result['${b}ffn_norm.weight'] = [h];
result['${b}feed_forward.w1.weight'] = [c.intermediateSize, h];
result['${b}feed_forward.w3.weight'] = [c.intermediateSize, h];
result['${b}feed_forward.w2.weight'] = [h, c.intermediateSize];
if (c.layerTypes[i] == VisionLayerType.conv) {
result['${b}conv.in_proj.weight'] = [3 * h, h];
result['${b}conv.out_proj.weight'] = [h, h];
result['${b}conv.spatial_conv.weight'] = [
h,
1,
c.convKernelSize,
c.convKernelSize,
];
} else {
final a = '${b}self_attn.';
result['${a}q_proj.weight'] = [h, h];
result['${a}k_proj.weight'] = [c.numKvHeads * c.headDim, h];
result['${a}v_proj.weight'] = [c.numKvHeads * c.headDim, h];
result['${a}out_proj.weight'] = [h, h];
result['${a}q_layernorm.weight'] = [c.headDim];
result['${a}k_layernorm.weight'] = [c.headDim];
}
}
return result;
}