[Pre-Split] LLM architecture theory research consolidation and pytorch experimentation, llm_surgeon python toolkit for performing layer/head surgery and probing intermediate states via pytorch, older react-based LLM surgery/analysis GUI/visualizer, newer Dear Imgui / C++ LLM visual interpretability research tool
0
stars
629
commits
C++
primary language
Jul 14, 2026
updated
[!NOTE] This repo is old, and has been split into four:
Old New Description theory, research llm-research Collection of broad technical LLM theory research, and personal research arcs testing/llm_surgeon llm-surgeon Python lib for performing 'surgical' operations on LLM models to make controlled alterations and observe impact on output testing/gui llm-gui-react Initial React-based app for LLM interpretability research testing/gui_cpp llobotomy (WIP) Improved C++/OpenGL/DearImGui app for LLM interpretability research
A workspace for experimental LLM research using open-source models. Combines theoretical foundations with hands-on local testing — layer surgery, mechanistic probing, and a live visualization dashboard.
theory/)LaTeX document covering Transformer architecture from the original encoder-decoder through modern decoder-only variants (LLaMA). 10 sections: Transformer overview, Tokenization, Embeddings, Positional Encoding, Attention, FFN, Normalization/Residuals, Decoder-Only Shift, Output Head, Full Forward Pass.
theory/build/llm-core-architecture/llm-core-architecture.textheory/llm-core-architecture.pdftheory/visuals/llm-architecture-diagram.html — clickable layers showing tensor shapes and data flow (standalone, no build step)theory/sources/index.json (citation index) + theory/sources/papers/ (local PDFs). All architectural claims grounded in canonical papers.theory/GLOSSARY.md — every technical term used in the workspaceBuild the PDF (automatically archives previous build):
make -C theory all
testing/llm_surgeon/)Python toolkit for layer-level model surgery, probing, and experiment tracking on LLaMA-family models. Loads models via HuggingFace (fp16 or 4-bit quantized).
| Module | Purpose |
|---|---|
surgery | Layer manipulation: remove, reorder, swap, duplicate layers. Attention head surgery: zero, scale, swap heads. Component ablation: zero MLP or attention. Calibration. |
probe | Logit lens (predictions at each layer), hidden state extraction, interventions (scale, zero dims, clamp, noise, replace, project out directions) |
inspect | Block influence scoring, magnitude analysis, sublayer decomposition, weight SVD, attention entropy, residual stream norms |
verify | Structural validation after surgery (layer count, embedding dims, lm_head consistency) |
benchmark | Perplexity evaluation, downstream task eval (via lm_eval), generation comparison across ollama models |
tracking | SQLite-backed experiment database — log surgery ops, metrics, generation samples |
recipe | YAML-based experiment definitions: surgery steps, analysis, evaluation, export pipeline |
export | Save HuggingFace checkpoints, convert to GGUF, register with ollama |
gguf_reader | Load GGUF files back into HuggingFace models: dequantize tensors, build config, reverse Q/K head permutation, reconstruct tokenizer |
llama_engine | Native llama.cpp wrapper: tokenize, logits, streaming generate with sampling, perplexity, HF→GGUF F16 exporter |
cd testing
python3 -m venv .venv
source .venv/bin/activate
# Install torch — pick one:
pip install torch --index-url https://download.pytorch.org/whl/cu128 # CUDA 12.8
pip install torch --index-url https://download.pytorch.org/whl/cu124 # CUDA 12.4
pip install torch --index-url https://download.pytorch.org/whl/cpu # CPU only
pip install -e ".[dev]"
Models are downloaded from HuggingFace on first use and cached in testing/.cache/models/.
cd testing
source .venv/bin/activate
python examples/quickstart.py
cd testing
source .venv/bin/activate
pytest tests/ -v
testing/gui/)Browser-based dashboard for interactive model experimentation. Load models into GPU memory, run probes, apply surgery, and visualize results in real time.
Browser (React/Vite/TypeScript)
|
|-- REST --> FastAPI --> SessionManager --> llm_surgeon
|-- WebSocket --> streaming probe results via on_layer callbacks
|
Backend holds models in GPU memory across operations
# Install GUI backend dependencies
cd testing
pip install -e ".[gui]"
# Install frontend dependencies
cd gui/frontend
npm install
./testing/gui/run.sh
Opens at http://localhost:5173 (frontend) with backend on 127.0.0.1:8000. Local only.
run.sh runs npm install automatically, but running it manually first avoids a wait on first launch.
| Layer | Stack |
|---|---|
| Backend | FastAPI, uvicorn, Python 3.10+ |
| Frontend | React 18, TypeScript, Vite, Zustand |
| Visualization | D3.js |
| Communication | REST (session/surgery/inspect), WebSocket (logit lens, generate, intervene) |
cd testing
source .venv/bin/activate
pytest gui/tests/ -v
research/)Experimental findings, anomalies, and hypotheses from model surgery experiments.
research/README.md — abstract index of research arcs (focused, multi-observation investigations), plus the conventions for observations / sessions / plans / figures.research/arcs/<slug>/) — one directory per investigation, each with its own README.md, observations/ (+ figures/), sessions/, and plans/. The flagship is arcs/nla-verbalizer/: a two-week NLA interpretability arc on Qwen2.5-7B layer 20 (Anthropic-released NLAs applied to a local open-source model) — research direction with verbatim transcript quotes, honestly-attributed collaboration mode, scope-qualified findings, methodology limitations, and filed next-paths.research/observations/) — landing bin for dated findings not yet part of an arc; promote to an arc when several cohere.research/archive/) — retired / pre-arc material.YYYY-MM-DD-<descriptive-slug>.mdllm/
theory/ # LLM architecture theory (LaTeX + visuals)
build/ # LaTeX source
sources/ # Citation index + paper PDFs
visuals/ # Interactive HTML diagrams
GLOSSARY.md # Term definitions
testing/
llm_surgeon/ # Python surgical toolkit (8 modules)
tests/ # pytest suite for llm_surgeon
gui/ # Live probe dashboard
backend/ # FastAPI + SessionManager + routes
frontend/ # React/Vite/TypeScript + D3 visualizations
tests/ # Backend API tests
run.sh # Start both servers
.cache/ # Gitignored runtime data
models/ # HuggingFace model downloads
outputs/ # Modified model variants from experiments
experiments/ # Experiment definitions + SQLite database
prompts/ # Prompt templates
lib/ # External libraries (llama.cpp, GPU-built)
research/ # Observations and findings
docs/ # Design specs
Python (in testing/.venv):
torch>=2.0
transformers>=4.40
accelerate>=0.27
bitsandbytes>=0.43
pyyaml>=6.0
sentencepiece>=0.1.99
requests
pytest>=8.0 # pip install -e ".[dev]"
fastapi>=0.100 # pip install -e ".[gui]"
uvicorn[standard]>=0.20 # pip install -e ".[gui]"
Node (in testing/gui/frontend):
react, react-dom, d3, zustand, vite, typescript
System:
lib/llama.cpp, built with CUDA)Tested on RTX 2080 (8GB VRAM). Two 4-bit quantized TinyLlama models fit comfortably for A/B comparison. OpenLLaMA 3B is tighter but works single-session.
Copyright (C) 2026 Michael Lannum
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License.
See LICENSE for the full text.
629 commits
C++
41.7%
TeX
28.5%
Python
19.9%
TypeScript
8.7%
[Pre-Split] LLM architecture theory research consolidation and pytorch experimentation, llm_surgeon python toolkit for performing layer/head surgery and probing intermediate states via pytorch, older react-based LLM surgery/analysis GUI/visualizer, newer Dear Imgui / C++ LLM visual interpretability research tool
0
stars
629
commits
C++
primary language
Jul 14, 2026
updated
[!NOTE] This repo is old, and has been split into four:
Old New Description theory, research llm-research Collection of broad technical LLM theory research, and personal research arcs testing/llm_surgeon llm-surgeon Python lib for performing 'surgical' operations on LLM models to make controlled alterations and observe impact on output testing/gui llm-gui-react Initial React-based app for LLM interpretability research testing/gui_cpp llobotomy (WIP) Improved C++/OpenGL/DearImGui app for LLM interpretability research
A workspace for experimental LLM research using open-source models. Combines theoretical foundations with hands-on local testing — layer surgery, mechanistic probing, and a live visualization dashboard.
theory/)LaTeX document covering Transformer architecture from the original encoder-decoder through modern decoder-only variants (LLaMA). 10 sections: Transformer overview, Tokenization, Embeddings, Positional Encoding, Attention, FFN, Normalization/Residuals, Decoder-Only Shift, Output Head, Full Forward Pass.
theory/build/llm-core-architecture/llm-core-architecture.textheory/llm-core-architecture.pdftheory/visuals/llm-architecture-diagram.html — clickable layers showing tensor shapes and data flow (standalone, no build step)theory/sources/index.json (citation index) + theory/sources/papers/ (local PDFs). All architectural claims grounded in canonical papers.theory/GLOSSARY.md — every technical term used in the workspaceBuild the PDF (automatically archives previous build):
make -C theory all
testing/llm_surgeon/)Python toolkit for layer-level model surgery, probing, and experiment tracking on LLaMA-family models. Loads models via HuggingFace (fp16 or 4-bit quantized).
| Module | Purpose |
|---|---|
surgery | Layer manipulation: remove, reorder, swap, duplicate layers. Attention head surgery: zero, scale, swap heads. Component ablation: zero MLP or attention. Calibration. |
probe | Logit lens (predictions at each layer), hidden state extraction, interventions (scale, zero dims, clamp, noise, replace, project out directions) |
inspect | Block influence scoring, magnitude analysis, sublayer decomposition, weight SVD, attention entropy, residual stream norms |
verify | Structural validation after surgery (layer count, embedding dims, lm_head consistency) |
benchmark | Perplexity evaluation, downstream task eval (via lm_eval), generation comparison across ollama models |
tracking | SQLite-backed experiment database — log surgery ops, metrics, generation samples |
recipe | YAML-based experiment definitions: surgery steps, analysis, evaluation, export pipeline |
export | Save HuggingFace checkpoints, convert to GGUF, register with ollama |
gguf_reader | Load GGUF files back into HuggingFace models: dequantize tensors, build config, reverse Q/K head permutation, reconstruct tokenizer |
llama_engine | Native llama.cpp wrapper: tokenize, logits, streaming generate with sampling, perplexity, HF→GGUF F16 exporter |
cd testing
python3 -m venv .venv
source .venv/bin/activate
# Install torch — pick one:
pip install torch --index-url https://download.pytorch.org/whl/cu128 # CUDA 12.8
pip install torch --index-url https://download.pytorch.org/whl/cu124 # CUDA 12.4
pip install torch --index-url https://download.pytorch.org/whl/cpu # CPU only
pip install -e ".[dev]"
Models are downloaded from HuggingFace on first use and cached in testing/.cache/models/.
cd testing
source .venv/bin/activate
python examples/quickstart.py
cd testing
source .venv/bin/activate
pytest tests/ -v
testing/gui/)Browser-based dashboard for interactive model experimentation. Load models into GPU memory, run probes, apply surgery, and visualize results in real time.
Browser (React/Vite/TypeScript)
|
|-- REST --> FastAPI --> SessionManager --> llm_surgeon
|-- WebSocket --> streaming probe results via on_layer callbacks
|
Backend holds models in GPU memory across operations
# Install GUI backend dependencies
cd testing
pip install -e ".[gui]"
# Install frontend dependencies
cd gui/frontend
npm install
./testing/gui/run.sh
Opens at http://localhost:5173 (frontend) with backend on 127.0.0.1:8000. Local only.
run.sh runs npm install automatically, but running it manually first avoids a wait on first launch.
| Layer | Stack |
|---|---|
| Backend | FastAPI, uvicorn, Python 3.10+ |
| Frontend | React 18, TypeScript, Vite, Zustand |
| Visualization | D3.js |
| Communication | REST (session/surgery/inspect), WebSocket (logit lens, generate, intervene) |
cd testing
source .venv/bin/activate
pytest gui/tests/ -v
research/)Experimental findings, anomalies, and hypotheses from model surgery experiments.
research/README.md — abstract index of research arcs (focused, multi-observation investigations), plus the conventions for observations / sessions / plans / figures.research/arcs/<slug>/) — one directory per investigation, each with its own README.md, observations/ (+ figures/), sessions/, and plans/. The flagship is arcs/nla-verbalizer/: a two-week NLA interpretability arc on Qwen2.5-7B layer 20 (Anthropic-released NLAs applied to a local open-source model) — research direction with verbatim transcript quotes, honestly-attributed collaboration mode, scope-qualified findings, methodology limitations, and filed next-paths.research/observations/) — landing bin for dated findings not yet part of an arc; promote to an arc when several cohere.research/archive/) — retired / pre-arc material.YYYY-MM-DD-<descriptive-slug>.mdllm/
theory/ # LLM architecture theory (LaTeX + visuals)
build/ # LaTeX source
sources/ # Citation index + paper PDFs
visuals/ # Interactive HTML diagrams
GLOSSARY.md # Term definitions
testing/
llm_surgeon/ # Python surgical toolkit (8 modules)
tests/ # pytest suite for llm_surgeon
gui/ # Live probe dashboard
backend/ # FastAPI + SessionManager + routes
frontend/ # React/Vite/TypeScript + D3 visualizations
tests/ # Backend API tests
run.sh # Start both servers
.cache/ # Gitignored runtime data
models/ # HuggingFace model downloads
outputs/ # Modified model variants from experiments
experiments/ # Experiment definitions + SQLite database
prompts/ # Prompt templates
lib/ # External libraries (llama.cpp, GPU-built)
research/ # Observations and findings
docs/ # Design specs
Python (in testing/.venv):
torch>=2.0
transformers>=4.40
accelerate>=0.27
bitsandbytes>=0.43
pyyaml>=6.0
sentencepiece>=0.1.99
requests
pytest>=8.0 # pip install -e ".[dev]"
fastapi>=0.100 # pip install -e ".[gui]"
uvicorn[standard]>=0.20 # pip install -e ".[gui]"
Node (in testing/gui/frontend):
react, react-dom, d3, zustand, vite, typescript
System:
lib/llama.cpp, built with CUDA)Tested on RTX 2080 (8GB VRAM). Two 4-bit quantized TinyLlama models fit comfortably for A/B comparison. OpenLLaMA 3B is tighter but works single-session.
Copyright (C) 2026 Michael Lannum
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License.
See LICENSE for the full text.
629 commits
C++
41.7%
TeX
28.5%
Python
19.9%
TypeScript
8.7%