Write Once, Run Everywhere: The Axon DSL for Shape-Safe and Framework-Agnostic LLM Architectures
新语言Axon让语言模型代码一次编写,可在PyTorch、JAX、MLX、vLLM上运行
开源语言模型生态系统实际上依赖单一平台Hugging Face,把模型移植到其他框架往往需要人工重写,还容易丢失原有的优化。研究团队开发了强类型、语法类似Haskell的专用语言Axon,只需描述一次模型结构,编译器就能自动生成PyTorch、Triton、JAX、MLX、vLLM五种后端的独立代码。在参数量从1.35亿到320亿的模型上进行的467次推理基准测试中,Axon生成的模型普遍比参考的Transformers实现更快。
METAL MEDIA 解读图
新语言Axon让语言模型代码一次编写,可在PyTorch、JAX、MLX、vLLM上运行
- 01问题:语言模型代码被锁定在特定平台的实现方式里,移植到其他框架需要人工重写,过程中容易出错并丢失针对性优化
- 02方案:用Axon描述模型的层结构、张量形状、参数位置等,编译器将其转为共享的中间表示(Graph IR),再自动生成五种后端的独立可运行代码
- 03强类型系统在编译阶段就检查张量形状,避免运行时出现形状不匹配的错误
- 04结果:相较Transformers参考实现,PyTorch后端中位数快7%,结合Triton的PyTorch快12%,JAX快91%,MLX快107%;以vLLM原生方式部署并使用PagedAttention和KV缓存时,中位数比Transformers快58%
- 05训练实验显示,Axon生成的PyTorch模型与原版Transformers实现的损失曲线几乎完全重合,且每步训练速度快约9.6%
他们做了什么
- 问题:语言模型代码被锁定在特定平台的实现方式里,移植到其他框架需要人工重写,过程中容易出错并丢失针对性优化
- 方案:用Axon描述模型的层结构、张量形状、参数位置等,编译器将其转为共享的中间表示(Graph IR),再自动生成五种后端的独立可运行代码
- 强类型系统在编译阶段就检查张量形状,避免运行时出现形状不匹配的错误
- 结果:相较Transformers参考实现,PyTorch后端中位数快7%,结合Triton的PyTorch快12%,JAX快91%,MLX快107%;以vLLM原生方式部署并使用PagedAttention和KV缓存时,中位数比Transformers快58%
- 训练实验显示,Axon生成的PyTorch模型与原版Transformers实现的损失曲线几乎完全重合,且每步训练速度快约9.6%

| Backend | Checkpoints | Axon ≤1× | Axon >1× | 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 | |||||
| PyTorch | 87 | 55 (63%) | 32 (37%) | 0.987 | 0.980 |
| Triton | 87 | 67 (77%) | 20 (23%) | 0.924 | 0.931 |
| JAX | 68 | 55 (81%) | 13 (19%) | 0.589 | 0.981 |
| 4–32B total | 242 | 177 (73%) | 65 (27%) | 0.908 | 0.963 |
| Backend | Checkpoints | Axon ≤1× | Axon >1× | 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 | |||||
| PyTorch | 20 | 13 (65%) | 7 (35%) | 0.990 | 1.506 |
| Triton | 20 | 8 (40%) | 12 (60%) | 1.133 | 1.546 |
| JAX | 14 | 0 (0%) | 14 (100%) | 3.747 | 3.356 |
| 4–32B total | 54 | 21 (39%) | 33 (61%) | 1.175 | 2.001 |
| Model size | Checkpoints | Axon ≤1× | Axon >1× | 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 ≤1× | Axon >1× | 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 |
| len=256 | 42 | 38 (90%) | 4 (10%) | 0.494 | 0.652 |
| Total | 126 | 119 (95%) | 7 (5%) | 0.483 | 0.544 |
| 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 |
| Flatten/validate-flat | flat AST | Explicit evaluation order; flat calls and binds accepted by typecheck and Graph IR lowering |
| Typecheck/validate-typed | Typed flat AST | expression types, arities, dimensions, and primitive rules applied to a fixpoint |
| Optimize-ast | typed flat AST | Optional conservative AST cleanup with retype/validation |
| Graph lowering/validation | Graph IR | Typed graph modules, multi-output nodes, structured paths, constraints, and metadata |
| Optimize-graph/validation | Graph IR | Optional graph cleanup, specialization, backend-neutral rewrites, and opt-in backend intrinsics |
| Backend | generated/runtime code | Executable tensor program consuming the validated Graph IR contract |
| 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% |
| CUDA kernels | 129,189 | 120,987 | — | 101,935 | 104,123 | — |
| 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 |
| F.linear | 18,928 | 18,928 | — | 14,880 | 14,880 | — |
| SDPA | 2,688 | 2,688 | — | 2,112 | 2,112 | — |
| rope_apply | 0 | 5,376 | — | 0 | 4,224 | — |
| forward (jit dispatch) | — | — | 112 | — | — | 96 |
为什么重要
当前语言模型工具链高度集中在少数平台上,一旦该平台出问题整个生态都会受影响;Axon提出用共享的语言规范取代共享框架来减少这种依赖。这对希望摆脱单一厂商优化基础设施、又想获得快速可移植模型的研究者和小团队具有实际意义。
本文术语
- DSL(领域专用语言) · 为特定用途设计的编程语言,这里用于描述神经网络结构
- 强类型 · 编译器在运行前严格检查数值的种类和形状
- Graph IR(图中间表示) · 各后端代码生成器共用的编译中间结构
- PagedAttention/KV缓存 · vLLM用来高效管理生成过程中缓存令牌的内存管理技术,可提升服务速度
- top-1 token parity(首选词一致性) · 检验不同实现在每一步是否预测出相同下一个词的正确性标准
论文原文摘要(英文)
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.
在 arXiv 阅读最新论文
- SWE-bench Science: Can Coding Agents Resolve Engineering Tasks in Science?让AI编程助手去修复真实科学软件,连最强的那个也有一半以上任务没做对
- FlashPrefill V2: Block-Sparse Prefill Attention for Long-Context LLM Serving把稀疏注意力从论文原型变成能真正上线服务的加速方案
- PolicyGuide: From Guarding One Action to Guiding the Whole Workflow for Policy-Compliant LLM Agents让客服AI坐席不只是拦住一个危险动作,而是把整个流程走对
- EXIMO: VLM Guided Exploration of VLA Policies不用人工遥控演示,让会说话的AI来教机械臂做新家务
- EnvHarness: Awakening Static Worlds for Agent Learning不重新搭建训练环境,而是给现有环境套一层可插拔组件,针对每个智能体的具体弱点重新塑形
- Bounded Sovereignty and the Control Tax: Pricing AI Oversight When the Deployer Does Not Own the Model租用AI而非拥有AI的机构,安全监管能力只剩一半
- Beyond Imitation: Filtering On-Policy Distillation by Reasoning ProgressAI模仿老师模型学习时,会误伤本来推理正确的步骤,新方法专门过滤掉这种误伤
- PersonalBench: Measuring the Authorship Gap in LLM Personalization让AI模仿某人的文风,结果发现它始终摆脱不了自己的腔调
METAL MEDIA 最新报道
图片来源: Jacob Nielsen et al., arXiv:2608.19889, arxiv-nonexclusive