A pure-Python (+numpy) byte-graph that is a 1-bit (ternary) LLM: dunder API, autograd, ultra-edges, visualization.
Project description
ultragraph
A pure-Python (+ numpy) byte-graph that is a 1-bit (ternary) LLM.
genesis
251e6ea· themed after pocoo.vaked.dev
Three levels:
| level | unit | storage |
|---|---|---|
| micro | node / edge | 1 byte each — int8 activation / ternary weight {-1,0,+1} |
| meso | tree | a whole graph == one net/module (a Linear/MLP block) |
| macro | ultra-edge (===) |
typed wiring between trees → the ultra-graph = the model |
Weights are ternary (BitNet b1.58 style); activations are int8. Full-precision "master" weights live in an ad-hoc side store during training; the byte buffers are the deployed state. Training uses a straight-through estimator (STE).
Illustrations
Real outputs from a trained ternary mini-GPT — regenerate with uv run python assets/make_figures.py:
| ultra-graph | causal attention | ternary weight bytes |
|---|---|---|
Left: the model as an ultra-graph — trees wired by ultra-edges (===), with residual skips.
Middle: real causal self-attention weights (lower-triangular → no peeking at the future).
Right: a trained query projection's weight bytes, each ∈ {−1, 0, +1}.
Install
pip install ultragraph-1bit # then: import ultragraph
# or from source (Python >=3.11):
uv sync
Dunder API
>> is overloaded by operand type:
import numpy as np
from ultragraph import Tree, UltraGraph, Tensor, mlp, SGD
# micro-edges inside a sparse tree
g = Tree(4, "g")
g[0] >> g[1] # node >> node -> micro-edge
g[2] = 7 # set a node byte
print(len(g), 2 in g, list(g))
# ultra-edges between trees
ug = UltraGraph()
a = ug.add(Tree.dense(8, 16, "a"))
b = ug.add(Tree.dense(16, 4, "b", act="none"))
a >> b # tree >> tree -> ultra-edge (plain)
a.wire(b, "residual")
Train a tiny ternary net
ug = mlp([4, 16, 2]) # dense ternary linear trees wired plain
opt = SGD(ug, lr=0.3, momentum=0.9)
x = Tensor(np.random.randn(32, 4).astype("float32"))
for _ in range(300):
loss = ug.forward(x).cross_entropy(y)
opt.zero_grad(); loss.backward(); opt.step() # step() re-quantizes weights
See examples/char_lm.py (MLP LM), examples/transformer_lm.py (single-head attention),
and examples/mini_gpt.py (batched multi-head attention + RMSNorm + Adam) for
end-to-end char-level ternary language models.
from ultragraph import Embedding, MultiHeadAttention, RMSNorm, linear_tree, Adam
# pre-norm transformer block over a [B, T, d_model] sequence:
# x = x + mha(norm1(x)); x = x + ff2(ff1(norm2(x)))
Tasks
just test # pytest
just test-fast # dependency-free runner (stdlib + numpy)
just demo # char-LM end-to-end
just viz # render example SVGs
Layout
ultragraph/quant.py ternary + int8 quantization, STE
ultragraph/autograd.py numpy autograd tape; ternary_linear (STE)
ultragraph/core.py Node/Edge/Tree/UltraEdge/UltraGraph + dunder API
ultragraph/nn.py linear_tree, mlp, Attention, MultiHeadAttention, RMSNorm, LayerNorm
ultragraph/optim.py SGD + Adam over fp32 masters (grad clip), re-quantize after step
ultragraph/viz.py pure-SVG + optional matplotlib (micro / macro / byte-heatmap)
ultragraph/io.py byte-exact save / load
Design spec: docs/superpowers/specs/2026-07-10-ultragraph-design.md.
Graph-theory reading list (Erdős classics): docs/references.md.
Install from source
git clone https://github.com/peterlodri-sec/ultra-graph
cd ultra-graph
uv sync
just test
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ultragraph_1bit-0.1.0.tar.gz.
File metadata
- Download URL: ultragraph_1bit-0.1.0.tar.gz
- Upload date:
- Size: 4.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecba7280044b5692e2d90a5db51576b87631105bbfa12145f7f4d7d25f924526
|
|
| MD5 |
b8f9ea2f4e947172a018c6187de0306d
|
|
| BLAKE2b-256 |
502058ca9700fe1f62cca026c4185910d7c86da1ba0d346647fdc07db2184e07
|
Provenance
The following attestation bundles were made for ultragraph_1bit-0.1.0.tar.gz:
Publisher:
publish.yml on peterlodri-sec/ultra-graph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ultragraph_1bit-0.1.0.tar.gz -
Subject digest:
ecba7280044b5692e2d90a5db51576b87631105bbfa12145f7f4d7d25f924526 - Sigstore transparency entry: 2140847340
- Sigstore integration time:
-
Permalink:
peterlodri-sec/ultra-graph@2dad03066facf62646ee1806031c8244f991cc79 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/peterlodri-sec
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2dad03066facf62646ee1806031c8244f991cc79 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file ultragraph_1bit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ultragraph_1bit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76c46d8af098d3644b14349eb6145dd3140fb974b42bca2ffd7ffbb9d5f9de4f
|
|
| MD5 |
a738f245d44928b421a2510a8273120f
|
|
| BLAKE2b-256 |
8ca3c9e44a081e4d56a979a64b9a1394744235bb24e59fccbafcadcc56aa11c7
|
Provenance
The following attestation bundles were made for ultragraph_1bit-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on peterlodri-sec/ultra-graph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ultragraph_1bit-0.1.0-py3-none-any.whl -
Subject digest:
76c46d8af098d3644b14349eb6145dd3140fb974b42bca2ffd7ffbb9d5f9de4f - Sigstore transparency entry: 2140847657
- Sigstore integration time:
-
Permalink:
peterlodri-sec/ultra-graph@2dad03066facf62646ee1806031c8244f991cc79 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/peterlodri-sec
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2dad03066facf62646ee1806031c8244f991cc79 -
Trigger Event:
workflow_dispatch
-
Statement type: