{ "architecture": { "attention_variant": "MLA", "family": "causal_lm", "is_moe": true, "mixer": "attention", "moe": { "num_experts": 64, "num_shared_experts": 2 }, "positional": "rope", "tie_word_embeddings": false, "view": "decoder" }, "capabilities": { "attention_backends": [ "eager", "sdpa", "flash_attention", "flex_attention" ], "attention_patterns": [ "causal" ], "attention_schedule": null, "kernels": { "RMSNorm": [ "kernels-community/liger-kernels", "kernels-community/rmsnorm", "kernels-community/mlx_rmsnorm" ] }, "task_heads": [ "causal_lm", "sequence_classification" ], "tensor_parallel": true }, "components": [ { "children": [ "embed_tokens", "decoder_layers", "norm", "rotary_emb" ], "class_name": "DeepseekV2Model", "id": "model", "kind": "model", "path_pattern": "model" }, { "attributes": { "embedding_dim": "config.hidden_size", "num_embeddings": "config.vocab_size", "tied_lm_head": false }, "class_name": "Embedding", "id": "embed_tokens", "kind": "embedding", "path_pattern": "model.embed_tokens" }, { "attributes": { "kernel": "RMSNorm", "norm_type": "rms" }, "class_name": "DeepseekV2RMSNorm", "id": "norm", "kind": "normalization", "path_pattern": "model.norm" }, { "attributes": { "head_dim": "config.head_dim", "rope_theta": 10000.0, "scheme": "rope" }, "class_name": "DeepseekV2RotaryEmbedding", "id": "rotary_emb", "kind": "position", "path_pattern": "model.rotary_emb" } ], "config": { "class_name": "DeepseekV2Config", "model_type": "deepseek_v2", "module": "transformers.models.deepseek_v2.configuration_deepseek_v2", "referenced_fields": { "num_hidden_layers": 32 }, "salient_fields": { "head_dim": 64, "hidden_act": "silu", "hidden_size": 4096, "intermediate_size": 11008, "is_encoder_decoder": false, "max_position_embeddings": 2048, "num_attention_heads": 32, "num_hidden_layers": 32, "num_key_value_heads": 32, "tie_word_embeddings": false, "vocab_size": 32000 } }, "edges": [ { "kind": "data", "source": "embed_tokens", "target": "decoder_layers" }, { "kind": "data", "source": "decoder_layers", "target": "norm" }, { "kind": "data", "source": "decoder_layer.input_layernorm", "target": "decoder_layer.post_attention_layernorm" }, { "kind": "mask", "source": "input:attention_mask", "target": "decoder_layer.self_attn" }, { "kind": "residual", "source": "decoder_layer", "target": "decoder_layer.self_attn" }, { "kind": "position", "source": "rotary_emb", "target": "decoder_layer.self_attn" }, { "kind": "data", "provenance": "intra_module", "source": "decoder_layer.self_attn", "target": "decoder_layer.self_attn.q_a_proj" }, { "kind": "data", "provenance": "intra_module", "source": "decoder_layer.self_attn", "target": "decoder_layer.self_attn.q_b_proj" }, { "kind": "data", "provenance": "intra_module", "source": "decoder_layer.self_attn", "target": "decoder_layer.self_attn.kv_a_proj_with_mqa" }, { "kind": "data", "provenance": "intra_module", "source": "decoder_layer.self_attn", "target": "decoder_layer.self_attn.kv_b_proj" }, { "kind": "data", "provenance": "intra_module", "source": "decoder_layer.self_attn.q_a_proj", "target": "decoder_layer.self_attn.o_proj" }, { "kind": "data", "provenance": "intra_module", "source": "decoder_layer.self_attn.q_b_proj", "target": "decoder_layer.self_attn.o_proj" }, { "kind": "data", "provenance": "intra_module", "source": "decoder_layer.self_attn.kv_a_proj_with_mqa", "target": "decoder_layer.self_attn.o_proj" }, { "kind": "data", "provenance": "intra_module", "source": "decoder_layer.self_attn.kv_b_proj", "target": "decoder_layer.self_attn.o_proj" }, { "kind": "data", "provenance": "intra_module", "source": "decoder_layer.mlp.shared_experts", "target": "decoder_layer.mlp.shared_experts.gate_proj" }, { "kind": "data", "provenance": "intra_module", "source": "decoder_layer.mlp.shared_experts", "target": "decoder_layer.mlp.shared_experts.up_proj" }, { "kind": "data", "provenance": "intra_module", "source": "decoder_layer.mlp.shared_experts.gate_proj", "target": "decoder_layer.mlp.shared_experts.down_proj" }, { "kind": "data", "provenance": "intra_module", "source": "decoder_layer.mlp.shared_experts.up_proj", "target": "decoder_layer.mlp.shared_experts.down_proj" }, { "kind": "cache_read", "source": "state:kv_cache", "target": "decoder_layer.self_attn" }, { "kind": "cache_write", "source": "decoder_layer.self_attn", "target": "state:kv_cache" }, { "kind": "route", "source": "decoder_layer.mlp", "target": "decoder_layer.mlp.experts" }, { "kind": "route", "source": "decoder_layer.mlp", "target": "decoder_layer.mlp.shared_experts" }, { "kind": "route", "source": "decoder_layer.mlp.shared_experts", "target": "decoder_layer.mlp.shared_experts.gate_proj" }, { "kind": "route", "source": "decoder_layer.mlp.shared_experts", "target": "decoder_layer.mlp.shared_experts.up_proj" }, { "kind": "route", "source": "decoder_layer.mlp.shared_experts", "target": "decoder_layer.mlp.shared_experts.down_proj" } ], "extends": "llama", "model_type": "deepseek_v2", "patches": [ { "added": { "attrs": [ "attention_bias", "attention_dropout", "attribute_map", "base_model_ep_plan", "base_model_tp_plan", "bos_token_id", "eos_token_id", "first_k_dense_replace", "hidden_act", "hidden_size", "initializer_range", "intermediate_size", "keys_to_ignore_at_inference", "kv_lora_rank", "max_position_embeddings", "mlp_bias", "model_type", "moe_intermediate_size", "n_group", "n_routed_experts", "n_shared_experts", "norm_topk_prob", "num_attention_heads", "num_experts_per_tok", "num_hidden_layers", "num_key_value_heads", "pad_token_id", "q_lora_rank", "qk_nope_head_dim", "qk_rope_head_dim", "rms_norm_eps", "rope_parameters", "routed_scaling_factor", "tie_word_embeddings", "topk_group", "topk_method", "use_cache", "v_head_dim", "vocab_size" ], "methods": [ "__post_init__" ] }, "component_kind": "config", "parent_class": "LlamaConfig", "relation": "new", "target_class": "DeepseekV2Config" }, { "component_kind": "moe", "overridden": { "methods": [ "__init__", "forward" ] }, "parent_class": "Qwen2MoeTopKRouter", "parent_model": "qwen2_moe", "relation": "inherits", "target_class": "DeepseekV2TopkRouter" }, { "added": { "methods": [ "__init__", "forward" ] }, "component_kind": "moe", "parent_class": "Module", "relation": "new", "target_class": "DeepseekV2Moe" }, { "component_kind": "feed_forward", "overridden": { "methods": [ "__init__" ] }, "parent_class": "LlamaMLP", "relation": "inherits", "target_class": "DeepseekV2MLP" }, { "component_kind": "position", "overridden": { "methods": [ "forward" ] }, "parent_class": "LlamaRotaryEmbedding", "relation": "inherits", "target_class": "DeepseekV2RotaryEmbedding" }, { "added": { "methods": [ "__init__", "forward" ] }, "component_kind": "attention", "parent_class": "Module", "relation": "new", "target_class": "DeepseekV2Attention" }, { "component_kind": "transformer_block", "overridden": { "methods": [ "__init__" ] }, "parent_class": "LlamaDecoderLayer", "relation": "inherits", "target_class": "DeepseekV2DecoderLayer" }, { "added": { "methods": [ "_init_weights" ] }, "component_kind": "model", "parent_class": "LlamaPreTrainedModel", "relation": "inherits", "target_class": "DeepseekV2PreTrainedModel" } ], "provenance": { "config_class": "DeepseekV2Config", "config_module": "transformers.models.deepseek_v2.configuration_deepseek_v2", "model_class": "DeepseekV2Model", "model_module": "transformers.models.deepseek_v2.modeling_deepseek_v2" }, "repeats": [ { "body": "decoder_layer", "container_path_pattern": "model.layers", "count": 32, "count_expr": "config.num_hidden_layers", "count_source": "config", "id": "decoder_layers", "index_symbol": "i", "item_path_pattern": "model.layers.{i}", "kind": "symbolic_repeat", "provenance": { "class_name": "DeepseekV2DecoderLayer", "container_path_pattern": "model.layers", "item_path_pattern": "model.layers.{i}", "source": "module_tree_repeat_collapse" }, "repeated_class_name": "DeepseekV2DecoderLayer" } ], "schema_version": "architecture-template-v0", "templates": [ { "children": [ "decoder_layer.self_attn", "decoder_layer.mlp", "decoder_layer.input_layernorm", "decoder_layer.post_attention_layernorm" ], "class_name": "DeepseekV2DecoderLayer", "id": "decoder_layer", "kind": "transformer_block", "path_pattern": "model.layers.{i}" }, { "attributes": { "head_dim": 64, "n_heads": 32, "n_kv_heads": 32, "pattern": "causal", "rope": true, "variant": "MLA" }, "children": [ "decoder_layer.self_attn.q_a_proj", "decoder_layer.self_attn.q_a_layernorm", "decoder_layer.self_attn.q_b_proj", "decoder_layer.self_attn.kv_a_proj_with_mqa", "decoder_layer.self_attn.kv_a_layernorm", "decoder_layer.self_attn.kv_b_proj", "decoder_layer.self_attn.o_proj" ], "class_name": "DeepseekV2Attention", "id": "decoder_layer.self_attn", "kind": "attention", "path_pattern": "model.layers.{i}.self_attn" }, { "attributes": { "in_features": "config.hidden_size", "out_features": 1536 }, "class_name": "Linear", "id": "decoder_layer.self_attn.q_a_proj", "kind": "projection", "path_pattern": "model.layers.{i}.self_attn.q_a_proj" }, { "attributes": { "kernel": "RMSNorm", "norm_type": "rms" }, "class_name": "DeepseekV2RMSNorm", "id": "decoder_layer.self_attn.q_a_layernorm", "kind": "normalization", "path_pattern": "model.layers.{i}.self_attn.q_a_layernorm" }, { "attributes": { "in_features": 1536, "out_features": 6144, "tp": "colwise" }, "class_name": "Linear", "id": "decoder_layer.self_attn.q_b_proj", "kind": "projection", "path_pattern": "model.layers.{i}.self_attn.q_b_proj" }, { "attributes": { "in_features": "config.hidden_size", "out_features": 576, "tp": "mla_kv_a_proj" }, "class_name": "Linear", "id": "decoder_layer.self_attn.kv_a_proj_with_mqa", "kind": "projection", "path_pattern": "model.layers.{i}.self_attn.kv_a_proj_with_mqa" }, { "attributes": { "kernel": "RMSNorm", "norm_type": "rms" }, "class_name": "DeepseekV2RMSNorm", "id": "decoder_layer.self_attn.kv_a_layernorm", "kind": "normalization", "path_pattern": "model.layers.{i}.self_attn.kv_a_layernorm" }, { "attributes": { "in_features": 512, "out_features": 8192, "tp": "colwise" }, "class_name": "Linear", "id": "decoder_layer.self_attn.kv_b_proj", "kind": "projection", "path_pattern": "model.layers.{i}.self_attn.kv_b_proj" }, { "attributes": { "in_features": "config.hidden_size", "out_features": "config.hidden_size", "tp": "rowwise" }, "class_name": "Linear", "id": "decoder_layer.self_attn.o_proj", "kind": "projection", "path_pattern": "model.layers.{i}.self_attn.o_proj" }, { "attributes": { "num_experts": 64, "num_shared_experts": 2 }, "children": [ "decoder_layer.mlp.experts", "decoder_layer.mlp.gate", "decoder_layer.mlp.shared_experts" ], "class_name": "DeepseekV2Moe", "id": "decoder_layer.mlp", "kind": "moe", "path_pattern": "model.layers.{i}.mlp" }, { "attributes": { "num_experts": 64, "num_shared_experts": 2 }, "class_name": "DeepseekV2Experts", "id": "decoder_layer.mlp.experts", "kind": "moe", "path_pattern": "model.layers.{i}.mlp.experts" }, { "attributes": { "num_experts": 64, "num_shared_experts": 2 }, "class_name": "DeepseekV2TopkRouter", "id": "decoder_layer.mlp.gate", "kind": "moe", "path_pattern": "model.layers.{i}.mlp.gate" }, { "attributes": { "num_experts": 64, "num_shared_experts": 2 }, "children": [ "decoder_layer.mlp.shared_experts.gate_proj", "decoder_layer.mlp.shared_experts.up_proj", "decoder_layer.mlp.shared_experts.down_proj" ], "class_name": "DeepseekV2MLP", "id": "decoder_layer.mlp.shared_experts", "kind": "moe", "path_pattern": "model.layers.{i}.mlp.shared_experts" }, { "attributes": { "in_features": "config.hidden_size", "out_features": 2814, "tp": "colwise" }, "class_name": "Linear", "id": "decoder_layer.mlp.shared_experts.gate_proj", "kind": "projection", "path_pattern": "model.layers.{i}.mlp.shared_experts.gate_proj" }, { "attributes": { "in_features": "config.hidden_size", "out_features": 2814, "tp": "colwise" }, "class_name": "Linear", "id": "decoder_layer.mlp.shared_experts.up_proj", "kind": "projection", "path_pattern": "model.layers.{i}.mlp.shared_experts.up_proj" }, { "attributes": { "in_features": 2814, "out_features": "config.hidden_size", "tp": "rowwise" }, "class_name": "Linear", "id": "decoder_layer.mlp.shared_experts.down_proj", "kind": "projection", "path_pattern": "model.layers.{i}.mlp.shared_experts.down_proj" }, { "attributes": { "kernel": "RMSNorm", "norm_type": "rms" }, "class_name": "DeepseekV2RMSNorm", "id": "decoder_layer.input_layernorm", "kind": "normalization", "path_pattern": "model.layers.{i}.input_layernorm" }, { "attributes": { "kernel": "RMSNorm", "norm_type": "rms" }, "class_name": "DeepseekV2RMSNorm", "id": "decoder_layer.post_attention_layernorm", "kind": "normalization", "path_pattern": "model.layers.{i}.post_attention_layernorm" } ] }