Unlock the math behind AI — run any operation with explain=True for a step-by-step trace, terminal visualization, and the intuition of why AI uses it.
Project description
OptimumAI
Unlock the math behind AI.
Every mathematical operation in modern AI — from a dot product to a full
attention block — can be run with explain=True to produce a step-by-step
computation trace, a terminal visualization, and the intuition for why
AI actually uses it.
The same code runs fast in production or teaches you exactly what it's doing.
micrograd shows you scalar backprop; EpyNN walks you through MLPs — OptimumAI
gives you a single, traceable API that runs the whole way from a · b up to
softmax(QKᵀ/√dₖ)·V.
from optimumai import Vector
Vector([1, 2, 3]).dot(Vector([4, 5, 6]), explain=True)
╭───────────────────────── OptimumAI ──────────────────────────╮
│ DOT │
│ a · b = Σᵢ aᵢ·bᵢ │
╰───────────────────────────────────────────────────────────────╯
# Step Computation
1 Multiply component 0 1 × 4 = 4
2 Multiply component 1 2 × 5 = 10
3 Multiply component 2 3 × 6 = 18
4 Sum the products 4 + 10 + 18 = 32
╭──────── Result · scalar ────────╮
│ 32 │
╰─────────────────────────────────╯
╭──────────── Why AI uses this ────────────╮
│ • Similarity between two embedding vectors │
│ • The raw attention score q · k │
│ • The inner loop of every matrix multiply │
╰────────────────────────────────────────────╯
Install
pip install optimumai
Optional extras:
pip install "optimumai[llm]" # LLM tutor (Q&A over concepts)
pip install "optimumai[viz]" # extra plotting backends
Quickstart — Python
from optimumai import Vector, Matrix, softmax, Attention
# Linear algebra
Vector([1, 2, 3]).cosine_similarity(Vector([2, 4, 6]), explain=True) # → 1.0
Matrix([[1, 2], [3, 4]]).matmul(Matrix([[5, 6], [7, 8]]), explain=True)
# Probability
softmax([2.0, 1.0, 0.1], temperature=0.5, explain=True)
# Transformers — the headline
Attention(d_k=4).forward(Q, K, V, explain=True)
Every explain=True call returns the numeric result and prints the trace, so
it drops straight into notebooks, scripts, and tests. Prefer the data over the
print-out? Use the *_trace variants:
trace = Vector([1, 2, 3]).dot_trace(Vector([4, 5, 6]))
trace.result # 32.0
trace.steps # [Step(...), Step(...), ...]
trace.why_ai # ['Similarity between two embedding vectors', ...]
The fundamentals (v0.2)
The same explain=True philosophy now runs all the way down to the atoms of
modern AI. Inspired by Karpathy's micrograd/nanoGPT,
Yann LeCun's world models, and Anthropic's interpretability research
(see PHILOSOPHY.md):
from optimumai import Value, MLP, MultiHeadAttention, JEPA, superposition
# Autograd — a scalar computation graph that differentiates itself (micrograd)
a = Value(2.0, label="a"); b = Value(-3.0, label="b")
L = (a * b).tanh(); L.label = "L"
L.backprop(explain=True) # watch the chain rule flow backwards
# Neural net — real backprop, trained by gradient descent
from optimumai.neural_networks import train_demo
train_demo(steps=150).render("intermediate") # loss falls to ~0
# Transformers — multi-head attention with a causal mask (the GPT decoder)
MultiHeadAttention.demo().render("engineer")
# World models — LeCun's JEPA: predict in latent space, not pixels
JEPA.demo().render("engineer") # energy = ‖predicted embedding − target embedding‖²
# Interpretability — Anthropic's superposition: why neurons are polysemantic
superposition(n_features=5, n_neurons=2, explain=True)
Quickstart — CLI
optimumai algebra dot "[1,2,3]" "[4,5,6]"
optimumai softmax "[2,1,0.1]" --temperature 0.5
optimumai attention --demo --level engineer
optimumai backprop # chain rule through a scalar graph
optimumai train --steps 150 # train a tiny MLP, watch loss fall
optimumai jepa --demo # LeCun's world-model energy
optimumai superposition # Anthropic's polysemantic neurons
optimumai learn # list every topic (16 and counting)
optimumai learn transformer --level researcher
Explain levels
The same math, revealed for four audiences (--level on the CLI, level= in
Python):
| Level | Adds |
|---|---|
beginner |
The steps and plain-English "why" |
intermediate |
Per-step detail notes (default) |
engineer |
Intermediate values + complexity |
researcher |
Everything |
What's inside
optimumai/
├── core/ # Tracer, Step/Trace model, ExplainLevel, BaseOp
├── algebra/ # Vector (dot, norm, cosine), Matrix (matmul)
├── probability/ # softmax (with temperature + stability)
├── autograd/ # Value — a micrograd-style scalar autograd engine ✨v0.2
├── calculus/ # derivatives, gradients, the chain rule ✨v0.2
├── optimization/ # SGD, Adam, the training loop ✨v0.2
├── neural_networks/ # Neuron/Layer/MLP + full backprop ✨v0.2
├── transformers/ # Attention, MultiHeadAttention (causal), PE, Block ✨v0.2
├── world_models/ # JEPA — LeCun's predict-in-latent-space energy ✨v0.2
├── interpretability/# superposition — Anthropic's polysemantic neurons ✨v0.2
├── visualization/ # Rich terminal renderer
└── cli/ # the `optimumai` command
Roadmap
v0.1 — the spine: algebra → probability → attention, plus the tracer, CLI, and terminal visualization.
v0.2 ✅ — the fundamentals: a micrograd-style autograd engine, calculus, SGD/Adam, neural networks with real backprop, multi-head attention + causal mask
- positional encoding + a full transformer block, LeCun's JEPA world model, and Anthropic-style superposition. See PHILOSOPHY.md.
v0.3 (next):
- Embeddings, RAG pipeline traces, diffusion schedules
- LLM tutor —
Tutor().ask("Why is LayerNorm after attention?")(optimumai[llm]) - Streamlit explorer for visual, interactive pipelines
Development
git clone https://github.com/muhammadyahiya/optimumai
cd optimumai
uv venv && uv pip install -e ".[dev]"
pytest
License
MIT © 2026 Muhammad Yahiya
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 optimumai-0.2.0.tar.gz.
File metadata
- Download URL: optimumai-0.2.0.tar.gz
- Upload date:
- Size: 290.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
835318c59b4535f47b69b627f5f634b46ed4128720239344049d92d608044e8f
|
|
| MD5 |
08d1d925cadb65476a0ce11d148a8402
|
|
| BLAKE2b-256 |
adeb87ca574572e62288181f3ab2c37ab53ced4357f23b03aa8f0afa260fc911
|
Provenance
The following attestation bundles were made for optimumai-0.2.0.tar.gz:
Publisher:
publish.yml on muhammadyahiya/optimumai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
optimumai-0.2.0.tar.gz -
Subject digest:
835318c59b4535f47b69b627f5f634b46ed4128720239344049d92d608044e8f - Sigstore transparency entry: 2056961773
- Sigstore integration time:
-
Permalink:
muhammadyahiya/optimumai@045e9bbbd156b86cddc976d89e94b9e3eeb406d4 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/muhammadyahiya
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@045e9bbbd156b86cddc976d89e94b9e3eeb406d4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file optimumai-0.2.0-py3-none-any.whl.
File metadata
- Download URL: optimumai-0.2.0-py3-none-any.whl
- Upload date:
- Size: 49.1 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 |
8e36e15478585cf698094403ff75ded731cdb6192f17b9269cb45e188045e1e2
|
|
| MD5 |
76ccd1079831a62cd05fc280f4efd5dd
|
|
| BLAKE2b-256 |
d369c17c3def0e7026200242455b519149e69bb2d3162fb7a2accc4b62472ec3
|
Provenance
The following attestation bundles were made for optimumai-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on muhammadyahiya/optimumai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
optimumai-0.2.0-py3-none-any.whl -
Subject digest:
8e36e15478585cf698094403ff75ded731cdb6192f17b9269cb45e188045e1e2 - Sigstore transparency entry: 2056961916
- Sigstore integration time:
-
Permalink:
muhammadyahiya/optimumai@045e9bbbd156b86cddc976d89e94b9e3eeb406d4 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/muhammadyahiya
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@045e9bbbd156b86cddc976d89e94b9e3eeb406d4 -
Trigger Event:
release
-
Statement type: