Skip to main content

Unfold any HuggingFace transformer into an interactive architecture diagram, inline in Jupyter.

Project description

MODEL UNFOLDER

your one click model unfolder

from model_unfolder import unfold
unfold("meta-llama/Meta-Llama-3-8B")

Meta-Llama-3-8B architecture diagram


Install

pip install model-unfolder

# for local development
pip install -e .
pip install transformers   # only required to load by model ID

Three ways to call it

from model_unfolder import unfold

# 1) by HuggingFace model ID — only config.json is downloaded, never weights
unfold("meta-llama/Meta-Llama-3-8B")
unfold("deepseek-ai/DeepSeek-V3")

# 2) from a transformers AutoConfig
from transformers import AutoConfig
unfold(AutoConfig.from_pretrained("Qwen/Qwen2.5-7B", trust_remote_code=True))

# 3) from a raw config.json dict — no transformers install needed
import json
unfold(json.load(open("config.json")))

Built on transformers

Pass a model ID and unfold calls transformers.AutoConfig.from_pretrained(model_id) under the hood (parser.py). It only retries with trust_remote_code=True when Transformers says the config requires remote code.

Auth-token from your environment

Gated models (Llama-3, Mistral, Gemma, …) need a HuggingFace token. unfold reuses whatever transformers / huggingface_hub already see:

# Either set an env var
export HF_TOKEN="hf_xxxxxxxx"            # also accepted: HUGGING_FACE_HUB_TOKEN

# or use the CLI cache (persists across sessions)
huggingface-cli login

# or load a .env in your notebook
# >>> from dotenv import load_dotenv; load_dotenv()

No extra config in model_unfolder itself.

Save / export

diagram = unfold(cfg)
diagram.save("model.html")   # standalone interactive HTML
diagram.save("model.json")   # IR (no rendering)
diagram.param_count()        # {"total": ..., "active": ..., "per_layer": [...]}
diagram.to_ir()              # full IR dict

Param estimates are close to published numbers — DeepSeek-V3 reports ~675B (~41B active), Llama-3-8B reports 8.03B.

Live demos

Open in any browser to interact (click blocks, expand sub-blocks, toggle layer types):

Model Highlights Demo
Llama-3-8B GQA + dense baseline examples/llama-3-8b.html
Mistral-7B-v0.3 GQA + dense, 32k context examples/mistral-7b-v0.3.html
DeepSeek-V3 MLA + dense → MoE phase change examples/deepseek-v3.html
Kimi K2 MLA + 384-expert MoE, ~1T params examples/kimi-k2.html

Supported architectures

Family Adapter Notes
DeepSeek-V2 / V3 / Kimi K2 families/deepseek.py MLA + dense → MoE phase change
Llama / Mistral / Qwen2 / Qwen3 / Phi-3 families/llama.py GQA / MQA / MHA + dense FFN
Gemma 4 families/gemma4.py sliding/global layers, KV sharing, PLE

License

Apache 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

model_unfolder-0.2.0.tar.gz (49.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

model_unfolder-0.2.0-py3-none-any.whl (58.1 kB view details)

Uploaded Python 3

File details

Details for the file model_unfolder-0.2.0.tar.gz.

File metadata

  • Download URL: model_unfolder-0.2.0.tar.gz
  • Upload date:
  • Size: 49.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for model_unfolder-0.2.0.tar.gz
Algorithm Hash digest
SHA256 27ab901e3ff97db6a03d94a8096f24a13aa94d3b767e78a3a2c0cb2ec31cdc87
MD5 9818f6d188f67d9f83f34de8f275944b
BLAKE2b-256 dac8b443caab0104f398d2a2d5de2acf04b22711fdeb605a8ba0c396ec19debc

See more details on using hashes here.

Provenance

The following attestation bundles were made for model_unfolder-0.2.0.tar.gz:

Publisher: release.yml on SoumilB7/unfold

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file model_unfolder-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: model_unfolder-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 58.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for model_unfolder-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e88d679eb8902b9e82a197e36352a2d5fe7bf931776ee135a2084c659da6fd8
MD5 f1504f51863ec1fb4d5b529b698acc3f
BLAKE2b-256 0328634c875651974ff24a9e6b76a334a35730543f57fd34d51d40bbaadf9c4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for model_unfolder-0.2.0-py3-none-any.whl:

Publisher: release.yml on SoumilB7/unfold

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page