TL;DR
Apple has open-sourced AXLearn, a JAX/XLA-based deep learning system designed for scalable, high-performance large model training. By enforcing strict modular encapsulation, AXLearn allows developers to add complex features like Mixture of Experts (MoE) with constant code complexity ($O(1)$) while remaining entirely hardware-agnostic across GPUs, TPUs, and AWS Trainium.
What Problem Does This Problem Address?
Training state-of-the-art large language models requires massive infrastructure and extreme optimization. However, existing deep learning frameworks often force a painful trade-off between engineering agility and hardware performance.
Most frameworks rely heavily on object-oriented subtyping or flat configuration files. When developers want to introduce a new feature—such as swapping a standard feed-forward network for a Mixture of Experts (MoE) layer—the changes cascade upward through the model hierarchy, requiring hundreds of lines of code modifications across multiple files.
Furthermore, many top-tier training systems are locked into specific hardware ecosystems (e.g., Megatron-LM for Nvidia GPUs, MaxText for Google TPUs). For large enterprises, this creates severe supply-chain vulnerabilities and limits the ability to leverage cost-effective cloud infrastructure across different vendors.
Methods
AXLearn addresses these challenges through two core design principles: strict encapsulation and a compiler-first approach.
Instead of subtyping, AXLearn uses a purely Python-based hierarchical configuration tree to compose models. To modify a model, users write "config modifiers" that programmatically traverse and alter the tree.
Because JAX requires purely functional, stateless programs, managing state (like model parameters, PRNG keys, and training summaries) can quickly clutter code. AXLearn solves this with an abstraction called InvocationContext. When a module executes, its context is pushed to an implicit stack that handles state propagation and PRNG splitting behind the scenes, allowing developers to write clean, imperative-style code.
To remain hardware-agnostic, AXLearn builds on top of the XLA compiler and GSPMD. It introduces "mesh rules"—mappings from specific accelerator types to target-dependent optimization strategies (like FSDP, tensor parallelism, or activation rematerialization)—allowing the exact same model code to run efficiently on different hardware backends.
Datasets
The authors evaluated AXLearn's training performance using standard open-source model architectures: Llama2-7B, Llama2-70B, and Qwen-3 30B-A3B. For the inference benchmarks, they utilized the ShareGPT dataset to supply realistic user prompts.
Key Insights and Ideas
- Asymptotic Lines-of-Code (LoC) Complexity: The authors propose a formal framework to measure system extensibility by evaluating how code changes scale asymptotically ($O$) when introducing new features. While other systems scale linearly or quadratically ($O(N)$ or $O(NM)$), AXLearn achieves constant $O(1)$ complexity.
- Unified Training and Inference: A highly modular training framework can double as a highly efficient inference engine. By reusing AXLearn's encapsulated attention and KV cache components, the authors built a TPU serving system that significantly outperforms specialized inference engines.
- Compiler-First with Escape Hatches: Relying on a compiler like XLA provides excellent hardware portability, but compilers can struggle to auto-derive highly optimized kernels. AXLearn treats custom hand-tuned kernels (like FlashAttention or AWS Nki) as encapsulated "black-box" nodes within the computation graph, combining portability with peak hardware utilization.
Key Results
- Zero-Line Feature Integration: Integrating Rotary Position Embeddings (RoPE) or MoE requires exactly 0 lines of code changes to existing interfaces in AXLearn, compared to hundreds or thousands of lines in frameworks like DeepSpeed or Megatron-LM.
- State-of-the-Art Performance: AXLearn delivers hardware utilization comparable to or better than vendor-specific frameworks. For example, training Llama2-7B on a 32×H100 cluster yields a Model FLOPS Utilization (MFU) of 54.2%, matching MaxText and outperforming Megatron-LM.
- Massive Scalability: The system demonstrates near-linear weak scaling up to 32,768 TPUs for a 150B parameter model.
- Inference Speedups: On TPUs, AXLearn achieved up to a 500x speedup in Time-To-First-Token (TTFT) and a 6x speedup in Time-Per-Output-Token (TPOT) compared to vLLM (though the authors note TPU support for vLLM is still experimental).
- Resilient Recovery: On a 32,768 TPU cluster, AXLearn successfully detected a hardware failure, initiated a slice-level hot-swap within 4 minutes, and fully restored the checkpoint in 9 minutes, losing only 21 minutes of total training progress.
Limitations and Future Work
While AXLearn achieves hardware agnosticism, it inherits the backend performance characteristics of XLA. On Nvidia GPUs, Megatron-LM still holds a slight edge because PyTorch currently offers finer-grained scheduling capabilities than XLA. Additionally, achieving peak performance on emerging platforms still requires writing and maintaining backend-specific custom kernels, which demands specialized hardware expertise. The authors plan to expand their unified training and inference capabilities to non-TPU backends in future work.
Summary updated