Metadata-Version: 2.4
Name: tensorplot-rs
Version: 0.1.0
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Rust
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Visualization
License-File: LICENSE
Summary: Neural network architecture diagrams for papers — CNNs to LLMs (TikZ, SVG, PNG, PDF).
Keywords: neural-network,diagram,tikz,svg,pdf,llm,onnx,cli
Home-Page: https://github.com/kaanrkaraman/tensorplot
Author-email: Recep Kaan Karaman <kaanrkaraman@gmail.com>
License-Expression: MIT
Requires-Python: >=3.9
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://github.com/kaanrkaraman/tensorplot
Project-URL: Issues, https://github.com/kaanrkaraman/tensorplot/issues
Project-URL: Repository, https://github.com/kaanrkaraman/tensorplot

# tensorplot

Neural network architecture diagrams for papers — CNNs to LLMs.
Inspired by [PlotNeuralNet](https://github.com/HarisIqbal88/PlotNeuralNet) (MIT), rewritten in Rust,
same visual style, no LaTeX required (but TikZ output when you want it).

![VGG16](https://raw.githubusercontent.com/kaanrkaraman/tensorplot/master/docs/vgg16.png)
![DeepSeek-V3 from its config.json](https://raw.githubusercontent.com/kaanrkaraman/tensorplot/master/docs/deepseek-v3.png)

## Install

```sh
cargo install tensorplot-rs       # crates.io
uv tool install tensorplot-rs     # PyPI (or: pip install tensorplot-rs)
```

Both install the `tensorplot` CLI binary.

## Usage

```sh
tensorplot examples/vgg16.toml -o vgg16.svg              # SVG
tensorplot examples/vgg16.toml -o vgg16.png              # PNG
tensorplot examples/vgg16.toml -o vgg16.pdf              # vector PDF, fonts embedded
tensorplot examples/vgg16.toml -o vgg16.tex              # standalone TikZ (pdflatex)
tensorplot examples/vgg16.toml -o fig.tex --snippet      # bare tikzpicture for \input
tensorplot examples/hf/deepseek-v3.json -o ds.svg        # Hugging Face config.json
tensorplot examples/onnx/tiny-resnet.onnx -o resnet.svg  # ONNX model
```

The snippet needs `\usepackage{tikz}` and `\usetikzlibrary{arrows.meta}` in your preamble.

**Playground:** `docs/playground/` runs the same renderer as WASM in the browser: edit a spec,
open a `.json` / `.onnx`, download SVG or TikZ. Serve it with `python3 -m http.server -d docs`
and open `/playground/`. Rebuild with `docs/playground/build.sh` (needs the
`wasm32-unknown-unknown` target).

## Spec

Layers are laid out left to right; sizes are derived from the dimensions.

```toml
[[layer]]
kind = "conv"            # see kinds below
name = "conv1"           # caption
channels = [64, 64]      # one box per conv
size = 224               # spatial size; conv inherits, pool halves
relu = true              # activation band

[[layer]]
kind = "pool"
```

| kind | needs | draws |
|---|---|---|
| `conv` | `channels`, `size` | one box per channel entry |
| `pool` | `size` (inherited) | attached slab, halves size |
| `fc` | `units` | long bar |
| `softmax` | — | attached bar |
| `embed` | `dim`, optional `seq`, `units` (vocab) | token embedding |
| `norm` | `dim`; `rms = true` for RMSNorm | thin slab |
| `attention` | `heads`, `dim`; `kv_heads` (GQA/MQA), `kv_rank` (MLA) | Q, (latent), K, V, O; box width shows head count |
| `ffn` | `hidden`, `dim`; `act = "swiglu" \| "gelu" \| "relu"` | gate/up/down projections |
| `moe` | `experts`, `hidden`, `dim`; `top_k`, `shared` | router, shared and routed experts, active ones banded |
| `repeat` | `times`, nested `[[layer.layer]]` | dashed frame labelled `×N` |

`dim` and `seq` are inherited like `size`. See `examples/llama3-8b.toml`.

**Graph:** every layer can take

- `id` — reference name (defaults to `name`)
- `from = ["a", "b"]` — inputs (default: previous layer). A second consumer of the same input
  branches onto a new row; several inputs merge (`examples/inception.toml`)
- `skip = ["a"]` — residual: `a`'s output is added to this layer's input, drawn as an arc
  (`examples/resnet18.toml`)
- `row` — explicit vertical offset in cm

Optional per layer: `gap` (cm before the layer), `label` (depth label, `""` hides),
`height` / `depth` / `width` (raw PlotNeuralNet units).

## Importers

- **Hugging Face `config.json`** (decoder-only LLMs): Llama, Mistral/Mixtral, Qwen, DeepSeek
  (MLA, dense-then-MoE layers), GPT-2 key aliases, and multimodal `text_config`.
- **ONNX**: Conv, pooling, Gemm/MatMul, Softmax and LayerNorm become layers; activations add the
  band; `Add` of an identity becomes a skip, other `Add`s and `Concat` merge. Other ops pass
  through. Shapes come from the weight initializers and the graph input; no onnxruntime needed.

