maxtext-remat-estimator
Skill2.5k starsChanged 4 days agoApache-2.0View on GitHub
Finds rematerialization (remat) policies and per-device batch sizes that fit in TPU HBM for a MaxText training config, using the AOT-compile-based estimator (`maxtext.utils.estimator`) so the target hardware is not needed. Use when a MaxText training run runs out of HBM, when choosing `remat_policy` or custom per-tensor `remat`/`offload`/`device` settings, when looking for the largest `per_device_batch_size` that fits a model on a TPU topology, or when sizing a run for hardware you do not have yet. Don't use it to measure step time or MFU; the estimator only checks whether a configuration fits in memory.
Trending
Less talk lately.about the whole repository
Who's talking about AI-Hypercomputer/maxtext
- ROCm/jax-titan“General Adapters”GitHub · Nov 19, 2026 · 1 reactions
- google/tunix“Let the dist_rl rollout node load MaxText checkpoints without weight sync”GitHub · Nov 19, 2026 · 1 reactions
- google/tunix“Stacked on #2979 (`uwlei/rl-4600-final-tunix` @ `54f488d8`); **retarget base branch to `atwigg/mlperf` once …”GitHub · Oct 21, 2026 · 1 reactions
- google/tunix“[MLPerf RL 397B]Supersedes #2884, #2948, #2913, and #2940 onto `atwigg/mlperf`.”GitHub · Oct 21, 2026 · 1 reactions
- AI-Hypercomputer/tpu-recipes“Add recipe for training Maxtext Qwen3.5-35B-A3B with v6e-256 #recipebot”GitHub · Oct 20, 2026 · 1 reactions
The biggest 5 of 50 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 50
Talked about on GitHub (50 times).
On GitHub · 50
- Nov 19, 2026General Adapters — ROCm/jax-titan1 reaction · 2 comments
- Nov 19, 2026Let the dist_rl rollout node load MaxText checkpoints without weight sync — google/tunix1 reaction · 1 comment
- Oct 21, 2026Stacked on #2979 (`uwlei/rl-4600-final-tunix` @ `54f488d8`); **retarget base branch to `atwigg/mlperf` once #2979 merges**. — google/tunix1 reaction · 2 comments
- Oct 21, 2026[MLPerf RL 397B]Supersedes #2884, #2948, #2913, and #2940 onto `atwigg/mlperf`. — google/tunix1 reaction · 2 comments
- Oct 20, 2026Add recipe for training Maxtext Qwen3.5-35B-A3B with v6e-256 #recipebot — AI-Hypercomputer/tpu-recipes1 reaction
45 more on GitHub
- Oct 15, 2026orchestrator: compact routed_experts wire packing with uint10/uint8 encoding and unrouted-token stripping — google/tunix1 reaction · 1 comment
- Oct 6, 2026feat(maxtext): bump commit pin for RBF overflow logging — google/tunix1 reaction · 1 comment
- Sep 30, 2026Add ROLLOUT_FP8 / TRAINER_FP8 switches for FP8 MoE in all recipe launchers — google/tunix1 reaction · 1 comment
- Sep 30, 2026feat(recipes): add FP8_MOE environment variable directly to mlperf recipes — google/tunix1 reaction · 1 comment
- Sep 19, 2026Migrate Llama 3.1 8B on Trillium (v6e-8) to Cluster Toolkit — AI-Hypercomputer/tpu-recipes1 reaction
- Oct 25, 2025Feature Enhancement: Add Advanced Post-Training and Fine-Tuning Capabilities to Simply — google-deepmind/simply1 reaction
- Dec 2, 2026With `weight_sync_config.mode: none` (evaluation), a MaxText vLLM rollout had no way to load real weights because config resolution required Raiden weight sync. Add checkpoint loading support for both unscanned and scanned MaxText checkpoints on the stock `dist_rl` rollout node, plus opt-in Pathways — google/tunix0 reactions · 1 comment
- Oct 30, 2026[AutoPGLE] Let the host run ahead and enqueue work — jax-ml/jax0 reactions
- Oct 20, 2026Migrate MaxText E2E checkpoint conversion (to-mt and to-hf) to CPU cluster — GoogleCloudPlatform/ml-auto-solutions0 reactions
- Oct 19, 2026Layer streaming: measure saving the attention projections instead of recomputing the whole layer — MakazhanAlpamys/Soup0 reactions · 3 comments
- Oct 16, 2026Migrate MaxText E2E checkpoint conversion (to-mt and to-hf) to CPU cluster — CIeNET-International/ml-auto-solutions-30 reactions · 1 comment
- Oct 14, 2026update maxtext pin — google/tunix0 reactions · 1 comment
- Oct 13, 2026recipes: opt-in Raiden trainer knobs for the pathways-worker and trainer client — google/tunix0 reactions · 2 comments
- Oct 12, 2026Documentation Link Check Failed - 2026-10-12 — gitrajav/maxtext0 reactions
- Oct 10, 2026recipes: add USE_BATCHED_RPA_LONG_CTX_KERNEL switch (default true) -> attention=vllm_batched_rpa_long_ctx — google/tunix0 reactions · 2 comments
- Oct 8, 2026feat(multipod): Add DAG `maxtext_distillation` with Cluster Toolkit — GoogleCloudPlatform/ml-auto-solutions0 reactions
- Oct 7, 2026feat(multipod): Add DAG `maxtext_distillation` with Cluster Toolkit — CIeNET-International/ml-auto-solutions-30 reactions · 1 comment
- Oct 7, 2026 feat(multipod): add `maxtext_distillation` DAG with Cluster Toolkit — GoogleCloudPlatform/ml-auto-solutions0 reactions
- Oct 5, 2026Documentation Link Check Failed - 2026-10-05 — gitrajav/maxtext0 reactions
- Oct 3, 2026[Add] MaxText (AI-Hypercomputer/maxtext) — PyTorchKR/landscape0 reactions
- Oct 3, 20263. MaxText: run one small pinned configuration after lower-level checks — egesamuray/jax-rocm-systems-lab0 reactions
- Sep 28, 2026Documentation Link Check Failed - 2026-09-28 — gitrajav/maxtext0 reactions
- Sep 21, 2026Documentation Link Check Failed - 2026-09-21 — gitrajav/maxtext0 reactions
- Sep 21, 2026feat(multipod): Add test_scope param to `maxtext_e2e_tests` — GoogleCloudPlatform/ml-auto-solutions0 reactions
- Sep 21, 2026feat(multipod): Add test_scope param to `maxtext_e2e_tests` — CIeNET-International/ml-auto-solutions-30 reactions · 5 comments
- Sep 19, 2026[RL] Sever autodiff graph with jnp.where on masked/padded tokens in G… — google/tunix0 reactions
- Sep 17, 2026# Description — matrawybarte-lgtm/gpc0 reactions
- Sep 15, 2026fix(checkpointing, infra): orchestrator save interval, save-sync serialization, memory requests, and fail-fast — google/tunix0 reactions
- Sep 14, 2026Documentation Link Check Failed - 2026-09-14 — gitrajav/maxtext0 reactions
- Sep 7, 2026Documentation Link Check Failed - 2026-09-07 — gitrajav/maxtext0 reactions
- Aug 31, 2026Documentation Link Check Failed - 2026-08-31 — gitrajav/maxtext0 reactions
- Aug 24, 2026feat: support multimodal models and eager loading in checkpoint conversion — GoogleCloudPlatform/accelerated-platforms0 reactions
- Aug 24, 2026Documentation Link Check Failed - 2026-08-24 — gitrajav/maxtext0 reactions
- Aug 22, 2026feat: RLVllmSampler weight sync via Raiden, bound in-process in the EngineCore worker — vllm-project/tpu-inference0 reactions · 1 comment
- Aug 18, 2026Update MaxText E2E TPU DAG checkpoint paths for reduced step count — GoogleCloudPlatform/ml-auto-solutions0 reactions
- Aug 17, 2026Documentation Link Check Failed - 2026-08-17 — gitrajav/maxtext0 reactions
- Aug 10, 2026Documentation Link Check Failed - 2026-08-10 — gitrajav/maxtext0 reactions
- Jul 20, 2026Update maxtext_moe_tpu_e2e DAG: hf access token & refactor — GoogleCloudPlatform/ml-auto-solutions0 reactions
- Jul 17, 2026[Maxtext] [Tunix] New Weight Sync for Post-train, maxtext -> maxtext — google/tunix0 reactions
- Jul 16, 2026feat: Restrict DAG `maxtext_e2e_tests` to GitHub schedule events — GoogleCloudPlatform/ml-auto-solutions0 reactions
- Jul 16, 2026feat: Restrict DAG `maxtext_e2e_tests` to GitHub schedule events — CIeNET-International/ml-auto-solutions-30 reactions · 2 comments
- Jun 9, 2026add qwen3.5 35b to xlml tests — GoogleCloudPlatform/ml-auto-solutions0 reactions
- May 21, 2026Remove collect_stack_trace config from checkpointing test — GoogleCloudPlatform/ml-auto-solutions0 reactions
- Feb 24, 2026Experiment: cast pallas xent dW to bf16 (keep fp32 accum) and validate speed + numerics — marin-community/marin0 reactions · 2 comments
- Feb 20, 2026Add Qwen3-Next tests to MaxText_MoE DAG — GoogleCloudPlatform/ml-auto-solutions0 reactions
In this repository6 other files it gives its agents.
- AGENTS.mdAGENTS.md
- maxtext-goodputSkill
- maxtext-pr-uploadSkill
- model-bringup-m3Skill
- model-bringupSkill
- update-changelogSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 53
Every probe is a full compile.
- Very specific: line 62
Environment: use the same install as train_compile: a MaxText environment with jax[tpu].
- Distinctive: line 133
Before you launch a generated command:
- Very specific: line 146
Start by benchmarking the last result for each pdb on the target hardware, and compare Tokens/s/device once step time is steady.
- Distinctive: line 172
Mode 1 stops at pdb 32: If full remat still fits at pdb 32, the results start there.
- Distinctive: line 190
Remove the compile-only flags from the chosen command.
- Very specific: line 194
If two candidates are close, capture XProf traces (profiler=xplane) to see how much time goes to recomputation and host transfers.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
MaxText Remat & Batch Size Estimator
maxtext.utils.estimator searches custom remat policies and
per_device_batch_size values. It checks each candidate by compiling the
training step ahead of time (AOT) for compile_topology, so a CPU VM or a
single small TPU VM can size a run for a large pod.
Reference docs:
- Tuning remat policy, including estimator examples for Llama 3.1 405B and DeepSeek V3 671B
- Ahead-of-time compilation
- Implementation:
src/maxtext/utils/estimator.py,is_oomintrain_compile.py, and the custom remat keys inbase.yml
1. How the search works
Each probe appends per_device_batch_size=<pdb> remat_policy=custom <tensor>=remat|offload|device ...
to your arguments and compiles train_step with train_compile.is_oom. If the
compile error contains RESOURCE_EXHAUSTED or HBM, the probe counts as out of
memory. Any other compile error stops the search.
The estimator varies the dense decoder checkpoints:
context- the Q/K/V projections:
query_proj,key_proj,value_proj, andkv_proj, orqkv_proj - the MLP input:
mlpwi, ormlpwi_0andmlpwi_1 mlpwoandout_proj
It ranks them by size from max_target_length and the layer widths. The largest
tensors are rematerialized first and kept on device last.
| Mode | When | Search | Result |
| 1. Batch size and policy | per_device_batch_size not set | Finds the largest pdb (up to 32) that fits when every tensor is rematerialized. Then it moves tensors from remat to offload, smallest first, one at a time. When all of them are offloaded, it moves them to device the same way. After each move, it binary-searches the largest pdb that still fits. | Several (pdb, policy) pairs, from the largest batch with full remat to smaller batches with more tensors saved |
| 2. Policy only | per_device_batch_size=<pdb> set | Starts with every tensor on device. It moves tensors from device to offload, largest first, then from offload to remat, until a policy fits. It raises ValueError if the batch runs out of memory even with full remat. | One (pdb, policy) pair: the least remat that fits |
Every probe is a full compile. A probe takes seconds for a small dense model and
minutes for a large MoE. Mode 2 needs roughly two probes per searched tensor at
most. Mode 1 can need several dozen probes; for example, qwen3-0.6b on
v6e-4 took 53. Run Mode 1 under tmux or nohup for large models.
2. Before you run
- Environment: use the same install as
train_compile: a MaxText environment withjax[tpu]. A CPU VM or any TPU VM can compile for a TPU topology. On a TPU VM, setJAX_PLATFORMS=cpuso the probes don't claim the local chips. To run several estimator ortrain_compileprocesses at the same time, also setALLOW_MULTIPLE_LIBTPU_LOAD=1. Copy every flag that affects memory from the real run:
model_nameand any model overrides, plusmax_target_length- dtypes (
dtype,weight_dtype,grad_dtype,mu_dtype) andopt_type - sharding:
ici_*anddcn_*parallelism,compile_topology, andcompile_topology_num_slices - attention and MoE kernel flags, and quantization
- host offload:
optimizer_memory_host_offloadandparameter_memory_host_offload LIBTPU_INIT_ARGS. XLA flags such as SparseCore collective offload change buffer assignment, which moves the OOM boundary.
Use
dataset_type=synthetic.- Compile once by hand with a setting that should fit. The estimator hides
compiler output during probes and stops on any non-OOM error, so fix
sharding and config errors first:
python3 -m maxtext.trainers.pre_train.train_compile src/maxtext/configs/base.yml \ <same args> remat_policy=full per_device_batch_size=1
3. Run the estimator
python3 -m maxtext.utils.estimator src/maxtext/configs/base.yml \
model_name=<model> \
compile_topology=<topology, e.g. v6e-256 or tpu7x-512> \
compile_topology_num_slices=<num_slices> \
max_target_length=<seq_len> \
ici_fsdp_parallelism=-1 <other sharding flags> \
<dtype, optimizer, kernel, and quantization flags from the real run> \
dataset_type=synthetic log_config=False \
write_estimator_result=True- To run Mode 2 instead of Mode 1, add
per_device_batch_size=<pdb>. - Pin a tensor by passing it yourself, such as
context=deviceormlpwo=offload. A pinned tensor keeps that setting and leaves the search. decoder_layer_inputstays ondeviceunless you passdecoder_layer_input=offload. Offloading it moves each layer's saved input to host memory, which helps with long sequences and deep models.- Mode 1 steps
per_device_batch_sizeby1/s. Heresis the product of theici_*_parallelismvalues over every mesh axis exceptdata,fsdp,fsdp_transpose,expert, andstage. For example,ici_tensor_parallelism=4gives steps of0.25. - You don't need to pass
remat_policy. Every probe appendsremat_policy=custom, and repeated flags take the last value.
4. Read the results
Each probe prints Checking whether batch_size=<pdb> and policy={...} is OOM
and then Is OOM: True or Is OOM: False. The search finishes with one or
more lines like this one:
- Found valid combo: pdb=2.0, policy={'mlpwo': 'offload', 'context': 'offload', ..., 'key_proj': 'device'}With write_estimator_result=True, the estimator also writes
remat_commands_from_estimator.txt in the current directory. The file holds one
runnable python -m maxtext.trainers.pre_train.train ... command per result.
Each run overwrites it.
Before you launch a generated command:
- Remove
compile_topologyandcompile_topology_num_slices. Whilecompile_topologyis set, MaxText sizes the mesh from the virtual topology and skipsjax.distributedinitialization. - Add the run-specific flags the estimator didn't need. These include
run_name,base_output_directory, the real dataset,steps, and checkpointing.
Choose by measuring speed. The estimator reports what fits, not what is
fastest. Remat recomputes activations in the backward pass. Offload spends
host-to-device bandwidth. A smaller batch can leave the TPU's matrix units idle.
Mode 1 reports every step of its walk, so many results share a pdb. Within each
group that shares a pdb, the last result rematerializes the fewest tensors.
Start by benchmarking the last result for each pdb on the target hardware, and
compare Tokens/s/device once step time is steady. MaxText
computes its TFLOP/s/device figure from the model, without counting
recomputation, so that figure is also comparable across remat policies.
5. Pitfalls
- Tensors go to
offloadbeforedevice. In both modes, every searched tensor goes tooffloadbefore any tensor goes todevice, so many results rely heavily on offload. Host offload competes for PCIe bandwidth and can be slower than recomputing. If you suspect that, pin the tensors you want saved (for examplecontext=device) and search again. Some checkpoints are never searched. The keys in the printed policy are the only tensors the estimator varies. Every other checkpoint keeps its value from the config or command line, which defaults to
remat. That includes:- MoE:
moe_mlpwi_0,moe_mlpwi_1,moe_mlpwo,moe_x_sorted,moe_routing_maps - MLA:
query_wa_proj,kv_wa_proj,mla_q,mla_kv attention_out- GDN:
gdn,gdn_states,gdn_cp_state
To include any of them, pin them on the command line. The complete list of names that
remat_policy=customhonors is in theremat_policy == "custom"block oftypes.py.- MoE:
- Mode 1 stops at pdb 32. If full remat still fits at pdb 32, the results start there.
ValueError: Abnormal min_pdb=... or max_pdb=0.0 valuesmeans nothing fits. Mode 1 raises it right after printingOOM at minimum batch size, when even the smallest batch runs out of memory with full remat. Add more sharding, setdecoder_layer_input=offload, or turn on optimizer or parameter host offload, and then search again.- Errors other than OOM end the search with a traceback. To see the full
compiler log, rerun
train_compilewith the pdb and policy from the last probe. - Only
train_stepis compiled. The probes don't check eval steps, checkpoint save and restore, or anything else outsidetrain_step. Confirm the chosen configuration on hardware.
6. Verify on hardware
- Remove the compile-only flags from the chosen command. Run it for about 20 steps with the production data, checkpointing, and eval settings.
- Confirm it doesn't run out of memory. Record step time and
Tokens/s/deviceafter warmup. - If two candidates are close, capture XProf traces (
profiler=xplane) to see how much time goes to recomputation and host transfers.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

