用途:为任意 HuggingFace decoder-only LLM 生成出版级纵向架构图,风格参照 Sebastian Raschka 的 LLM Architecture Gallery,每个子模块标注参数量公式及加载配置下的具体数值。适合论文或博客配图,以及可视化 DeepSeek-V4-Flash、MLA、MoE、稀疏注意力、MTP 等结构。若只需显存/并行度数字,应改用 megatron-memory-estimator。
主要能力:extract_arch.py 先尝试 transformers.AutoConfig,无法识别 model_type 时回退到 huggingface_hub 原始 JSON;按配置字段规则识别架构家族(mha、gqa、mla、dsv4)及正交标志(MoE、哈希路由、共享专家、MTP、tied LM head、first_k_dense_replace);按家族闭式公式计算参数量并输出 arch.json;render_tikz.py 结合 Jinja2 模板生成 TikZ;compile.sh 用 xelatex 编译两次再经 pdftocairo 转 300dpi PNG,无 XeTeX 时回退 pdflatex。
使用方式:cd hf-architecture-tikz/ 后依次运行:uv run python scripts/extract_arch.py deepseek-ai/DeepSeek-V4-Flash --output examples/deepseek-v4-flash/arch.json;uv run python scripts/render_tikz.py examples/deepseek-v4-flash/arch.json --output examples/deepseek-v4-flash/deepseek-v4-flash.tex;bash scripts/compile.sh examples/deepseek-v4-flash/deepseek-v4-flash.tex。自定义代码模型需显式加 --trust-remote-code;本地配置可传 /path/to/config.json。
限制:依赖 Python 的 transformers、huggingface_hub、jinja2(经 uv run),系统需 xelatex 或 pdflatex 及 poppler 的 pdftocairo。完整展开加侧注与 MTP 分支通常高达 4–6k 像素,可用 --no-mtp 缩短。tie_word_embeddings=True 时嵌入表不重复计数。mbridge 非必需,仅用于交叉核对 V3/Qwen 计数。其余细节暂未提供。