JAX Tutorial: From Basics to Advanced JAX 教程:从入门到进阶

Online tutorial在线教程, JAX 0.12 · Jupyter, 2026

About this tutorial

A hands-on JAX tutorial in two parts, from the basics to advanced topics. It follows two courses on apxml.com — Getting Started with JAX and Advanced JAX: Performance, Optimization, and Scale — and adds five extra chapters on topics you run into in real projects: Pallas kernels, debugging, export and deployment, random numbers and sharding, and scientific computing.

Every chapter is a Jupyter notebook that was run end to end on JAX 0.12 (CPU), with all outputs included, so you can read it here without running anything. Key claims are backed by asserts in the code, and outdated APIs are shown side by side with the current way to write them.

How to use it

  • Read online: open any chapter below.
  • Run it yourself: on each chapter page, click Open in Colab. The first cell installs the tested JAX version; use the default CPU runtime. You can also download the .ipynb and run it locally.
  • Exercises: each exercise has a ✍️ answer cell followed by a 🧪 self-check. ✅ means your answer passes; ⏳ means you haven’t defined the required name yet. Reference solutions are in each chapter’s appendix.
  • First time through: follow the core learning path — read the main text and the 🟢 Must-read extras, and skip the ⚪ Optional ones for now. Looking for a specific API? Try the keyword index.

Part 1 · Basics

ChapterRun
Basics · OverviewOpen in Colab
Chapter 1: Introduction to JAXOpen in Colab
Chapter 2: Accelerating Functions with JIT CompilationOpen in Colab
Chapter 3: Automatic Differentiation with gradOpen in Colab
Chapter 4: Automatic Vectorization with vmapOpen in Colab
Chapter 5: Parallelization Across Devices with pmapOpen in Colab
Chapter 6: Managing State in JAXOpen in Colab
Chapter 7: Practical TopicsOpen in Colab

Part 2 · Advanced

ChapterRun
Advanced · OverviewOpen in Colab
Chapter 1: Advanced Transformations and Control FlowOpen in Colab
Chapter 2: Optimizing JAX Code for PerformanceOpen in Colab
Chapter 3: Distributed Computing with JAXOpen in Colab
Chapter 4: Advanced Automatic DifferentiationOpen in Colab
Chapter 5: Interoperability and Custom OperationsOpen in Colab
Chapter 6: Large-Scale Model TrainingOpen in Colab
Chapter 7: Custom Kernels with PallasOpen in Colab
Chapter 8: The Debugging ToolkitOpen in Colab
Chapter 9: Export and DeploymentOpen in Colab
Chapter 10: Random Numbers and ShardingOpen in Colab
Chapter 11: Scientific Computing and Differentiable SimulationOpen in Colab

Course explanations are reorganized from the key points of the original apxml.com courses, with a link to the original page at the start of each section. The original course content is © ApX Machine Learning.

教程简介

一套分成入门和进阶两部分的 JAX 实战教程。内容跟着 apxml.com 的两门课程整理: JAX 入门 和 JAX 高级编程:性能、优化与规模化,另外补充了五章实际项目里常用的内容: Pallas 内核、调试、导出与部署、随机数与分片、科学计算。

每章是一个 Jupyter notebook,都在 JAX 0.12(CPU)上完整运行过,输出也一并保留,不运行也能直接在这里阅读。 重要结论都配了 assert 验证;过时的 API 会和现在的写法放在一起对照。

怎么用

  • 在线阅读:点下面任意一章。
  • 自己动手运行:在章节页点 在 Colab 中打开。第一格会安装测试过的 JAX 版本,用默认的 CPU 运行时即可。 也可以下载 .ipynb 在本地运行。
  • 做练习:每道练习下面有 ✍️ 作答区和 🧪 自检。✅ 表示通过;⏳ 表示还没定义题目要求的名字。参考答案在每章最后的附录里。
  • 第一遍学习:按 核心学习路径 走,只看正文和标着 🟢 必读的补充,⚪ 选读的可以先跳过。 想查某个 API 在哪讲过,可以用 关键词索引。

第一部分 · 入门

章节运行
入门 · 总目录在 Colab 中打开
第 1 章 JAX 简介在 Colab 中打开
第 2 章 用 JIT 编译加速函数在 Colab 中打开
第 3 章 用 grad 做自动微分在 Colab 中打开
第 4 章 用 vmap 自动向量化在 Colab 中打开
第 5 章 用 pmap 跨设备并行在 Colab 中打开
第 6 章 JAX 中的状态管理在 Colab 中打开
第 7 章 实战专题在 Colab 中打开

第二部分 · 进阶

章节运行
进阶 · 总目录在 Colab 中打开
第 1 章 高级变换与控制流在 Colab 中打开
第 2 章 JAX 代码性能优化在 Colab 中打开
第 3 章 JAX 分布式计算在 Colab 中打开
第 4 章 进阶自动微分在 Colab 中打开
第 5 章 互操作性与自定义操作在 Colab 中打开
第 6 章 大规模模型训练在 Colab 中打开
第 7 章 用 Pallas 写自定义内核在 Colab 中打开
第 8 章 调试工具链在 Colab 中打开
第 9 章 导出与部署在 Colab 中打开
第 10 章 随机数与分片在 Colab 中打开
第 11 章 科学计算与可微分仿真在 Colab 中打开

讲解部分按 apxml.com 原课程的要点重新组织,每节开头附有原课程链接。原课程内容版权归 ApX Machine Learning 所有。