@MaximeRivest probabilistic programming and differential programming are quite well established ... looking forward to see something similar in AI programming :)
Thinking about writing this up as a blog series:
1. building a tensor language for GPTs
2. writing autodiff from scratch
3. why Rust was not magically faster than Python
4. what optimization actually helped
5. why Burn became the right backend
Would you read this?
I tried to build a tiny GPT stack from scratch.
Not just the model.
A small tensor language.
A parser + HIR.
A custom autodiff engine.
An interpreter.
Training.
Inference.
KV cache.
Batching.
Fusion.
Benchmarks.
Then I learned why frameworks exist.
So I optimized.
Dense IDs instead of hash maps.
In-place tensor ops.
KV cache reuse.
Fast paths for sum(lhs * rhs).
Less cloning.
Less allocation.
More precomputed execution plans.
Some changes helped a lot.
Some clever ideas broke correctness immediately.
Funny result:
my Rust tensor-language interpreter was not automatically faster than the pure Python microGPT.
Rust was fast.
My abstraction stack was not.
Interpreter dispatch, shape metadata, map lookups, small tensor allocation, and generic graph execution ate the advantage.
Then came autodiff.
Reverse-mode autodiff sounds simple:
run forward,
walk backward,
accumulate gradients.
But once tensors, reductions, softmax, cross entropy, params, targets, and shape checks enter the room, “simple” becomes a very educational swamp.
So I built Tenscript.
Example vibe:
axis time = 16
axis embed = 16
logits[time, vocab] =
sum embed. x[time, embed] * lm_head[vocab, embed]
The goal was to make GPT architecture readable as math, not buried in framework code.
The project started from Karpathy microGPT: one tiny Python file where the whole algorithm is visible.
That file is beautiful because nothing is hidden.
But I wanted to ask:
what if the model itself was written as tensor equations, with named axes, and compiled from there?
@spacebat@mikehostetler oh nice , any one that catches your eyes ? since Prolog is also homoiconic , it would be interesting to see those languages created for AI is used by AI :)
@mikehostetler ah can't wait to see some code :) been trying to do use pythonx to do data analysis in similar way. I am keeping the python process alive so it's kinda look like a REPL to me, is it not making sense ?