Write Once, Run Everywhere: The Axon DSL for Shape-Safe and Framework-Agnostic LLM Architectures
Organizations: University of Southern Denmark Campusvej 55, 5230 Odense, Denmark
Abstract
The entire ecosystem of open-source language models effectively relies on a single platform. What if this platform was forced to shut down tomorrow? Implementing and maintaining efficient model definitions and translating them between different training and inference regimes is a resource-heavy task that severely limits model efficiency and portability, hindering both scaling and deployment. Here, we present Axon, a strongly typed domain-specific language with Haskell-like syntax, that enables a write-once, run everywhere paradigm for LLM architectures. By basing collaboration on a language specification rather than a specific framework's vision, Axon fosters open cooperation and empowers researchers to implement highly specialized architectures without giving up optimization infrastructure or accepting deployment lock-in. Axon allows for concise, auditable specifications that can be automatically compiled to standalone implementations for leading frameworks: PyTorch, PyTorch with Triton, JAX, MLX and vLLM. In 467 inference benchmarking experiments on models ranging from 135M to 32B parameters, we demonstrate median speedups of 7% on PyTorch, 12% on PyTorch with Triton, 91% on JAX, and 107% on MLX, compared to the reference implementations from Transformers. When deployed as native vLLM architectures with PagedAttention and KV-cache, Axon models achieve a 58% median speedup over Transformers implementations.
Figures & tables
| Backend | Checkpoints | Axon | Axon | Median ratio | Mean ratio |
|---|---|---|---|---|---|
| <4B | |||||
| PyTorch | 76 | 48 (63%) | 28 (37%) | 0.903 | 0.925 |
| Triton | 75 | 60 (80%) | 15 (20%) | 0.843 | 0.878 |
| JAX | 74 | 64 (86%) | 10 (14%) | 0.481 | 1.122 |
| <4B total | 225 | 172 (76%) | 53 (24%) | 0.804 | 0.974 |
| 4–32B | |||||
| Backend | Checkpoints | Axon | Axon | Median ratio | Mean ratio |
|---|---|---|---|---|---|
| 4B | |||||
| PyTorch | 26 | 15 (58%) | 11 (42%) | 0.883 | 1.786 |
| Triton | 26 | 9 (35%) | 17 (65%) | 1.332 | 2.169 |
| JAX | 26 | 7 (27%) | 19 (73%) | 1.079 | 1.260 |
| 4B total | 78 | 31 (40%) | 47 (60%) | 1.084 | 1.738 |
| 4–32B | |||||
| Model size | Checkpoints | Axon | Axon | Median ratio | Mean ratio |
|---|---|---|---|---|---|
| Small ( 4B) | 54 | 38 (70%) | 16 (30%) | 0.656 | 1.430 |
| Large (4B–32B) | 34 | 27 (79%) | 7 (21%) | 0.609 | 2.889 |
| Total | 88 | 65 (74%) | 23 (26%) | 0.631 | 1.994 |
| Group | Points | Axon | Axon | Median ratio | Mean ratio |
|---|---|---|---|---|---|
| BF16 | 63 | 61 (97%) | 2 (3%) | 0.423 | 0.500 |
| FP32 | 63 | 58 (92%) | 5 (8%) | 0.503 | 0.588 |
| causal_lm | 84 | 82 (98%) | 2 (2%) | 0.390 | 0.437 |
| seq2seq_lm | 42 | 37 (88%) | 5 (12%) | 0.574 | 0.752 |
| len=64 | 42 | 42 (100%) | 0 (0%) | 0.417 | 0.448 |
| len=128 | 42 | 39 (93%) | 3 (7%) | 0.483 | 0.525 |
| Phase | Representation | Primary invariant |
|---|---|---|
| Parse | one-file AST | Syntactic structure and explicit MAIN pragma insertion |
| Load | loaded AST set | Imports and builtins located without rewriting semantics |
| Materialize | one-file AST | Optional checkpoint/config specialization for generic models |
| Resolve/validate-closed | closed AST | No unresolved imports or names; unreachable definitions pruned from MAIN |
| Normalize | normalized AST | Call syntax, pipes, path sugar, and zero-arg call/name distinctions made explicit |
| Elaborate/validate-elaborated | elaborated AST | Default arguments filled and call arguments positionalized |
| Qwen2.5-0.5B (0.67B) | Pleias-3b-Preview (3.8B) | |||||
| Metric | Transformers | Axon-Torch | Axon-JAX | Transformers | Axon-Torch | Axon-JAX |
| Wall-clock (ms) | 1380 | 1185 | 541 | 1091 | 1071 | 1160 |
| Speedup vs Transformers | 1.0 | 0.86 | 0.39 | 1.0 | 0.98 | 1.07 |
| GPU active (ms) | 373 | 370 | — | 557 | 561 | — |
| GPU idle (ms) | 1007 | 815 | — | 534 | 510 | — |
| GPU idle % | 73.0% | 68.8% | 0.0% | 48.9% | 47.6% | 0.0% |
| Qwen2.5-0.5B (0.67B) | Pleias-3b-Preview (3.8B) | |||||
| Metric | Transformers | Axon-Torch | Axon-JAX | Transformers | Axon-Torch | Axon-JAX |
| Total Python calls | 455,769 | 508,390 | 137,805 | 359,909 | 330,929 | 82,210 |
| Calls vs Transformers | 1.0 | 1.12 | 0.30 | 1.0 | 0.92 | 0.23 |
| cProfile time (s) | 1.13 | 0.95 | 0.54 | 0.87 | 0.78 | 1.16 |
| Per-op dispatch (Python calls per generate pass): | ||||||
| nn . Module . call | 35,616 | 0 | 0 | 28,032 | 0 | 0 |
Efficient Language Model Inference
Efficient language model inference reduces the compute, memory, latency, and energy needed to generate useful outputs.
See all 318 papers