Remat policy + batch size estimation using AOT compilation #2504
+528
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
MaxText Estimator: Automatic Batch Size & Remat Policy Search
This PR introduces an estimation tool (
MaxText.estimator) that automatically searches for optimal training configurations to maximize performance and prevent OOM errors.It can operate in several modes:
context=offload).Example Usage
Here are a few examples of running the estimator for a
llama3.1-405bmodel on av5p-1024cluster.Search for both Batch Size and Remat Policy
This is the most common use case. The estimator will find the best
per_device_batch_sizeand the corresponding remat policy.Search for Remat Policy with a Fixed Batch Size
If you know your target batch size (e.g.,
per_device_batch_size=4), the tool will find the "lightest" remat policy (least rematerialization) that allows that batch size to fit in memory.Search with a Partially Fixed Policy
If you want to enforce specific remat settings (e.g., you know you want to remat
mlpwoand offloadcontext), you can fix them. The estimator will then search for the best batch size and policy for the remaining tensors.Search with Fixed Batch Size AND Partially Fixed Policy
You can also combine a fixed batch size with a partially fixed policy
Output
The program runs its search and saves all suggested runnable commands that it believes will yield high MFU without OOMing.
The results are written to a file named
remat_commands_from_estimator.txt.Example
FIXES: b/449559587
Tests
Please describe how you tested this change, and include any instructions and/or
commands to reproduce.
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.