Coverage for transformer_lens/tools/model_registry/generate_report.py: 7%
113 statements
« prev ^ index » next coverage.py v7.10.1, created at 2026-11-25 00:28 +0000
« prev ^ index » next coverage.py v7.10.1, created at 2026-11-25 00:28 +0000
1#!/usr/bin/env python3
2"""Generate a markdown report of supported and unsupported models.
4This script generates a comprehensive report showing:
5- All supported model IDs grouped by architecture
6- Total count of supported models
7- Unsupported architectures with model counts and descriptions
9Usage:
10 python -m transformer_lens.tools.model_registry.generate_report
11 python -m transformer_lens.tools.model_registry.generate_report --output custom_report.md
12 python -m transformer_lens.tools.model_registry.generate_report --help
13"""
15import argparse
16from datetime import datetime
17from pathlib import Path
19from .api import (
20 get_registry_stats,
21 get_supported_architectures,
22 get_supported_models,
23 get_unsupported_architectures,
24)
26# Descriptions of common architectures (both supported and unsupported)
27ARCHITECTURE_DESCRIPTIONS: dict[str, str] = {
28 # Supported architectures
29 "AfmoeForCausalLM": "Arcee AI's Trinity MoE with sandwich norms, gated attention, and token-choice routing",
30 "ArceeForCausalLM": "Arcee AI's AFM, a Llama-style decoder with an ungated squared-ReLU (ReLU^2) MLP",
31 "ASTForAudioClassification": "MIT's Audio Spectrogram Transformer model for audio classification",
32 "GPT2LMHeadModel": "OpenAI's GPT-2 decoder-only transformer for causal language modeling",
33 "GPTNeoForCausalLM": "EleutherAI's GPT-Neo, an open-source GPT-3-like model",
34 "GPTNeoXForCausalLM": "EleutherAI's GPT-NeoX architecture used in Pythia models",
35 "GPTJForCausalLM": "EleutherAI's GPT-J 6B parameter model",
36 "LlamaForCausalLM": "Meta's LLaMA architecture, basis for many open models",
37 "Llama4ForCausalLM": "Meta's Llama 4 text decoder with interleaved MoE and NoPE layers",
38 "Llama4ForConditionalGeneration": "Meta's Llama 4 Scout/Maverick vision-language model",
39 "LongT5ForConditionalGeneration": "Google's LongT5 with local or transient-global encoder attention",
40 "LEDForConditionalGeneration": "AllenAI's Longformer Encoder-Decoder for long documents",
41 "Florence2ForConditionalGeneration": "Microsoft's Florence-2 vision-language model with DaViT backbone and BART text stack",
42 "Lfm2ForCausalLM": "LiquidAI's LFM2 hybrid convolution/attention dense model",
43 "LLaDAModelLM": "GSAI's bidirectional masked-diffusion language model (single-forward support)",
44 "Lfm2MoeForCausalLM": "LiquidAI's LFM2 hybrid convolution/attention Mixture of Experts model",
45 "MistralForCausalLM": "Mistral AI's efficient 7B parameter model with sliding window attention",
46 "Mistral3ForConditionalGeneration": "Mistral AI's Mistral-Small VLM (Pixtral tower + Mistral decoder)",
47 "MixtralForCausalLM": "Mistral AI's Mixture of Experts model",
48 "MuseGlimmerForConditionalGeneration": "Meta's Muse Glimmer VLM (gated QK-norm attention, interleaved NoPE layers)",
49 "GemmaForCausalLM": "Google's Gemma lightweight open model family",
50 "Gemma2ForCausalLM": "Google's Gemma 2 with improved architecture",
51 "Gemma3ForCausalLM": "Google's Gemma 3 latest generation",
52 "Gemma3nForConditionalGeneration": "Google's Gemma 3n efficient tri-modal model (text-only support)",
53 "Gemma4ForConditionalGeneration": "Google's Gemma 4 multimodal model family (text-only support)",
54 "Gemma4UnifiedForConditionalGeneration": "Google's Gemma 4 unified encoder-free multimodal model (text-only support)",
55 "Gemma4ForCausalLM": "Google's Gemma 4 bare text decoder",
56 "DeepseekV4ForCausalLM": "DeepSeek V4 with mHC residual streams and hybrid compressed attention",
57 "GlmMoeDsaForCausalLM": "Z.ai's GLM-5 MoE model with DeepSeek Sparse Attention",
58 "Glm4MoeForCausalLM": "Z.ai's GLM-4.5/4.6/4.7 sparse Mixture-of-Experts causal LM",
59 "Glm4MoeLiteForCausalLM": "Z.ai's GLM-4.7-Flash MoE with DeepSeek-style latent attention",
60 "Qwen2ForCausalLM": "Alibaba's Qwen2 multilingual model",
61 "Qwen2MoeForCausalLM": "Alibaba's Qwen2 sparse Mixture-of-Experts model with shared experts",
62 "Qwen2_5_VLForConditionalGeneration": "Alibaba's Qwen2.5-VL vision-language model (windowed ViT + mRoPE decoder)",
63 "Qwen3VLForConditionalGeneration": "Alibaba's Qwen3-VL with DeepStack multi-level visual injection",
64 "Qwen3VLMoeForConditionalGeneration": "Alibaba's Qwen3-VL-MoE (DeepStack + sparse expert routing)",
65 "Qwen3ForCausalLM": "Alibaba's Qwen3 latest generation",
66 "Qwen3_5ForConditionalGeneration": "Alibaba's Qwen3.5 vision-language model",
67 "Qwen3_5MoeForCausalLM": "Alibaba's Qwen3.5-MoE hybrid linear-attention sparse-MoE text model",
68 "Qwen3_5MoeForConditionalGeneration": "Alibaba's Qwen3.5-MoE vision-language model",
69 "BloomForCausalLM": "BigScience's BLOOM multilingual model",
70 "OPTForCausalLM": "Meta's Open Pre-trained Transformer",
71 "PhiForCausalLM": "Microsoft's Phi small language model",
72 "Phi3ForCausalLM": "Microsoft's Phi-3 improved small model",
73 "PhiMoEForCausalLM": "Microsoft's Phi sparse Mixture of Experts model",
74 "FalconForCausalLM": "TII's Falcon model series",
75 "FalconH1ForCausalLM": "TII's Falcon-H1 parallel attention + Mamba-2 hybrid series",
76 "JambaForCausalLM": "AI21's Jamba interleaved attention + Mamba-1 hybrid with optional MoE",
77 "OlmoForCausalLM": "Allen AI's OLMo open language model",
78 "Olmo2ForCausalLM": "Allen AI's OLMo 2 with improved training",
79 "Olmo3ForCausalLM": "Allen AI's OLMo 3 latest generation",
80 "OlmoeForCausalLM": "Allen AI's OLMoE Mixture of Experts model",
81 "OlmoHybridForCausalLM": "Allen AI's OLMo Hybrid (GatedDeltaNet linear attention + full attention)",
82 "StableLmForCausalLM": "Stability AI's StableLM model",
83 "SmolLM3ForCausalLM": "Hugging Face's SmolLM3 compact open model with NoPE layers",
84 "T5ForConditionalGeneration": "Google's T5 encoder-decoder model (partial support)",
85 "T5WithLMHeadModel": "Legacy T5 class name on old google-t5 checkpoints (t5-3b, t5-11b)",
86 "T5GemmaForConditionalGeneration": "Google's T5Gemma encoder-decoder model with Gemma-style RoPE, GQA, and gated MLP",
87 "BambaForCausalLM": "IBM's Bamba hybrid Mamba-2 + attention decoder",
88 "BartForConditionalGeneration": "Facebook's BART encoder-decoder model",
89 "M2M100ForConditionalGeneration": "Meta's M2M100 / NLLB-200 multilingual translation encoder-decoder",
90 "MarianMTModel": "Helsinki-NLP's Marian opus-mt translation encoder-decoder",
91 "OpenAIGPTLMHeadModel": "The original OpenAI GPT-1 decoder (post-norm, no final LN)",
92 "SeedOssForCausalLM": "ByteDance's Seed-OSS Llama-layout decoder with config-gated biases",
93 "NemotronForCausalLM": "NVIDIA's dense Nemotron/Minitron decoder (LayerNorm1P, squared-ReLU MLP)",
94 "BloomModel": "Headless Bloom checkpoints (loads as BloomForCausalLM with tied embeddings)",
95 "BertLMHeadModel": "BERT with a causal LM head (decoder-style BERT; same module tree as BertForMaskedLM)",
96 "RobertaForMaskedLM": "RoBERTa with masked language modeling head",
97 "Idefics3ForConditionalGeneration": "HuggingFace's Idefics3/SmolVLM vision-language model (granite-docling)",
98 "Qwen2AudioForConditionalGeneration": "Alibaba's Qwen2-Audio (Whisper-style encoder + Qwen2 decoder)",
99 "Ernie4_5ForCausalLM": "Baidu's dense ERNIE 4.5 Llama-layout decoder",
100 "Ernie4_5_MoeForCausalLM": "Baidu's ERNIE 4.5 MoE (shared experts, dense prefix, interleaved RoPE)",
101 "GlmForCausalLM": "Z.ai's dense GLM-4 decoder (interleaved partial RoPE, joint gate_up MLP)",
102 "Glm4ForCausalLM": "Z.ai's GLM-4-0414 / GLM-Z1 decoder with sandwich norms",
103 "Glm4vForConditionalGeneration": "Z.ai's GLM-4V / GLM-4.1V reasoning vision-language model",
104 "GlmAsrForConditionalGeneration": "Z.ai's GLM-ASR speech recognizer (audio encoder + Llama decoder)",
105 "Starcoder2ForCausalLM": "BigCode's StarCoder2 code model (LayerNorm, biased projections)",
106 "BitNetForCausalLM": "Microsoft's BitNet b1.58 (llama layout with attn/ffn sub-layer norms)",
107 "Exaone4ForCausalLM": "LG AI Research's EXAONE 4.0 (post-norms in residual, per-head QK-norm, hybrid sliding attention)",
108 "BlenderbotForConditionalGeneration": "Meta's Blenderbot dialogue encoder-decoder (asymmetric stacks)",
109 "MiniMaxM2ForCausalLM": "MiniMax's M2 sparse-MoE decoder with sigmoid routing",
110 "ExaoneForCausalLM": "LG AI Research's EXAONE-3.x Korean-English decoder (remote code)",
111 "FalconMambaForCausalLM": "TII's FalconMamba pure-SSM decoder (Mamba-1 with B/C/dt RMS)",
112 "T5Gemma2ForConditionalGeneration": "Google's T5Gemma2 multimodal encoder-decoder model with merged self+cross decoder attention, QK-norm, and dual RoPE (text-only bridge support)",
113 "HrmTextForCausalLM": "Sapient Intelligence's HRM-Text hierarchical two-timescale recurrent model",
114 "BD3LM": "Kuleshov Group's Block Diffusion Language Model (ICLR 2025) for masked text generation",
115 "DreamModel": "HKU-NLP's Dream 7B discrete-diffusion LM (Qwen2.5-based, bidirectional; also Apple DiffuCoder)",
116 "AudioFlamingo3ForConditionalGeneration": "NVIDIA Audio Flamingo 3 audio LALM (Whisper tower + Qwen2.5 LM)",
117 "Emu3ForConditionalGeneration": "BAAI Emu3 unified next-token text+image generation (VQ tokens in a shared vocab)",
118 "FlexOlmoForCausalLM": "AllenAI FlexOlmo federated MoE (merged OLMo-2 experts, inference-time data opt-out)",
119 "MusicFlamingoForConditionalGeneration": "NVIDIA Music Flamingo / Audio Flamingo Next (AF3 + temporal rotary conditioning)",
120 "GiddForDiffusionLM": "GIDD uniform-noise diffusion LM with self-correction (only open non-masked dLM at scale)",
121 "HyenaDNAForCausalLM": "HazyResearch HyenaDNA genomic LM (attention-free Hyena long-conv operator)",
122 "LLaDA2MoeModelLM": "Ant Group LLaDA 2.x masked block-diffusion LM on a DeepSeek-V3-style MoE decoder",
123 "JetMoeForCausalLM": "MIT-IBM JetMoE, the only open at-scale Mixture-of-Attention-heads model",
124 "LagunaForCausalLM": "poolside Laguna coding MoE (heterogeneous per-layer head counts, softplus attention gating)",
125 "ModernBertDecoderForCausalLM": "JHU Ettin decoders (ModernBERT recipe run causally; paired encoder/decoder science suite)",
126 "Jais2ForCausalLM": "G42/Inception Jais 2 Arabic-English family (Nemotron-shaped LN decoder)",
127 "Ministral3ForCausalLM": "Mistral AI Ministral 3 edge models (pure Mistral shape)",
128 "VaultGemmaForCausalLM": "Google VaultGemma, the only fully DP-SGD-pretrained open LLM (Gemma 2 minus post-norms)",
129 "YoutuForCausalLM": "Tencent Youtu-LLM: laptop-scale dense Multi-head Latent Attention (DeepSeek-V2 MLA, all layers dense)",
130 "SwitchTransformersForConditionalGeneration": "Google Switch Transformer, the foundational top-1 capacity-routed MoE (encoder-decoder)",
131 "RwkvForCausalLM": "BlinkDL RWKV-4 WKV linear-attention RNN (Pythia-parallel Pile suite)",
132 "NanoChatForCausalLM": "Karpathy's nanochat education-stack decoder (weightless norms, relu^2 MLP, capped logits)",
133 "HunYuanDenseV1ForCausalLM": "Tencent's open source decoder models",
134 "ViTModel": "Vision Transformer (bare encoder, no classification head)",
135 "ViTForImageClassification": "Vision Transformer with an image classification head",
136 "DeiTModel": "Data-efficient Image Transformer (bare encoder)",
137 "DeiTForImageClassification": "DeiT with a single CLS-token classification head",
138 "Wav2Vec2Model": "Facebook's Wav2Vec 2.0 for speech",
139 "HubertModel": "Facebook's HuBERT for speech",
140 "WhisperForConditionalGeneration": "OpenAI's Whisper speech recognition encoder-decoder (log-mel audio encoder, text decoder)",
141 "Cohere2ForCausalLM": "Cohere's Command-A architecture with interleaved sliding-window RoPE and full-attention NoPE layers",
142 "OuroForCausalLM": "ByteDance's Ouro looped language model (LoopLM) with weight-shared iterated depth",
143 "RavenForCausalLM": "tomg-group-umd's Huginn depth-recurrent decoder (prelude / weight-tied recurrent core / coda) with runtime recurrence count",
144 "RWKV7ForCausalLM": 'fla-hub\'s RWKV-7 ("Goose") attention-free recurrent decoder with generalized-delta-rule time-mixing and squared-ReLU channel-mixing',
145 # Unsupported architectures
146 "BertModel": "Google's BERT bidirectional encoder for understanding tasks",
147 "BertForMaskedLM": "BERT with masked language modeling head",
148 "BertForSequenceClassification": "BERT fine-tuned for classification",
149 "RobertaModel": "Facebook's RoBERTa, optimized BERT training",
150 "DistilBertModel": "Distilled version of BERT, 40% smaller",
151 "AlbertModel": "A Lite BERT with parameter sharing",
152 "XLNetLMHeadModel": "Google/CMU's XLNet with permutation language modeling",
153 "ElectraModel": "Google's ELECTRA with replaced token detection",
154 "DebertaModel": "Microsoft's DeBERTa with disentangled attention",
155 "DebertaV2Model": "DeBERTa version 2 with improved architecture",
156 "MPNetModel": "Microsoft's MPNet combining MLM and PLM",
157 "LongformerModel": "Allen AI's Longformer for long documents",
158 "BigBirdModel": "Google's BigBird with sparse attention",
159 "ReformerModel": "Google's Reformer with locality-sensitive hashing",
160 "MBartForConditionalGeneration": "Multilingual BART",
161 "PegasusForConditionalGeneration": "Google's PEGASUS for summarization",
162 "MT5ForConditionalGeneration": "Multilingual T5",
163 "WhisperForConditionalGeneration": "OpenAI's Whisper speech recognition",
164 "CLIPModel": "OpenAI's CLIP vision-language model",
165 "SwinModel": "Microsoft's Swin Transformer for vision",
166 "BeitModel": "Microsoft's BERT pre-training for images",
167 "ConvNextModel": "Facebook's ConvNeXt modernized ConvNet",
168 "SegformerModel": "NVIDIA's SegFormer for segmentation",
169 "SpeechT5Model": "Microsoft's SpeechT5 for speech tasks",
170 "BlipModel": "Salesforce's BLIP vision-language model",
171 "Blip2Model": "Salesforce's BLIP-2 with frozen LLM",
172 "LlavaForConditionalGeneration": "Visual instruction-tuned LLaMA",
173 "GitModel": "Microsoft's GIT for vision-language",
174 "PaliGemmaForConditionalGeneration": "Google's PaliGemma vision-language",
175 "CohereForCausalLM": "Cohere's Command models",
176 "DeepseekForCausalLM": "DeepSeek's open models",
177 "InternLMForCausalLM": "Shanghai AI Lab's InternLM",
178 "BaichuanForCausalLM": "Baichuan's Chinese-focused models",
179 "YiForCausalLM": "01.AI's Yi model series",
180 "OrionForCausalLM": "OrionStar's Orion models",
181 "StarcoderForCausalLM": "BigCode's StarCoder for code",
182 "CodeLlamaForCausalLM": "Meta's Code Llama for programming",
183 "CodeGenForCausalLM": "Salesforce's CodeGen models",
184 "SantacoderForCausalLM": "BigCode's SantaCoder",
185}
188def get_architecture_description(arch_id: str) -> str:
189 """Get a description for an architecture, with fallback."""
190 if arch_id in ARCHITECTURE_DESCRIPTIONS:
191 return ARCHITECTURE_DESCRIPTIONS[arch_id]
193 # Generate a basic description from the name
194 if "ForCausalLM" in arch_id:
195 base = arch_id.replace("ForCausalLM", "")
196 return f"{base} architecture for causal language modeling"
197 elif "ForConditionalGeneration" in arch_id:
198 base = arch_id.replace("ForConditionalGeneration", "")
199 return f"{base} encoder-decoder for conditional generation"
200 elif "ForMaskedLM" in arch_id:
201 base = arch_id.replace("ForMaskedLM", "")
202 return f"{base} with masked language modeling head"
203 elif "ForSequenceClassification" in arch_id:
204 base = arch_id.replace("ForSequenceClassification", "")
205 return f"{base} fine-tuned for sequence classification"
206 elif "Model" in arch_id:
207 base = arch_id.replace("Model", "")
208 return f"{base} base model architecture"
209 else:
210 return "Transformer architecture"
213def generate_report(output_path: Path | None = None) -> str:
214 """Generate the markdown report.
216 Args:
217 output_path: Optional path to write the report. If None, only returns the string.
219 Returns:
220 The generated markdown report as a string.
221 """
222 # Gather data
223 models = get_supported_models()
224 architectures = get_supported_architectures()
225 gaps = get_unsupported_architectures()
226 stats = get_registry_stats()
228 # Group models by architecture
229 models_by_arch: dict[str, list[str]] = {}
230 for model in models:
231 arch = model.architecture_id
232 if arch not in models_by_arch:
233 models_by_arch[arch] = []
234 models_by_arch[arch].append(model.model_id)
236 # Sort models within each architecture
237 for arch in models_by_arch:
238 models_by_arch[arch].sort()
240 # Calculate totals
241 total_supported = len(models)
242 total_unsupported = sum(g.total_models for g in gaps)
243 total_all = total_supported + total_unsupported
245 # Build report
246 lines = []
247 lines.append("# TransformerLens Model Compatibility Report")
248 lines.append("")
249 lines.append(f"*Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}*")
250 lines.append("")
252 # Summary
253 lines.append("## Summary")
254 lines.append("")
255 lines.append(f"| Metric | Count |")
256 lines.append(f"|--------|-------|")
257 lines.append(f"| Supported Models | {total_supported:,} |")
258 lines.append(f"| Supported Architectures | {len(architectures)} |")
259 lines.append(f"| Verified Models | {stats['total_verified']} |")
260 lines.append(f"| Provisional Models | {stats.get('total_provisional', 0)} |")
261 lines.append(f"| Unsupported Architectures | {len(gaps)} |")
262 lines.append(f"| Models in Unsupported Architectures | {total_unsupported:,} |")
263 lines.append(f"| **Total Potential Models** | **{total_all:,}** |")
264 lines.append("")
266 # Supported models section
267 lines.append("## Supported Models")
268 lines.append("")
269 lines.append(
270 f"TransformerLens supports **{total_supported:,} models** across **{len(architectures)} architectures**."
271 )
272 lines.append("")
274 for arch in sorted(models_by_arch.keys()):
275 model_list = models_by_arch[arch]
276 desc = get_architecture_description(arch)
277 lines.append(f"### {arch}")
278 lines.append("")
279 lines.append(f"*{desc}*")
280 lines.append("")
281 lines.append(f"**{len(model_list)} models:**")
282 lines.append("")
283 for model_id in model_list:
284 model_entry = next((m for m in models if m.model_id == model_id), None)
285 if model_entry and model_entry.status == 1:
286 badge = " ✓"
287 elif model_entry and model_entry.status == 4:
288 badge = " ⚠"
289 else:
290 badge = ""
291 lines.append(f"- `{model_id}`{badge}")
292 lines.append("")
294 # Unsupported architectures section
295 lines.append("## Unsupported Architectures")
296 lines.append("")
297 lines.append(
298 f"The following **{len(gaps)} architectures** are not yet supported by TransformerLens,"
299 )
300 lines.append(f"representing **{total_unsupported:,} models** on HuggingFace.")
301 lines.append("")
302 lines.append("| Architecture | Models | Description |")
303 lines.append("|--------------|--------|-------------|")
305 for gap in gaps:
306 desc = get_architecture_description(gap.architecture_id)
307 lines.append(f"| `{gap.architecture_id}` | {gap.total_models:,} | {desc} |")
309 lines.append("")
311 # Footer
312 lines.append("---")
313 lines.append("")
314 lines.append(
315 "*Report generated by `python -m transformer_lens.tools.model_registry.generate_report`*"
316 )
317 lines.append("")
318 lines.append("✓ = Verified to work with TransformerLens")
319 lines.append(
320 "⚠ = Provisional (structural check only; not numerically verified against HuggingFace)"
321 )
323 report = "\n".join(lines)
325 # Write to file if path provided
326 if output_path:
327 output_path.write_text(report)
328 print(f"Report written to: {output_path}")
330 return report
333def main():
334 """CLI entry point."""
335 parser = argparse.ArgumentParser(
336 description="Generate a markdown report of TransformerLens model compatibility.",
337 formatter_class=argparse.RawDescriptionHelpFormatter,
338 epilog="""
339Examples:
340 # Generate report to default location (MODEL_COMPATIBILITY_REPORT.md)
341 python -m transformer_lens.tools.model_registry.generate_report
343 # Generate report to custom location
344 python -m transformer_lens.tools.model_registry.generate_report -o my_report.md
346 # Print report to stdout only
347 python -m transformer_lens.tools.model_registry.generate_report --stdout
348""",
349 )
350 parser.add_argument(
351 "-o",
352 "--output",
353 type=Path,
354 default=None,
355 help="Output file path (default: MODEL_COMPATIBILITY_REPORT.md in current directory)",
356 )
357 parser.add_argument(
358 "--stdout",
359 action="store_true",
360 help="Print report to stdout instead of writing to file",
361 )
363 args = parser.parse_args()
365 if args.stdout:
366 report = generate_report()
367 print(report)
368 else:
369 output_path = args.output or Path("MODEL_COMPATIBILITY_REPORT.md")
370 generate_report(output_path)
373if __name__ == "__main__": 373 ↛ 374line 373 didn't jump to line 374 because the condition on line 373 was never true
374 main()