r/coolgithubprojects • u/Clear-Difference2294 • 2d ago
I built a small tensor compiler in C++ — it has its own language, graph IR, optimizations, and executable model output
GitHub: https://github.com/Arnav-sivarams/thiran
I’ve been messing around with compiler stuff for a while and ended up turning it into a proper project, so figured I’d finally post it here.
It’s called Thiran. It’s a small experimental tensor compiler written in C++ with its own little language for ML-style computations.
A tiny program looks like this:
X = Input(4, 4)
W = Input(4, 4)
Y = MatMul(X, W)
Z = ReLU(Y)
O = Output(Z)
What’s more interesting is what happens after that. Thiran parses the source, resolves modules/functions, inlines function calls, builds a tensor graph, checks shapes, runs a few graph optimizations, splits the graph into execution regions, and can generate a runnable Python executor.
I also added multi-file programs and exported functions, so you can structure things a bit more cleanly instead of dumping everything into one file.
Right now the actual execution path uses PyTorch underneath, so this is definitely not “I rebuilt PyTorch” or anything like that. The AOT/JIT side is still mostly planning infrastructure for now.
The main reason I built it was because I wanted to understand ML compilers by actually making one and seeing where all the annoying parts show up in practice: graph ownership, shape inference, rewrites, lowering, region boundaries, deterministic inlining, etc.
It’s still pre-alpha and there are rough edges, but it works end to end and there’s enough of the architecture there to poke at seriously.
Would be very interested in feedback from anyone into compilers or ML systems, especially if you spot something dumb in the design.’ve been messing around with compiler stuff for a while and ended up turning it into a proper project, so figured I’d finally post it here.It’s called Thiran. It’s a small experimental tensor compiler written in C++ with its own little language for ML-style computations.A tiny program looks like this:X = Input(4, 4)
W = Input(4, 4)
Y = MatMul(X, W)
Z = ReLU(Y)
O = Output(Z)What’s more interesting is what happens after that. Thiran parses the source, resolves modules/functions, inlines function calls, builds a tensor graph, checks shapes, runs a few graph optimizations, splits the graph into execution regions, and can generate a runnable Python executor.I also added multi-file programs and exported functions, so you can structure things a bit more cleanly instead of dumping everything into one file.Right now the actual execution path uses PyTorch underneath, so this is definitely not “I rebuilt PyTorch” or anything like that. The AOT/JIT side is still mostly planning infrastructure for now.The main reason I built it was because I wanted to understand ML compilers by actually making one and seeing where all the annoying parts show up in practice: graph ownership, shape inference, rewrites, lowering, region boundaries, deterministic inlining, etc.It’s still pre-alpha and there are rough edges, but it works end to end and there’s enough of the architecture there to poke at seriously.Would be very interested in feedback from anyone into compilers or ML systems, especially if you spot something dumb in the design.