Skip to content

Improve JAX for pretraining notebook. - #293

Merged
emilyfertig merged 11 commits into
jax-ml:revamp-2025from
f33ac:revamp-2025
Mar 10, 2026
Merged

Improve JAX for pretraining notebook.#293
emilyfertig merged 11 commits into
jax-ml:revamp-2025from
f33ac:revamp-2025

Conversation

@f33ac

@f33ac f33ac commented Jan 6, 2026

Copy link
Copy Markdown

Description

This PR extends the notebook by replacing all placeholder "REVAMP" sections with actual content. The notebook ready for review initial review.

Note:
The vLLM section was intentionally not fully implemented, as running it inside the notebook would require more code and some hacky setup. Instead, it is briefly mentioned with guidance.

Changes

  • Replaced all "REVAMP" placeholders with content

Testing

  • Ran the notebook E2E on a T4 GPU & v5e-1 TPU on Google Colab with no issues.

@f33ac

f33ac commented Jan 6, 2026

Copy link
Copy Markdown
Author

@emilyfertig

@emilyfertig

Copy link
Copy Markdown
Collaborator

Hi @f33ac thanks for the PR -- I was going to start reviewing it but it looks like the file size is now 41 MB when it used to be 110 kb, do you know why that is and could you mitigate it?

@emilyfertig emilyfertig left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, overall I think this looks great! I left some comments (I might take another pass later), but in general I think your additions tie it all together really nicely.

A couple high-level things:

  • Some of the cells are tagged nbval-skip or nbval-ignore-output. Some of these tags got deleted, so we'll need to reinstate them so the presubmits pass (some of the cells you added might need these tags too, if they're too long-running for the tests or the cell output is different on the CPU test runners e.g.)
  • The sphinx build is failing and I'm not sure why: https://app.readthedocs.org/api/v2/build/31206675.txt It looks like this might be the relevant line:
/home/docs/checkouts/readthedocs.org/user_builds/jax-ai-stack/checkouts/293/docs/source/JAX_for_LLM_pretraining.ipynb:650002: WARNING: skipping unknown output mime type: application/vnd.google.colaboratory.intrinsic+json [mystnb.unknown_mime_type] [mystnb.unknown_mime_type]

If you could take a look, that would be great.

"\n",
"By the end of this tutorial, you will be able to:\n",
"\n",
"- **Understand JAX's parallelism capabilities**: Learn how to leverage data and tensor parallelism to distribute training across multiple TPU devices\n",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

say "TPU or GPU" to emphasize JAX is multi-platform

},
"outputs": [],
"outputs": [

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert the outputs?

"tags": [
"nbval-ignore-output"
]
"outputId": "29c2e1dc-e49c-484a-96db-3b6c0df901a5"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to keep the nbval-ignore-output tags. The notebook integration tests compare the output of the run cell with the saved output and error if they're different, and the tag bypasses the error.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, could you clear the outputs of this cell?

"outputs": [],
"source": [
"# Verify that an accelerator (GPU/TPU) is available\n",
"# This tutorial requires hardware acceleration and cannot run on CPU\n",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to allow it to be run on CPU, besides that it's slow? I'm wondering if this should be a warning instead.

"- **Automatic parallelization**: JAX can automatically distribute computations across multiple devices using SPMD (Single Program, Multiple Data) parallelism\n",
"- **Functional programming**: JAX encourages pure functions, which enables reliable transformations and better performance\n",
"\n",
"For training large language models like our miniGPT, JAX's automatic parallelization capabilities are particularly valuable. They allow us to efficiently utilize multiple TPU cores without manually managing device placement and communication."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's mention GPUs here too, again to emphasize multi-platform capabilities and not imply we're TPU-only

"metadata": {
"id": "Mtzb0NXb8TVY",
"tags": [
"nbval-ignore-output"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reinstate nbval-ignore-output?

"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m242.4/242.4 kB\u001b[0m \u001b[31m24.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m221.6/221.6 kB\u001b[0m \u001b[31m22.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m377.3/377.3 kB\u001b[0m \u001b[31m32.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m21.4/21.4 MB\u001b[0m \u001b[31m104.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear cell output?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need tensorflow anymore -- could you take a look at https://docs.jax.dev/en/latest/profiling.html and check that this is up to date?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! According to my colleague, using Perfetto here is not really feasible.

It's blocking execution, analizing single trace rather than a batch as would be the case in training (multiple training steps executions).

We can dive deeper into that if you think it's really important for this tutorial.

Comment thread docs/source/JAX_for_LLM_pretraining.ipynb
Comment thread docs/source/JAX_for_LLM_pretraining.ipynb

@emilyfertig emilyfertig left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @f33ac could you please sign the Contributor License Agreement? (See the link in the cla/google presubmit). Thanks!

]
},
{
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you delete these three lines? (2543-2545) That should fix the readthedocs build.

@f33ac

f33ac commented Feb 10, 2026

Copy link
Copy Markdown
Author

Hey @emilyfertig!
I've released a new version with the tags fixed. Here are all the validatoin that I've run on my side:

>>>> jupytext --sync docs/source/JAX_for_LLM_pretraining.ipynb
[jupytext] Reading docs/source/JAX_for_LLM_pretraining.ipynb in format ipynb
[jupytext] Loading docs/source/JAX_for_LLM_pretraining.md
[jupytext] Updating docs/source/JAX_for_LLM_pretraining.md
---
>>>>> git add docs/source/JAX_for_LLM_pretraining.*
---
>>>>> pre-commit run         
check python ast.....................................(no files to check)Skipped
check for merge conflicts................................................Passed
check toml...........................................(no files to check)Skipped
check yaml...........................................(no files to check)Skipped
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
debug statements (python)............................(no files to check)Skipped
pyink................................................(no files to check)Skipped
ruff.....................................................................Passed
jupytext.................................................................Passed

---
>>>> pytest --nbval docs/source/JAX_for_LLM_pretraining.ipynb 
====================================== test session starts ======================================
platform darwin -- Python 3.13.5, pytest-9.0.2, pluggy-1.6.0
rootdir: /Users/adam/Projects/JAX/jax-ai-stack
configfile: pyproject.toml
plugins: xdist-3.8.0, jaxtyping-0.3.7, nbval-0.11.0
collected 36 items                                                                              

docs/source/JAX_for_LLM_pretraining.ipynb s.ss...........s.ssssssss.ssssss..ss            [100%]

================================ 16 passed, 20 skipped in 6.15s =================================

@emilyfertig
emilyfertig merged commit 75cafc8 into jax-ml:revamp-2025 Mar 10, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants