inspector / ir /artifacts /blip-2.json
lysandre's picture
lysandre HF Staff
Deploy architecture inspector
ed5700a verified
Raw
History Blame Contribute Delete
25.2 kB
{
"architecture": {
"attention_variant": "MHA",
"family": "image_text_to_text",
"is_moe": false,
"mixer": "attention",
"positional": "learned",
"tie_word_embeddings": true,
"towers": [
{
"attention_variant": "MHA",
"config_class": "OPTConfig",
"hidden_size": 768,
"name": "text",
"num_attention_heads": 12,
"num_hidden_layers": 12,
"positional": "learned"
},
{
"attention_variant": "MHA",
"config_class": "Blip2VisionConfig",
"hidden_size": 1408,
"name": "vision",
"num_attention_heads": 16,
"num_hidden_layers": 39
}
],
"view": "multimodal"
},
"capabilities": {
"attention_backends": [
"eager",
"sdpa",
"flex_attention"
],
"attention_patterns": [
"causal"
],
"attention_schedule": null,
"task_heads": [
"image_text_to_text",
"multimodal_lm",
"visual_question_answering",
"zero_shot_image_classification"
],
"tensor_parallel": false
},
"components": [
{
"children": [
"vision_model",
"qformer",
"language_projection",
"language_model"
],
"class_name": "Blip2Model",
"id": "model",
"kind": "model",
"path_pattern": "model"
},
{
"children": [
"vision_model.embeddings",
"vision_model.encoder",
"vision_model.post_layernorm"
],
"class_name": "Blip2VisionModel",
"id": "vision_model",
"kind": "model",
"path_pattern": "model.vision_model"
},
{
"attributes": {
"embedding_dim": "config.hidden_size"
},
"children": [
"vision_model.embeddings.patch_embedding"
],
"class_name": "Blip2VisionEmbeddings",
"id": "vision_model.embeddings",
"kind": "embedding",
"path_pattern": "model.vision_model.embeddings"
},
{
"class_name": "Conv2d",
"id": "vision_model.embeddings.patch_embedding",
"kind": "convolution",
"path_pattern": "model.vision_model.embeddings.patch_embedding"
},
{
"children": [
"encoder_layers"
],
"class_name": "Blip2Encoder",
"id": "vision_model.encoder",
"kind": "encoder",
"path_pattern": "model.vision_model.encoder"
},
{
"attributes": {
"norm_type": "layer"
},
"class_name": "LayerNorm",
"id": "vision_model.post_layernorm",
"kind": "normalization",
"path_pattern": "model.vision_model.post_layernorm"
},
{
"children": [
"qformer.layernorm",
"qformer.encoder"
],
"class_name": "Blip2QFormerModel",
"id": "qformer",
"kind": "model",
"path_pattern": "model.qformer"
},
{
"attributes": {
"norm_type": "layer"
},
"class_name": "LayerNorm",
"id": "qformer.layernorm",
"kind": "normalization",
"path_pattern": "model.qformer.layernorm"
},
{
"children": [
"encoder_layer_2s"
],
"class_name": "Blip2QFormerEncoder",
"id": "qformer.encoder",
"kind": "encoder",
"path_pattern": "model.qformer.encoder"
},
{
"attributes": {
"in_features": 768,
"out_features": 768
},
"class_name": "Linear",
"id": "language_projection",
"kind": "projection",
"path_pattern": "model.language_projection"
},
{
"children": [
"language_model.model"
],
"class_name": "OPTForCausalLM",
"id": "language_model",
"kind": "model",
"path_pattern": "model.language_model"
},
{
"children": [
"language_model.model.decoder"
],
"class_name": "OPTModel",
"id": "language_model.model",
"kind": "model",
"path_pattern": "model.language_model.model"
},
{
"children": [
"language_model.model.decoder.embed_tokens",
"language_model.model.decoder.embed_positions",
"language_model.model.decoder.final_layer_norm",
"decoder_layers"
],
"class_name": "OPTDecoder",
"id": "language_model.model.decoder",
"kind": "decoder",
"path_pattern": "model.language_model.model.decoder"
},
{
"attributes": {
"embedding_dim": "config.hidden_size",
"num_embeddings": "config.vocab_size",
"tied_lm_head": true
},
"class_name": "Embedding",
"id": "language_model.model.decoder.embed_tokens",
"kind": "embedding",
"path_pattern": "model.language_model.model.decoder.embed_tokens"
},
{
"attributes": {
"max_position_embeddings": "config.max_position_embeddings",
"scheme": "learned"
},
"class_name": "OPTLearnedPositionalEmbedding",
"id": "language_model.model.decoder.embed_positions",
"kind": "position",
"path_pattern": "model.language_model.model.decoder.embed_positions"
},
{
"attributes": {
"norm_type": "layer"
},
"class_name": "LayerNorm",
"id": "language_model.model.decoder.final_layer_norm",
"kind": "normalization",
"path_pattern": "model.language_model.model.decoder.final_layer_norm"
}
],
"config": {
"class_name": "Blip2Config",
"model_type": "blip-2",
"module": "transformers.models.blip_2.configuration_blip_2",
"referenced_fields": {},
"salient_fields": {
"is_encoder_decoder": false
}
},
"edges": [
{
"kind": "data",
"source": "vision_model",
"target": "qformer"
},
{
"kind": "data",
"source": "vision_model.embeddings",
"target": "vision_model.encoder"
},
{
"kind": "data",
"source": "vision_model.encoder",
"target": "vision_model.post_layernorm"
},
{
"kind": "data",
"source": "encoder_layer.self_attn",
"target": "encoder_layer.layer_norm1"
},
{
"kind": "data",
"source": "encoder_layer.layer_norm1",
"target": "encoder_layer.mlp"
},
{
"kind": "data",
"source": "encoder_layer.mlp",
"target": "encoder_layer.layer_norm2"
},
{
"kind": "data",
"source": "qformer.layernorm",
"target": "qformer.encoder"
},
{
"kind": "data",
"source": "encoder_layer_2.attention",
"target": "encoder_layer_2.crossattention"
},
{
"kind": "data",
"source": "encoder_layer_2.crossattention",
"target": "encoder_layer_2.intermediate_query"
},
{
"kind": "data",
"source": "encoder_layer_2.crossattention.attention",
"target": "encoder_layer_2.crossattention.output"
},
{
"kind": "data",
"source": "encoder_layer_2.attention",
"target": "encoder_layer_2.intermediate_query"
},
{
"kind": "data",
"source": "language_model.model.decoder.embed_tokens",
"target": "language_model.model.decoder.final_layer_norm"
},
{
"kind": "data",
"source": "language_model.model.decoder.final_layer_norm",
"target": "decoder_layers"
},
{
"kind": "mask",
"source": "input:attention_mask",
"target": "encoder_layer.self_attn"
},
{
"kind": "mask",
"source": "input:attention_mask",
"target": "encoder_layer_2.attention"
},
{
"kind": "mask",
"source": "input:attention_mask",
"target": "encoder_layer_2.attention.attention"
},
{
"kind": "mask",
"source": "input:attention_mask",
"target": "encoder_layer_2.crossattention"
},
{
"kind": "mask",
"source": "input:attention_mask",
"target": "encoder_layer_2.crossattention.attention"
},
{
"kind": "mask",
"source": "input:attention_mask",
"target": "encoder_layer_2.crossattention.output"
},
{
"kind": "mask",
"source": "input:attention_mask",
"target": "encoder_layer_2.crossattention.output.LayerNorm"
},
{
"kind": "mask",
"source": "input:attention_mask",
"target": "decoder_layer.self_attn"
},
{
"kind": "residual",
"source": "encoder_layer",
"target": "encoder_layer.self_attn"
},
{
"kind": "residual",
"source": "encoder_layer",
"target": "encoder_layer.mlp"
},
{
"kind": "residual",
"source": "encoder_layer_2",
"target": "encoder_layer_2.attention"
},
{
"kind": "residual",
"source": "encoder_layer_2",
"target": "encoder_layer_2.crossattention"
},
{
"kind": "residual",
"source": "encoder_layer_2",
"target": "encoder_layer_2.intermediate_query"
},
{
"kind": "residual",
"source": "decoder_layer",
"target": "decoder_layer.self_attn"
},
{
"kind": "position",
"source": "language_model.model.decoder.embed_positions",
"target": "decoder_layer.self_attn"
},
{
"kind": "cross_attention",
"source": "vision_model.encoder",
"target": "encoder_layer_2.crossattention"
},
{
"kind": "cross_attention",
"source": "vision_model.encoder",
"target": "encoder_layer_2.crossattention.attention"
},
{
"kind": "cross_attention",
"source": "vision_model.encoder",
"target": "encoder_layer_2.crossattention.output"
},
{
"kind": "cross_attention",
"source": "vision_model.encoder",
"target": "encoder_layer_2.crossattention.output.LayerNorm"
},
{
"kind": "data",
"provenance": "intra_module",
"source": "encoder_layer.self_attn",
"target": "encoder_layer.self_attn.qkv"
},
{
"kind": "data",
"provenance": "intra_module",
"source": "encoder_layer.self_attn",
"target": "encoder_layer.self_attn.projection"
},
{
"kind": "data",
"provenance": "intra_module",
"source": "encoder_layer.mlp",
"target": "encoder_layer.mlp.fc1"
},
{
"kind": "data",
"provenance": "intra_module",
"source": "encoder_layer.mlp.fc1",
"target": "encoder_layer.mlp.fc2"
},
{
"kind": "data",
"provenance": "intra_module",
"source": "encoder_layer_2.attention.attention",
"target": "encoder_layer_2.attention.attention.query"
},
{
"kind": "data",
"provenance": "intra_module",
"source": "encoder_layer_2.attention.attention",
"target": "encoder_layer_2.attention.attention.key"
},
{
"kind": "data",
"provenance": "intra_module",
"source": "encoder_layer_2.attention.attention",
"target": "encoder_layer_2.attention.attention.value"
},
{
"kind": "data",
"provenance": "intra_module",
"source": "encoder_layer_2.intermediate_query",
"target": "encoder_layer_2.intermediate_query.dense"
},
{
"kind": "data",
"provenance": "intra_module",
"source": "decoder_layer.self_attn",
"target": "decoder_layer.self_attn.k_proj"
},
{
"kind": "data",
"provenance": "intra_module",
"source": "decoder_layer.self_attn",
"target": "decoder_layer.self_attn.v_proj"
},
{
"kind": "data",
"provenance": "intra_module",
"source": "decoder_layer.self_attn",
"target": "decoder_layer.self_attn.q_proj"
},
{
"kind": "data",
"provenance": "intra_module",
"source": "decoder_layer.self_attn.k_proj",
"target": "decoder_layer.self_attn.out_proj"
},
{
"kind": "data",
"provenance": "intra_module",
"source": "decoder_layer.self_attn.v_proj",
"target": "decoder_layer.self_attn.out_proj"
},
{
"kind": "data",
"provenance": "intra_module",
"source": "decoder_layer.self_attn.q_proj",
"target": "decoder_layer.self_attn.out_proj"
}
],
"extends": null,
"model_type": "blip-2",
"provenance": {
"config_class": "Blip2Config",
"config_module": "transformers.models.blip_2.configuration_blip_2",
"model_class": "Blip2Model",
"model_module": "transformers.models.blip_2.modeling_blip_2"
},
"repeats": [
{
"body": "encoder_layer",
"container_path_pattern": "model.vision_model.encoder.layers",
"count": 39,
"count_expr": "39",
"count_source": "module_tree",
"id": "encoder_layers",
"index_symbol": "i",
"item_path_pattern": "model.vision_model.encoder.layers.{i}",
"kind": "symbolic_repeat",
"provenance": {
"class_name": "Blip2EncoderLayer",
"container_path_pattern": "model.vision_model.encoder.layers",
"item_path_pattern": "model.vision_model.encoder.layers.{i}",
"source": "module_tree_repeat_collapse"
},
"repeated_class_name": "Blip2EncoderLayer"
},
{
"body": "encoder_layer_2",
"container_path_pattern": "model.qformer.encoder.layer",
"count": 12,
"count_expr": "12",
"count_source": "module_tree",
"id": "encoder_layer_2s",
"index_symbol": "i",
"item_path_pattern": "model.qformer.encoder.layer.{i}",
"kind": "symbolic_repeat",
"provenance": {
"class_name": "Blip2QFormerLayer",
"container_path_pattern": "model.qformer.encoder.layer",
"item_path_pattern": "model.qformer.encoder.layer.{i}",
"source": "module_tree_repeat_collapse"
},
"repeated_class_name": "Blip2QFormerLayer"
},
{
"body": "decoder_layer",
"container_path_pattern": "model.language_model.model.decoder.layers",
"count": 12,
"count_expr": "12",
"count_source": "module_tree",
"id": "decoder_layers",
"index_symbol": "i",
"item_path_pattern": "model.language_model.model.decoder.layers.{i}",
"kind": "symbolic_repeat",
"provenance": {
"class_name": "OPTDecoderLayer",
"container_path_pattern": "model.language_model.model.decoder.layers",
"item_path_pattern": "model.language_model.model.decoder.layers.{i}",
"source": "module_tree_repeat_collapse"
},
"repeated_class_name": "OPTDecoderLayer"
}
],
"schema_version": "architecture-template-v0",
"templates": [
{
"children": [
"encoder_layer.self_attn",
"encoder_layer.layer_norm1",
"encoder_layer.mlp",
"encoder_layer.layer_norm2"
],
"class_name": "Blip2EncoderLayer",
"id": "encoder_layer",
"kind": "transformer_block",
"path_pattern": "model.vision_model.encoder.layers.{i}"
},
{
"attributes": {
"head_dim": 88,
"n_heads": 16,
"n_kv_heads": 16,
"rope": false,
"variant": "MHA"
},
"children": [
"encoder_layer.self_attn.qkv",
"encoder_layer.self_attn.projection"
],
"class_name": "Blip2Attention",
"id": "encoder_layer.self_attn",
"kind": "attention",
"path_pattern": "model.vision_model.encoder.layers.{i}.self_attn"
},
{
"attributes": {
"in_features": "config.hidden_size",
"out_features": 4224
},
"class_name": "Linear",
"id": "encoder_layer.self_attn.qkv",
"kind": "projection",
"path_pattern": "model.vision_model.encoder.layers.{i}.self_attn.qkv"
},
{
"attributes": {
"in_features": "config.hidden_size",
"out_features": "config.hidden_size"
},
"class_name": "Linear",
"id": "encoder_layer.self_attn.projection",
"kind": "projection",
"path_pattern": "model.vision_model.encoder.layers.{i}.self_attn.projection"
},
{
"attributes": {
"norm_type": "layer"
},
"class_name": "LayerNorm",
"id": "encoder_layer.layer_norm1",
"kind": "normalization",
"path_pattern": "model.vision_model.encoder.layers.{i}.layer_norm1"
},
{
"attributes": {
"activation": "gelu",
"hidden_size": 1408,
"intermediate_size": 6144
},
"children": [
"encoder_layer.mlp.fc1",
"encoder_layer.mlp.fc2"
],
"class_name": "Blip2MLP",
"id": "encoder_layer.mlp",
"kind": "feed_forward",
"path_pattern": "model.vision_model.encoder.layers.{i}.mlp"
},
{
"attributes": {
"in_features": "config.hidden_size",
"out_features": "config.intermediate_size"
},
"class_name": "Linear",
"id": "encoder_layer.mlp.fc1",
"kind": "projection",
"path_pattern": "model.vision_model.encoder.layers.{i}.mlp.fc1"
},
{
"attributes": {
"in_features": "config.intermediate_size",
"out_features": "config.hidden_size"
},
"class_name": "Linear",
"id": "encoder_layer.mlp.fc2",
"kind": "projection",
"path_pattern": "model.vision_model.encoder.layers.{i}.mlp.fc2"
},
{
"attributes": {
"norm_type": "layer"
},
"class_name": "LayerNorm",
"id": "encoder_layer.layer_norm2",
"kind": "normalization",
"path_pattern": "model.vision_model.encoder.layers.{i}.layer_norm2"
},
{
"children": [
"encoder_layer_2.attention",
"encoder_layer_2.crossattention",
"encoder_layer_2.intermediate_query",
"encoder_layer_2.output_query"
],
"class_name": "Blip2QFormerLayer",
"id": "encoder_layer_2",
"kind": "transformer_block",
"path_pattern": "model.qformer.encoder.layer.{i}"
},
{
"attributes": {
"rope": false
},
"children": [
"encoder_layer_2.attention.attention",
"encoder_layer_2.attention.output"
],
"class_name": "Blip2QFormerAttention",
"id": "encoder_layer_2.attention",
"kind": "attention",
"path_pattern": "model.qformer.encoder.layer.{i}.attention"
},
{
"attributes": {
"rope": false
},
"children": [
"encoder_layer_2.attention.attention.query",
"encoder_layer_2.attention.attention.key",
"encoder_layer_2.attention.attention.value"
],
"class_name": "Blip2QFormerMultiHeadAttention",
"id": "encoder_layer_2.attention.attention",
"kind": "attention",
"path_pattern": "model.qformer.encoder.layer.{i}.attention.attention"
},
{
"attributes": {
"in_features": 768,
"out_features": 768
},
"class_name": "Linear",
"id": "encoder_layer_2.attention.attention.query",
"kind": "projection",
"path_pattern": "model.qformer.encoder.layer.{i}.attention.attention.query"
},
{
"attributes": {
"in_features": 768,
"out_features": 768
},
"class_name": "Linear",
"id": "encoder_layer_2.attention.attention.key",
"kind": "projection",
"path_pattern": "model.qformer.encoder.layer.{i}.attention.attention.key"
},
{
"attributes": {
"in_features": 768,
"out_features": 768
},
"class_name": "Linear",
"id": "encoder_layer_2.attention.attention.value",
"kind": "projection",
"path_pattern": "model.qformer.encoder.layer.{i}.attention.attention.value"
},
{
"children": [
"encoder_layer_2.attention.output.LayerNorm"
],
"class_name": "Blip2QFormerSelfOutput",
"id": "encoder_layer_2.attention.output",
"kind": "module",
"path_pattern": "model.qformer.encoder.layer.{i}.attention.output"
},
{
"attributes": {
"norm_type": "layer"
},
"class_name": "LayerNorm",
"id": "encoder_layer_2.attention.output.LayerNorm",
"kind": "normalization",
"path_pattern": "model.qformer.encoder.layer.{i}.attention.output.LayerNorm"
},
{
"attributes": {
"rope": false
},
"children": [
"encoder_layer_2.crossattention.attention",
"encoder_layer_2.crossattention.output"
],
"class_name": "Blip2QFormerAttention",
"id": "encoder_layer_2.crossattention",
"kind": "cross_attention",
"path_pattern": "model.qformer.encoder.layer.{i}.crossattention"
},
{
"attributes": {
"rope": false
},
"class_name": "Blip2QFormerMultiHeadAttention",
"id": "encoder_layer_2.crossattention.attention",
"kind": "cross_attention",
"path_pattern": "model.qformer.encoder.layer.{i}.crossattention.attention"
},
{
"attributes": {
"rope": false
},
"children": [
"encoder_layer_2.crossattention.output.LayerNorm"
],
"class_name": "Blip2QFormerSelfOutput",
"id": "encoder_layer_2.crossattention.output",
"kind": "cross_attention",
"path_pattern": "model.qformer.encoder.layer.{i}.crossattention.output"
},
{
"attributes": {
"rope": false
},
"class_name": "LayerNorm",
"id": "encoder_layer_2.crossattention.output.LayerNorm",
"kind": "cross_attention",
"path_pattern": "model.qformer.encoder.layer.{i}.crossattention.output.LayerNorm"
},
{
"children": [
"encoder_layer_2.intermediate_query.dense"
],
"class_name": "Blip2QFormerIntermediate",
"id": "encoder_layer_2.intermediate_query",
"kind": "feed_forward",
"path_pattern": "model.qformer.encoder.layer.{i}.intermediate_query"
},
{
"attributes": {
"in_features": 768,
"out_features": 3072
},
"class_name": "Linear",
"id": "encoder_layer_2.intermediate_query.dense",
"kind": "projection",
"path_pattern": "model.qformer.encoder.layer.{i}.intermediate_query.dense"
},
{
"children": [
"encoder_layer_2.output_query.LayerNorm"
],
"class_name": "Blip2QFormerOutput",
"id": "encoder_layer_2.output_query",
"kind": "module",
"path_pattern": "model.qformer.encoder.layer.{i}.output_query"
},
{
"attributes": {
"norm_type": "layer"
},
"class_name": "LayerNorm",
"id": "encoder_layer_2.output_query.LayerNorm",
"kind": "normalization",
"path_pattern": "model.qformer.encoder.layer.{i}.output_query.LayerNorm"
},
{
"children": [
"decoder_layer.self_attn",
"decoder_layer.self_attn_layer_norm",
"decoder_layer.final_layer_norm"
],
"class_name": "OPTDecoderLayer",
"id": "decoder_layer",
"kind": "transformer_block",
"path_pattern": "model.language_model.model.decoder.layers.{i}"
},
{
"attributes": {
"head_dim": 64,
"n_heads": 12,
"n_kv_heads": 12,
"rope": false,
"variant": "MHA"
},
"children": [
"decoder_layer.self_attn.k_proj",
"decoder_layer.self_attn.v_proj",
"decoder_layer.self_attn.q_proj",
"decoder_layer.self_attn.out_proj"
],
"class_name": "OPTAttention",
"id": "decoder_layer.self_attn",
"kind": "attention",
"path_pattern": "model.language_model.model.decoder.layers.{i}.self_attn"
},
{
"attributes": {
"in_features": "config.hidden_size",
"out_features": "config.hidden_size"
},
"class_name": "Linear",
"id": "decoder_layer.self_attn.k_proj",
"kind": "projection",
"path_pattern": "model.language_model.model.decoder.layers.{i}.self_attn.k_proj"
},
{
"attributes": {
"in_features": "config.hidden_size",
"out_features": "config.hidden_size"
},
"class_name": "Linear",
"id": "decoder_layer.self_attn.v_proj",
"kind": "projection",
"path_pattern": "model.language_model.model.decoder.layers.{i}.self_attn.v_proj"
},
{
"attributes": {
"in_features": "config.hidden_size",
"out_features": "config.hidden_size"
},
"class_name": "Linear",
"id": "decoder_layer.self_attn.q_proj",
"kind": "projection",
"path_pattern": "model.language_model.model.decoder.layers.{i}.self_attn.q_proj"
},
{
"attributes": {
"in_features": "config.hidden_size",
"out_features": "config.hidden_size"
},
"class_name": "Linear",
"id": "decoder_layer.self_attn.out_proj",
"kind": "projection",
"path_pattern": "model.language_model.model.decoder.layers.{i}.self_attn.out_proj"
},
{
"attributes": {
"norm_type": "layer"
},
"class_name": "LayerNorm",
"id": "decoder_layer.self_attn_layer_norm",
"kind": "normalization",
"path_pattern": "model.language_model.model.decoder.layers.{i}.self_attn_layer_norm"
},
{
"attributes": {
"norm_type": "layer"
},
"class_name": "LayerNorm",
"id": "decoder_layer.final_layer_norm",
"kind": "normalization",
"path_pattern": "model.language_model.model.decoder.layers.{i}.final_layer_norm"
}
]
}