Show HN: Glowstick – type level tensor shapes in stable rust

25 bietroi 2 6/9/2025, 4:08:22 PM github.com ↗
Hi HN,

In the past few years I've become more interested in machine learning. Since I'm sure the same is true for many here, I wanted to share this project I've been working on: glowstick uses type-directed metaprogramming to keep track of tensor shapes in Rust's type system and determine which operations are permitted or not at compile time.

I find Rust has a lot of strengths when it comes to ML applications, but waiting until runtime to find shape related issues feels a bit strange since normally I don't run the code all that often while developing. Given Rust has fancy types available, I figured I'd try my hand at using them to address this.

I've added integration crates for the two ML frameworks I use most frequently, candle and burn, and included examples of implementing llama 3.2 in each using typed shapes for much of the model internals and inference loop. Mixtures of static and dynamic dimensions should be supported well enough for most applications at this point, though there are of course still improvements to be made.

Any feedback is appreciated!

Comments (2)

srean · 22m ago
Could you take a look at Barry Jay's shape theory.

https://web.archive.org/web/20111015133833/http://www-staff....

This was used in his shape aware language FiSh, for dealing with multidimensional arrays. Shape compatibilities were statically type checked, if I recall correctly. Shapes were also used to optimize the loops.

[Programming in FISh] https://link.springer.com/article/10.1007/s100090050037

[Towards Dynamic Shaping] https://www.researchgate.net/publication/265975794_Towards_D...

bee_rider · 45m ago
I wonder… I know Eigen has some tricks it can do when the size of a matrix is known beforehand. The obvious example, 4x4 matrix inverse gets special treatment. I assume they also be smart about loop unrolling, that sort of stuff.

Anything similar in here?

If not—actually, optimizing compilers are pretty okay nowadays anyway. I wonder if you’ve tried just seeing what Rust will do automatically with different optimization levels?