Deploy architecture inspector
Browse files- examples/01-structure.jsonc +255 -0
- examples/02-capabilities.jsonc +62 -0
- examples/03-modularity.jsonc +61 -0
- examples/04-full.jsonc +133 -0
examples/01-structure.jsonc
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// 01 — structure: components, edges, dataflow + per-node facts (the annotated diagram).
|
| 2 |
+
// Trimmed mistral (real values); "…" marks omitted repetition. Tiers 02–04 add to this.
|
| 3 |
+
{
|
| 4 |
+
"schema_version": "architecture-template-v0",
|
| 5 |
+
"model_type": "mistral",
|
| 6 |
+
"architecture": {
|
| 7 |
+
"view": "decoder",
|
| 8 |
+
"family": "causal_lm",
|
| 9 |
+
"attention_variant": "GQA",
|
| 10 |
+
"positional": "rope",
|
| 11 |
+
"is_moe": false,
|
| 12 |
+
"sliding_window": 4096,
|
| 13 |
+
"tie_word_embeddings": false
|
| 14 |
+
},
|
| 15 |
+
"config": {
|
| 16 |
+
"class_name": "MistralConfig",
|
| 17 |
+
"module": "transformers.models.mistral.configuration_mistral",
|
| 18 |
+
"model_type": "mistral",
|
| 19 |
+
"referenced_fields": {
|
| 20 |
+
"num_hidden_layers": 32
|
| 21 |
+
},
|
| 22 |
+
"salient_fields": {
|
| 23 |
+
"hidden_size": 4096,
|
| 24 |
+
"intermediate_size": 14336,
|
| 25 |
+
"num_attention_heads": 32,
|
| 26 |
+
"num_key_value_heads": 8,
|
| 27 |
+
"head_dim": 128,
|
| 28 |
+
"vocab_size": 32000,
|
| 29 |
+
"sliding_window": 4096
|
| 30 |
+
}
|
| 31 |
+
},
|
| 32 |
+
"components": [
|
| 33 |
+
{
|
| 34 |
+
"id": "model",
|
| 35 |
+
"kind": "model",
|
| 36 |
+
"class_name": "MistralModel",
|
| 37 |
+
"path_pattern": "model",
|
| 38 |
+
"children": [
|
| 39 |
+
"embed_tokens",
|
| 40 |
+
"decoder_layers",
|
| 41 |
+
"norm",
|
| 42 |
+
"rotary_emb"
|
| 43 |
+
]
|
| 44 |
+
},
|
| 45 |
+
// "decoder_layers" is the repeat id
|
| 46 |
+
{
|
| 47 |
+
"id": "embed_tokens",
|
| 48 |
+
"kind": "embedding",
|
| 49 |
+
"class_name": "Embedding",
|
| 50 |
+
"path_pattern": "model.embed_tokens",
|
| 51 |
+
"attributes": {
|
| 52 |
+
"num_embeddings": "config.vocab_size",
|
| 53 |
+
"embedding_dim": "config.hidden_size"
|
| 54 |
+
}
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"id": "norm",
|
| 58 |
+
"kind": "normalization",
|
| 59 |
+
"class_name": "MistralRMSNorm",
|
| 60 |
+
"path_pattern": "model.norm",
|
| 61 |
+
"attributes": {
|
| 62 |
+
"norm_type": "rms",
|
| 63 |
+
"kernel": "RMSNorm"
|
| 64 |
+
}
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"id": "rotary_emb",
|
| 68 |
+
"kind": "position",
|
| 69 |
+
"class_name": "MistralRotaryEmbedding",
|
| 70 |
+
"path_pattern": "model.rotary_emb",
|
| 71 |
+
"attributes": {
|
| 72 |
+
"scheme": "rope",
|
| 73 |
+
"rope_theta": 10000.0,
|
| 74 |
+
"head_dim": "config.head_dim"
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
],
|
| 78 |
+
"templates": [
|
| 79 |
+
{
|
| 80 |
+
"id": "decoder_layer",
|
| 81 |
+
"kind": "transformer_block",
|
| 82 |
+
"class_name": "MistralDecoderLayer",
|
| 83 |
+
"path_pattern": "model.layers.{i}",
|
| 84 |
+
// {i} = layer index
|
| 85 |
+
"children": [
|
| 86 |
+
"decoder_layer.input_layernorm",
|
| 87 |
+
"decoder_layer.self_attn",
|
| 88 |
+
"decoder_layer.post_attention_layernorm",
|
| 89 |
+
"decoder_layer.mlp"
|
| 90 |
+
]
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"id": "decoder_layer.self_attn",
|
| 94 |
+
"kind": "attention",
|
| 95 |
+
"class_name": "MistralAttention",
|
| 96 |
+
"path_pattern": "model.layers.{i}.self_attn",
|
| 97 |
+
"children": [
|
| 98 |
+
"decoder_layer.self_attn.q_proj",
|
| 99 |
+
"decoder_layer.self_attn.o_proj"
|
| 100 |
+
],
|
| 101 |
+
// … k_proj, v_proj
|
| 102 |
+
"attributes": {
|
| 103 |
+
"variant": "GQA",
|
| 104 |
+
"n_heads": 32,
|
| 105 |
+
"n_kv_heads": 8,
|
| 106 |
+
"head_dim": 128,
|
| 107 |
+
"rope": true,
|
| 108 |
+
"sliding_window": 4096,
|
| 109 |
+
"pattern": "sliding"
|
| 110 |
+
}
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"id": "decoder_layer.self_attn.q_proj",
|
| 114 |
+
"kind": "projection",
|
| 115 |
+
"class_name": "Linear",
|
| 116 |
+
"path_pattern": "model.layers.{i}.self_attn.q_proj",
|
| 117 |
+
"attributes": {
|
| 118 |
+
"in_features": "config.hidden_size",
|
| 119 |
+
"out_features": 4096,
|
| 120 |
+
"tp": "colwise"
|
| 121 |
+
}
|
| 122 |
+
},
|
| 123 |
+
{
|
| 124 |
+
"id": "decoder_layer.mlp",
|
| 125 |
+
"kind": "feed_forward",
|
| 126 |
+
"class_name": "MistralMLP",
|
| 127 |
+
"path_pattern": "model.layers.{i}.mlp",
|
| 128 |
+
"children": [
|
| 129 |
+
"decoder_layer.mlp.gate_proj",
|
| 130 |
+
"decoder_layer.mlp.up_proj",
|
| 131 |
+
"decoder_layer.mlp.down_proj"
|
| 132 |
+
],
|
| 133 |
+
"attributes": {
|
| 134 |
+
"hidden_size": 4096,
|
| 135 |
+
"intermediate_size": 14336,
|
| 136 |
+
"activation": "silu"
|
| 137 |
+
}
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"id": "decoder_layer.input_layernorm",
|
| 141 |
+
"kind": "normalization",
|
| 142 |
+
"class_name": "MistralRMSNorm",
|
| 143 |
+
"path_pattern": "model.layers.{i}.input_layernorm",
|
| 144 |
+
"attributes": {
|
| 145 |
+
"norm_type": "rms",
|
| 146 |
+
"kernel": "RMSNorm"
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
// … post_attention_layernorm, and the k/v/o + gate/up/down projection nodes
|
| 150 |
+
],
|
| 151 |
+
"repeats": [
|
| 152 |
+
{
|
| 153 |
+
"id": "decoder_layers",
|
| 154 |
+
"kind": "symbolic_repeat",
|
| 155 |
+
"body": "decoder_layer",
|
| 156 |
+
"count_expr": "config.num_hidden_layers",
|
| 157 |
+
"count": 32,
|
| 158 |
+
"count_source": "config",
|
| 159 |
+
"index_symbol": "i",
|
| 160 |
+
"container_path_pattern": "model.layers",
|
| 161 |
+
"item_path_pattern": "model.layers.{i}",
|
| 162 |
+
"repeated_class_name": "MistralDecoderLayer"
|
| 163 |
+
}
|
| 164 |
+
// 32 identical layers → one symbolic entry
|
| 165 |
+
],
|
| 166 |
+
"edges": [
|
| 167 |
+
{
|
| 168 |
+
"source": "embed_tokens",
|
| 169 |
+
"target": "decoder_layers",
|
| 170 |
+
"kind": "data"
|
| 171 |
+
},
|
| 172 |
+
{
|
| 173 |
+
"source": "decoder_layers",
|
| 174 |
+
"target": "norm",
|
| 175 |
+
"kind": "data"
|
| 176 |
+
},
|
| 177 |
+
{
|
| 178 |
+
"source": "decoder_layer.input_layernorm",
|
| 179 |
+
"target": "decoder_layer.self_attn",
|
| 180 |
+
"kind": "data",
|
| 181 |
+
"provenance": "observed_forward"
|
| 182 |
+
},
|
| 183 |
+
{
|
| 184 |
+
"source": "decoder_layer",
|
| 185 |
+
"target": "decoder_layer.self_attn",
|
| 186 |
+
"kind": "residual"
|
| 187 |
+
},
|
| 188 |
+
{
|
| 189 |
+
"source": "rotary_emb",
|
| 190 |
+
"target": "decoder_layer.self_attn",
|
| 191 |
+
"kind": "position"
|
| 192 |
+
},
|
| 193 |
+
{
|
| 194 |
+
"source": "input:attention_mask",
|
| 195 |
+
"target": "decoder_layer.self_attn",
|
| 196 |
+
"kind": "mask"
|
| 197 |
+
},
|
| 198 |
+
{
|
| 199 |
+
"source": "state:kv_cache",
|
| 200 |
+
"target": "decoder_layer.self_attn",
|
| 201 |
+
"kind": "cache_read"
|
| 202 |
+
}
|
| 203 |
+
// … kinds: data | residual | mask | position | cross_attention | route | cache_read | cache_write
|
| 204 |
+
],
|
| 205 |
+
"dataflow": {
|
| 206 |
+
"source": "observed_forward_meta",
|
| 207 |
+
"input": {
|
| 208 |
+
"name": "input_ids",
|
| 209 |
+
"shape": [
|
| 210 |
+
"B",
|
| 211 |
+
"S"
|
| 212 |
+
]
|
| 213 |
+
},
|
| 214 |
+
// B=batch, S=sequence
|
| 215 |
+
"output": {
|
| 216 |
+
"shape": [
|
| 217 |
+
"B",
|
| 218 |
+
"S",
|
| 219 |
+
"config.hidden_size"
|
| 220 |
+
]
|
| 221 |
+
},
|
| 222 |
+
"shapes": {
|
| 223 |
+
// per-node observed shapes (symbolized); node ORDER lives in edges
|
| 224 |
+
"embed_tokens": {
|
| 225 |
+
"in": [
|
| 226 |
+
"B",
|
| 227 |
+
"S"
|
| 228 |
+
],
|
| 229 |
+
"out": [
|
| 230 |
+
"B",
|
| 231 |
+
"S",
|
| 232 |
+
"config.hidden_size"
|
| 233 |
+
]
|
| 234 |
+
},
|
| 235 |
+
"decoder_layer.self_attn": {
|
| 236 |
+
"in": [
|
| 237 |
+
"B",
|
| 238 |
+
"S",
|
| 239 |
+
"config.hidden_size"
|
| 240 |
+
],
|
| 241 |
+
"out": [
|
| 242 |
+
"B",
|
| 243 |
+
"S",
|
| 244 |
+
"config.hidden_size"
|
| 245 |
+
]
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
},
|
| 249 |
+
"provenance": {
|
| 250 |
+
"config_class": "MistralConfig",
|
| 251 |
+
"config_module": "transformers.models.mistral.configuration_mistral",
|
| 252 |
+
"model_class": "MistralModel",
|
| 253 |
+
"model_module": "transformers.models.mistral.modeling_mistral"
|
| 254 |
+
}
|
| 255 |
+
}
|
examples/02-capabilities.jsonc
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// 02 — everything in 01, plus `capabilities`: what the model can do / run with.
|
| 2 |
+
// (structure/dataflow trimmed here to keep the focus on the new block — see 01 for the full diagram.)
|
| 3 |
+
{
|
| 4 |
+
"schema_version": "architecture-template-v0",
|
| 5 |
+
"model_type": "mistral",
|
| 6 |
+
"architecture": {
|
| 7 |
+
"view": "decoder", "family": "causal_lm", "attention_variant": "GQA",
|
| 8 |
+
"positional": "rope", "is_moe": false, "sliding_window": 4096, "tie_word_embeddings": false
|
| 9 |
+
},
|
| 10 |
+
|
| 11 |
+
// ▼▼▼ the tier-02 addition ▼▼▼
|
| 12 |
+
"capabilities": {
|
| 13 |
+
"attention_backends": ["eager", "sdpa", "flash_attention", "flex_attention"], // "can run with", not "installed"
|
| 14 |
+
"attention_patterns": ["sliding"], // distinct per-layer mask kinds
|
| 15 |
+
"attention_schedule": null, // raw config.layer_types when non-uniform, else null
|
| 16 |
+
"task_heads": ["causal_lm", "question_answering", "sequence_classification", "token_classification"],
|
| 17 |
+
"tensor_parallel": true, // → projection nodes carry attributes.tp (colwise/rowwise)
|
| 18 |
+
"kernels": { // kernelizable layers → compatible Hub kernel repos
|
| 19 |
+
"RMSNorm": ["kernels-community/liger-kernels", "kernels-community/rmsnorm", "kernels-community/mlx_rmsnorm"]
|
| 20 |
+
}
|
| 21 |
+
},
|
| 22 |
+
// ▲▲▲ nodes point in via attributes.kernel: "RMSNorm" ▲▲▲
|
| 23 |
+
|
| 24 |
+
"config": {
|
| 25 |
+
"class_name": "MistralConfig", "module": "transformers.models.mistral.configuration_mistral", "model_type": "mistral",
|
| 26 |
+
"referenced_fields": { "num_hidden_layers": 32 },
|
| 27 |
+
"salient_fields": { "hidden_size": 4096, "intermediate_size": 14336, "num_key_value_heads": 8, "head_dim": 128 }
|
| 28 |
+
},
|
| 29 |
+
"components": [
|
| 30 |
+
{ "id": "model", "kind": "model", "class_name": "MistralModel", "path_pattern": "model",
|
| 31 |
+
"children": ["embed_tokens", "decoder_layers", "norm"] },
|
| 32 |
+
{ "id": "norm", "kind": "normalization", "class_name": "MistralRMSNorm", "path_pattern": "model.norm",
|
| 33 |
+
"attributes": { "norm_type": "rms", "kernel": "RMSNorm" } } // ← joins to capabilities.kernels["RMSNorm"]
|
| 34 |
+
// … embed_tokens, rotary_emb (see 01)
|
| 35 |
+
],
|
| 36 |
+
"templates": [
|
| 37 |
+
{ "id": "decoder_layer.self_attn", "kind": "attention", "class_name": "MistralAttention",
|
| 38 |
+
"path_pattern": "model.layers.{i}.self_attn",
|
| 39 |
+
"attributes": { "variant": "GQA", "n_heads": 32, "n_kv_heads": 8, "head_dim": 128, "pattern": "sliding" } }
|
| 40 |
+
// … decoder_layer + its projection / norm / mlp children (see 01)
|
| 41 |
+
],
|
| 42 |
+
"repeats": [
|
| 43 |
+
{ "id": "decoder_layers", "kind": "symbolic_repeat", "body": "decoder_layer",
|
| 44 |
+
"count_expr": "config.num_hidden_layers", "count": 32, "count_source": "config", "index_symbol": "i",
|
| 45 |
+
"container_path_pattern": "model.layers", "item_path_pattern": "model.layers.{i}",
|
| 46 |
+
"repeated_class_name": "MistralDecoderLayer" }
|
| 47 |
+
],
|
| 48 |
+
"edges": [
|
| 49 |
+
{ "source": "embed_tokens", "target": "decoder_layers", "kind": "data" },
|
| 50 |
+
{ "source": "decoder_layers", "target": "norm", "kind": "data" }
|
| 51 |
+
],
|
| 52 |
+
"dataflow": {
|
| 53 |
+
"source": "observed_forward_meta",
|
| 54 |
+
"input": { "name": "input_ids", "shape": ["B", "S"] },
|
| 55 |
+
"output": { "shape": ["B", "S", "config.hidden_size"] },
|
| 56 |
+
"shapes": { "embed_tokens": { "in": ["B", "S"], "out": ["B", "S", "config.hidden_size"] } }
|
| 57 |
+
},
|
| 58 |
+
"provenance": {
|
| 59 |
+
"config_class": "MistralConfig", "config_module": "transformers.models.mistral.configuration_mistral",
|
| 60 |
+
"model_class": "MistralModel", "model_module": "transformers.models.mistral.modeling_mistral"
|
| 61 |
+
}
|
| 62 |
+
}
|
examples/03-modularity.jsonc
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// 03 — everything in 01+02, plus modular inheritance: `extends` + `patches`.
|
| 2 |
+
// (structure/capabilities trimmed here — see 01/02.) Standalone models have extends=null and no patches.
|
| 3 |
+
{
|
| 4 |
+
"schema_version": "architecture-template-v0",
|
| 5 |
+
"model_type": "mistral",
|
| 6 |
+
|
| 7 |
+
// ▼▼▼ the tier-03 addition ▼▼▼
|
| 8 |
+
"extends": "llama", // dominant parent model_type (from modular_mistral.py)
|
| 9 |
+
"patches": [ // per-class changes vs the parent; trivial (unchanged) classes are omitted
|
| 10 |
+
{ "relation": "inherits", "target_class": "MistralAttention", "component_kind": "attention",
|
| 11 |
+
"parent_class": "LlamaAttention", "overridden": { "methods": ["__init__", "forward"] } },
|
| 12 |
+
{ "relation": "inherits", "target_class": "MistralMLP", "component_kind": "feed_forward",
|
| 13 |
+
"parent_class": "LlamaMLP", "overridden": { "methods": ["__init__"] } },
|
| 14 |
+
{ "relation": "new", "target_class": "MistralForQuestionAnswering", "component_kind": null,
|
| 15 |
+
"parent_class": "MistralPreTrainedModel" }
|
| 16 |
+
// … relation: "inherits" | "new"; buckets: overridden / added / deleted, each { methods?, attrs? }
|
| 17 |
+
],
|
| 18 |
+
// ▲▲▲ the diff_size metric is NOT here — it lives per-node in modular_graph.json (see bottom) ▲▲▲
|
| 19 |
+
|
| 20 |
+
"architecture": { "view": "decoder", "family": "causal_lm", "attention_variant": "GQA", "positional": "rope" },
|
| 21 |
+
"capabilities": { "attention_backends": ["eager", "sdpa", "flash_attention", "flex_attention"],
|
| 22 |
+
"kernels": { "RMSNorm": ["kernels-community/rmsnorm"] } },
|
| 23 |
+
"config": {
|
| 24 |
+
"class_name": "MistralConfig", "module": "transformers.models.mistral.configuration_mistral", "model_type": "mistral",
|
| 25 |
+
"referenced_fields": { "num_hidden_layers": 32 }
|
| 26 |
+
},
|
| 27 |
+
"components": [
|
| 28 |
+
{ "id": "model", "kind": "model", "class_name": "MistralModel", "path_pattern": "model",
|
| 29 |
+
"children": ["embed_tokens", "decoder_layers", "norm"] }
|
| 30 |
+
// … see 01
|
| 31 |
+
],
|
| 32 |
+
"templates": [
|
| 33 |
+
{ "id": "decoder_layer.self_attn", "kind": "attention", "class_name": "MistralAttention",
|
| 34 |
+
"path_pattern": "model.layers.{i}.self_attn", "attributes": { "variant": "GQA", "pattern": "sliding" } }
|
| 35 |
+
// … see 01
|
| 36 |
+
],
|
| 37 |
+
"repeats": [
|
| 38 |
+
{ "id": "decoder_layers", "kind": "symbolic_repeat", "body": "decoder_layer",
|
| 39 |
+
"count_expr": "config.num_hidden_layers", "count": 32, "count_source": "config", "index_symbol": "i",
|
| 40 |
+
"container_path_pattern": "model.layers", "item_path_pattern": "model.layers.{i}",
|
| 41 |
+
"repeated_class_name": "MistralDecoderLayer" }
|
| 42 |
+
],
|
| 43 |
+
"edges": [ { "source": "embed_tokens", "target": "decoder_layers", "kind": "data" } ],
|
| 44 |
+
"dataflow": {
|
| 45 |
+
"source": "observed_forward_meta",
|
| 46 |
+
"input": { "name": "input_ids", "shape": ["B", "S"] },
|
| 47 |
+
"output": { "shape": ["B", "S", "config.hidden_size"] },
|
| 48 |
+
"shapes": { "embed_tokens": { "in": ["B", "S"], "out": ["B", "S", "config.hidden_size"] } }
|
| 49 |
+
},
|
| 50 |
+
"provenance": {
|
| 51 |
+
"config_class": "MistralConfig", "config_module": "transformers.models.mistral.configuration_mistral",
|
| 52 |
+
"model_class": "MistralModel", "model_module": "transformers.models.mistral.modeling_mistral"
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
// Companion library-wide file `modular_graph.json` (one for the whole library, not per model):
|
| 57 |
+
// { "schema_version": "modular-graph-v0",
|
| 58 |
+
// "roots": ["llama", "vit", "clip"],
|
| 59 |
+
// "nodes": { "mistral": { "extends": "llama", "children": ["mixtral"], "root": "llama",
|
| 60 |
+
// "depth": 1, "is_modular": true, "diff_size": 9 } } }
|
| 61 |
+
// → models sharing a `root` are the same lineage (align cleanly for comparison); diff_size = modularity metric.
|
examples/04-full.jsonc
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// 04 — the complete ArchitectureTemplate (all tiers together), lightly annotated.
|
| 2 |
+
// Faithful trimmed copy of artifacts/mistral.json (a modular, GQA, sliding-window decoder LLM).
|
| 3 |
+
// JSONC = JSON + // comments (not machine-parseable as-is); "…" marks omitted repetition.
|
| 4 |
+
// Regenerate the exact file: python utils/architecture_ir/generate_architecture_ir.py --architectures mistral --output-dir out
|
| 5 |
+
{
|
| 6 |
+
"schema_version": "architecture-template-v0",
|
| 7 |
+
"model_type": "mistral",
|
| 8 |
+
|
| 9 |
+
// modular inheritance (diff_size metric lives in modular_graph.json)
|
| 10 |
+
"extends": "llama",
|
| 11 |
+
"patches": [
|
| 12 |
+
{ "relation": "inherits", "target_class": "MistralAttention", "component_kind": "attention",
|
| 13 |
+
"parent_class": "LlamaAttention", "overridden": { "methods": ["__init__", "forward"] } },
|
| 14 |
+
{ "relation": "new", "target_class": "MistralForQuestionAnswering", "component_kind": null,
|
| 15 |
+
"parent_class": "MistralPreTrainedModel" }
|
| 16 |
+
// … other overridden classes (MistralMLP, MistralModel, …)
|
| 17 |
+
],
|
| 18 |
+
|
| 19 |
+
// model-level facts (multimodal reads the text backbone)
|
| 20 |
+
"architecture": {
|
| 21 |
+
"view": "decoder", "family": "causal_lm", "attention_variant": "GQA",
|
| 22 |
+
"positional": "rope", "is_moe": false, "sliding_window": 4096, "tie_word_embeddings": false
|
| 23 |
+
},
|
| 24 |
+
|
| 25 |
+
// what it can do / run with
|
| 26 |
+
"capabilities": {
|
| 27 |
+
"attention_backends": ["eager", "sdpa", "flash_attention", "flex_attention"],
|
| 28 |
+
"attention_patterns": ["sliding"], "attention_schedule": null,
|
| 29 |
+
"task_heads": ["causal_lm", "question_answering", "sequence_classification", "token_classification"],
|
| 30 |
+
"tensor_parallel": true,
|
| 31 |
+
"kernels": { "RMSNorm": ["kernels-community/liger-kernels", "kernels-community/rmsnorm", "kernels-community/mlx_rmsnorm"] }
|
| 32 |
+
},
|
| 33 |
+
|
| 34 |
+
// config identity + the parametric surface (full config NOT serialized)
|
| 35 |
+
"config": {
|
| 36 |
+
"class_name": "MistralConfig", "module": "transformers.models.mistral.configuration_mistral", "model_type": "mistral",
|
| 37 |
+
"referenced_fields": { "num_hidden_layers": 32 },
|
| 38 |
+
"salient_fields": { "hidden_size": 4096, "intermediate_size": 14336, "vocab_size": 32000,
|
| 39 |
+
"num_attention_heads": 32, "num_key_value_heads": 8, "head_dim": 128,
|
| 40 |
+
"max_position_embeddings": 131072, "sliding_window": 4096, "hidden_act": "silu",
|
| 41 |
+
"tie_word_embeddings": false }
|
| 42 |
+
},
|
| 43 |
+
|
| 44 |
+
// nodes outside any repeat body (leaf nodes omit `children`)
|
| 45 |
+
"components": [
|
| 46 |
+
{ "id": "model", "kind": "model", "class_name": "MistralModel", "path_pattern": "model",
|
| 47 |
+
"children": ["embed_tokens", "decoder_layers", "norm", "rotary_emb"] },
|
| 48 |
+
{ "id": "embed_tokens", "kind": "embedding", "class_name": "Embedding", "path_pattern": "model.embed_tokens",
|
| 49 |
+
"attributes": { "num_embeddings": "config.vocab_size", "embedding_dim": "config.hidden_size" } },
|
| 50 |
+
{ "id": "norm", "kind": "normalization", "class_name": "MistralRMSNorm", "path_pattern": "model.norm",
|
| 51 |
+
"attributes": { "norm_type": "rms", "kernel": "RMSNorm" } },
|
| 52 |
+
{ "id": "rotary_emb", "kind": "position", "class_name": "MistralRotaryEmbedding", "path_pattern": "model.rotary_emb",
|
| 53 |
+
"attributes": { "scheme": "rope", "rope_theta": 10000.0, "head_dim": "config.head_dim" } }
|
| 54 |
+
],
|
| 55 |
+
|
| 56 |
+
// the repeated block body, serialized once ({i} = layer index)
|
| 57 |
+
"templates": [
|
| 58 |
+
{ "id": "decoder_layer", "kind": "transformer_block", "class_name": "MistralDecoderLayer",
|
| 59 |
+
"path_pattern": "model.layers.{i}",
|
| 60 |
+
"children": ["decoder_layer.input_layernorm", "decoder_layer.self_attn",
|
| 61 |
+
"decoder_layer.post_attention_layernorm", "decoder_layer.mlp"] },
|
| 62 |
+
{ "id": "decoder_layer.self_attn", "kind": "attention", "class_name": "MistralAttention",
|
| 63 |
+
"path_pattern": "model.layers.{i}.self_attn",
|
| 64 |
+
"children": ["decoder_layer.self_attn.q_proj", "decoder_layer.self_attn.k_proj",
|
| 65 |
+
"decoder_layer.self_attn.v_proj", "decoder_layer.self_attn.o_proj"],
|
| 66 |
+
"attributes": { "variant": "GQA", "n_heads": 32, "n_kv_heads": 8, "head_dim": 128,
|
| 67 |
+
"rope": true, "sliding_window": 4096, "pattern": "sliding" } },
|
| 68 |
+
// GQA: q/o are hidden-sized; k/v are num_kv_heads*head_dim = 1024
|
| 69 |
+
{ "id": "decoder_layer.self_attn.q_proj", "kind": "projection", "class_name": "Linear",
|
| 70 |
+
"path_pattern": "model.layers.{i}.self_attn.q_proj",
|
| 71 |
+
"attributes": { "in_features": "config.hidden_size", "out_features": 4096, "tp": "colwise" } },
|
| 72 |
+
{ "id": "decoder_layer.self_attn.k_proj", "kind": "projection", "class_name": "Linear",
|
| 73 |
+
"path_pattern": "model.layers.{i}.self_attn.k_proj",
|
| 74 |
+
"attributes": { "in_features": "config.hidden_size", "out_features": 1024, "tp": "colwise" } },
|
| 75 |
+
// … v_proj (1024, colwise), o_proj (4096 → config.hidden_size, rowwise)
|
| 76 |
+
{ "id": "decoder_layer.mlp", "kind": "feed_forward", "class_name": "MistralMLP",
|
| 77 |
+
"path_pattern": "model.layers.{i}.mlp",
|
| 78 |
+
"children": ["decoder_layer.mlp.gate_proj", "decoder_layer.mlp.up_proj", "decoder_layer.mlp.down_proj"],
|
| 79 |
+
"attributes": { "hidden_size": 4096, "intermediate_size": 14336, "activation": "silu" } },
|
| 80 |
+
{ "id": "decoder_layer.mlp.gate_proj", "kind": "projection", "class_name": "Linear",
|
| 81 |
+
"path_pattern": "model.layers.{i}.mlp.gate_proj",
|
| 82 |
+
"attributes": { "in_features": "config.hidden_size", "out_features": "config.intermediate_size", "tp": "colwise" } },
|
| 83 |
+
// … up_proj (colwise), down_proj (config.intermediate_size → config.hidden_size, rowwise)
|
| 84 |
+
{ "id": "decoder_layer.input_layernorm", "kind": "normalization", "class_name": "MistralRMSNorm",
|
| 85 |
+
"path_pattern": "model.layers.{i}.input_layernorm", "attributes": { "norm_type": "rms", "kernel": "RMSNorm" } }
|
| 86 |
+
// … post_attention_layernorm
|
| 87 |
+
],
|
| 88 |
+
|
| 89 |
+
// 32 identical layers collapsed to one symbolic entry, count kept parametric
|
| 90 |
+
"repeats": [
|
| 91 |
+
{ "id": "decoder_layers", "kind": "symbolic_repeat", "body": "decoder_layer",
|
| 92 |
+
"count_expr": "config.num_hidden_layers", "count": 32, "count_source": "config", "index_symbol": "i",
|
| 93 |
+
"container_path_pattern": "model.layers", "item_path_pattern": "model.layers.{i}",
|
| 94 |
+
"repeated_class_name": "MistralDecoderLayer" }
|
| 95 |
+
],
|
| 96 |
+
|
| 97 |
+
// coarse dataflow. kinds: data | residual | mask | position | cross_attention | route | cache_read | cache_write
|
| 98 |
+
"edges": [
|
| 99 |
+
{ "source": "embed_tokens", "target": "decoder_layers", "kind": "data" },
|
| 100 |
+
{ "source": "decoder_layers", "target": "norm", "kind": "data" },
|
| 101 |
+
// block-level flow (pre-norm), re-grounded from the observed forward:
|
| 102 |
+
{ "source": "decoder_layer.input_layernorm", "target": "decoder_layer.self_attn", "kind": "data", "provenance": "observed_forward" },
|
| 103 |
+
{ "source": "decoder_layer.self_attn", "target": "decoder_layer.post_attention_layernorm", "kind": "data", "provenance": "observed_forward" },
|
| 104 |
+
{ "source": "decoder_layer.post_attention_layernorm", "target": "decoder_layer.mlp", "kind": "data", "provenance": "observed_forward" },
|
| 105 |
+
// intra-module fan-out/fan-in (role-based; q/k/v parallel, not chained):
|
| 106 |
+
{ "source": "decoder_layer.self_attn", "target": "decoder_layer.self_attn.q_proj", "kind": "data", "provenance": "intra_module" },
|
| 107 |
+
{ "source": "decoder_layer.self_attn.q_proj", "target": "decoder_layer.self_attn.o_proj", "kind": "data", "provenance": "intra_module" },
|
| 108 |
+
{ "source": "decoder_layer.mlp.gate_proj", "target": "decoder_layer.mlp.down_proj", "kind": "data", "provenance": "intra_module" },
|
| 109 |
+
{ "source": "decoder_layer", "target": "decoder_layer.self_attn", "kind": "residual" },
|
| 110 |
+
{ "source": "rotary_emb", "target": "decoder_layer.self_attn", "kind": "position" },
|
| 111 |
+
{ "source": "input:attention_mask", "target": "decoder_layer.self_attn", "kind": "mask" },
|
| 112 |
+
{ "source": "state:kv_cache", "target": "decoder_layer.self_attn", "kind": "cache_read" },
|
| 113 |
+
{ "source": "decoder_layer.self_attn", "target": "state:kv_cache", "kind": "cache_write" }
|
| 114 |
+
],
|
| 115 |
+
|
| 116 |
+
// observed tensor shapes (symbolized), keyed by node id; order lives in edges
|
| 117 |
+
"dataflow": {
|
| 118 |
+
"source": "observed_forward_meta",
|
| 119 |
+
"input": { "name": "input_ids", "shape": ["B", "S"] },
|
| 120 |
+
"output": { "shape": ["B", "S", "config.hidden_size"] },
|
| 121 |
+
"shapes": {
|
| 122 |
+
"embed_tokens": { "in": ["B", "S"], "out": ["B", "S", "config.hidden_size"] },
|
| 123 |
+
"decoder_layer.self_attn": { "in": ["B", "S", "config.hidden_size"], "out": ["B", "S", "config.hidden_size"] }
|
| 124 |
+
// … norm, mlp, the other block children
|
| 125 |
+
}
|
| 126 |
+
},
|
| 127 |
+
|
| 128 |
+
// which classes this IR was introspected from (resolution strategy is invariant → in SPEC, not here)
|
| 129 |
+
"provenance": {
|
| 130 |
+
"config_class": "MistralConfig", "config_module": "transformers.models.mistral.configuration_mistral",
|
| 131 |
+
"model_class": "MistralModel", "model_module": "transformers.models.mistral.modeling_mistral"
|
| 132 |
+
}
|
| 133 |
+
}
|