caleb-bb
I just wanted to gauge people’s interest.
So, I’ve got this tool in the works. It’s supposed to take a model implementation in PyTorch and spit out an Axon implementation. I haven’t written the Axon emitter yet, though. Once I do, it won’t just let you run the model. It will translate the model into Elixir.
See, models on Arxiv come with a PyTorch reference implementation. This is why people usually use PyTorch for research; you can basically import arxiv_paper. Elixir has nothing like that. We’re way behind because the best we can do is have someone hand-implement a model in Axon. You have to translate, by hand, from the PyTorch implementations we find on Arxiv. Bumblebee is basically a body of that work.
So I’m trying to automate it and make it so you can fire up this Elixir library in your CLI and basically do import arxiv_paper, and get it back in Axon. This is different from ONNX importing. ONNX just lets you run a model. This actually translates the PyTorch model to Elixir so you can tweak it, do LoRA, etc. The old axon_onnx library is stale, though, and the ONNX hop adds another step where things can break.
Today it captures a PyTorch model via FX or torch.export, round-trips it through a JSON graph into Elixir where you can validate it, infer shapes, expand it to primitives and collapse it back, and compiles it back out to PyTorch .
The first step is an Axon emitter that works for common architectures (CNNs, MLPs) on Arxiv.
My question is: if I can get this working to that benchmark, would anyone want to use it? Elixir, generally speaking, is not a research language for ML (more for deployment and orchestration) but as long as Axon exists, we might as well have something like this.
How it happened
My original idea was a graph-theoretic notation to enable transpilation of ML models between languages. You compile your PyTorch implementation (or whatever language) into my notation. Then that notation can be compiled into any other language. A model transpiler, in other words.
# Primitive Set — ML Architecture Notation Version 0.4 — Draft --- # - Pastebin.com ← my original notation.
My friend at Brainfuel has this thing called LawSpec. I showed him my notation and he used his LawSpec thing to make it an actual Elixir application. I forked it:
I have yet to write the back-end Axon emitter to enable transpilation. But like I said, it shouldn’t take that long to get common model architectures working.
Questions:
- Would you use it?
- What would it take for you to trust this over a hand port?
Trending in AI / LLMs
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #elixirconf-us
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #security
- #elixirconf-eu
- #processes
- #api
- #forms
- #hex










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
gtcode
I looked into this when you first posted, but didn’t find the time to put together a detailed reply. I had a number of thoughts, some of which were getting ahead of where the project currently stands.
This is an ambitious project. I’m curious to see how the approach holds up in practice, given how much variation there is between potential models to port.
caleb-bb
Fair cop. The answer: the approach holds up as well as my ability to generalize over models. I suspect that very common architectures will not be terribly hard to implement. The only other major bottleneck would be something so clever in a model that it doesn’t map well to Axon, but that’s an upstream problem.
The nice thing about the LawSpec stuff is that it generalizes. Once the LawSpec laws are in place, it makes it much easier to replicate this project in other languages, e.g. Rust, which would probably be next.
gtcode
Yes. I ported a custom Qwen 0.6B SLM to Elixir, which was a decent challenge. Parameter orientation was a gotcha. Valid Axon code wasn’t an assurance of correct results. I wasn’t able to get byte-identical outputs from PyTorch → EXLA, and instead settled on a suitable tolerance. Might be a valuable eval for your platform.
caleb-bb
Correct. Right now my goal is just structural correctness. But within-tolerance on actual results would be a clear next step.
Just curious: what tolerances did you settle on, and how did you verify it? I would have used a property test, but what did you do?
Also, did you just check overall output or were you checking intermediate layers as well?
gtcode
I just did deterministic reference comparison rather than a property test. I dumped results from Python and compared using the same inputs run through Elixir. Numerical gates were cosine similarity >= 0.99, both for the extracted penultimate hidden vector, and the final router logits (this was for a custom router that used those), and relative L2 error <= 0.12 for hidden and <= 0.10 for logits. CS was ~0.9945 for hidden and ~0.9974 for logits. Thresholds were tailored to the given router comparison, nothing universal.
Yes, intermediate checks that did survive as scripts and tests. Detailed checkpoints were in the weight reconstruction pipeline, and the hidden vector before the router head. I wasn’t able to find a permanent comparison of activations at every transformer layer.
E2E check used a fixed transcript and required matching token ID’s, router head weight hash and selected agent/role, in addition to the vector/logit checks. The final checks were Python/Elixir output comparisons, along with a prompt eval suite that I expanded for coverage before calling it close enough for jazz.
caleb-bb
Thank you! Very useful.
Watch this space. Results soon.