Skip to content

recipes(397b v7x): trainer perf flags (SparseCore offload thresholds, decoder-layer-input placement) and MaxText gather-once pin - #2895

Closed
khatwanimohit wants to merge 2 commits into
parambole/ours275-trainer-configfrom
mohit/trainer-perf-flags
Closed

khatwanimohit wants to merge 2 commits into
parambole/ours275-trainer-configfrom
mohit/trainer-perf-flags

Conversation

@khatwanimohit

Copy link
Copy Markdown
Collaborator

Stacked on #2878 (parambole/ours275-trainer-config); retarget to atwigg/mlperf once it lands.

Trainer performance changes for the 397B v7x recipes, measured or compiled on the RL trainer bench (AI-Hypercomputer/maxtext#5701, 128 chips):

Change Flag Default Evidence
SparseCore offload only for large collectives: all-reduces from 64 MiB, all-gathers from 256 MiB, so the small per-layer ones skip the busy SparseCore queue TRAINER_SC_OFFLOAD_THRESHOLDS off in mlperf_397b_256_v7x.sh, on in mlperf_gbs1024_submission.sh bench: 106.5 -> 105.1 s/step
Keep each layer's input in HBM instead of host offload (decoder_layer_input) REMAT_DECODER_LAYER_INPUT (offload/device) offload (unchanged) removes ~115 ms/micro-batch of DMA wait in the profile; +~1 GiB AOT
MaxText pin: #5718 + AI-Hypercomputer/maxtext#5740, #5741, #5742 (gather small FSDP-sharded kernels once per scanned layer stack) none (fixed behaviour in MaxText) on with this pin ~1.2 s/micro-batch of synchronous all-gathers exposed in the profile; AOT + small-model gradient checks in those PRs

MoE token chunking (a candidate lever for the dependency-bound MoE token all-gather/reduce-scatter) needs no change here: NUM_MOE_TOKEN_CHUNKS=4 already overrides the tuned value.

Dry run (DRY_RUN=true ... mlperf_gbs1024_submission.sh start with REMAT_DECODER_LAYER_INPUT=device): both threshold flags appear in the trainer env, the Pathways workers and the proxy; decoder_layer_input=device in the trainer's MaxText flags.

Bench runs of the combined changes are pending capacity.

TRAINER_SC_OFFLOAD_THRESHOLDS=true (on in mlperf_gbs1024_submission.sh) keeps
small all-reduces (<64 MiB) and all-gathers (<256 MiB) on the TensorCore path
so they skip the busy SparseCore queue. RL trainer bench: 106.5 -> 105.1 s/step.

(cherry picked from commit 6d589fb3d9c9ad9aedca29eea995f071e40bf488)
…her-once PRs

- REMAT_DECODER_LAYER_INPUT (offload by default, as before) sets the trainer's
  decoder_layer_input; device keeps each layer's input in HBM and drops the
  per-layer host round trip.
- MaxText pin: atwigg/mlperf + AI-Hypercomputer/maxtext#5718 + #5740-#5742,
  which gather the small FSDP-sharded kernels (router, query, shared expert,
  GDN in_proj_ba, K/V) once per scanned layer stack instead of in every layer.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces performance optimizations for the 397B v7x trainer recipes. The changes focus on fine-tuning collective offloading thresholds, providing more control over memory placement for decoder layer inputs, and updating core dependencies to leverage recent improvements in MaxText for more efficient kernel execution.

Highlights

  • SparseCore Offload Thresholds: Introduced configurable thresholds for SparseCore offloading to optimize collective operations, reducing overhead for small per-layer collectives.
  • Decoder Layer Input Placement: Added the REMAT_DECODER_LAYER_INPUT flag to allow keeping layer inputs in HBM instead of host offload, reducing DMA wait times.
  • MaxText Dependency Update: Updated MaxText requirements to include performance improvements related to FSDP-sharded kernel gathering.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the MaxText requirements and introduces new performance tuning configurations in the MLPerf recipes, specifically adding options for SparseCore offload thresholds (TRAINER_SC_OFFLOAD_THRESHOLDS) and decoder layer input rematerialization (REMAT_DECODER_LAYER_INPUT). The review feedback recommends validating these environment variables to ensure they only accept valid values and fail loud and fast on invalid inputs, as well as checking for duplicate flags when appending to TRAINER_LIBTPU_INIT_ARGS.

Comment on lines +133 to +135
if [[ "${TRAINER_SC_OFFLOAD_THRESHOLDS:-false}" == "true" ]]; then
export TRAINER_LIBTPU_INIT_ARGS="${TRAINER_LIBTPU_INIT_ARGS} --xla_tpu_sparse_core_all_reduce_offload_min_size_in_bytes=67108864 --xla_tpu_sparse_core_all_gather_offload_min_size_in_bytes=268435456"
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Validate the TRAINER_SC_OFFLOAD_THRESHOLDS environment variable to ensure it is strictly set to true or false (failing loud and fast on invalid inputs), and check if the corresponding SparseCore flags are already present in TRAINER_LIBTPU_INIT_ARGS before appending them to avoid duplicates.

Suggested change
if [[ "${TRAINER_SC_OFFLOAD_THRESHOLDS:-false}" == "true" ]]; then
export TRAINER_LIBTPU_INIT_ARGS="${TRAINER_LIBTPU_INIT_ARGS} --xla_tpu_sparse_core_all_reduce_offload_min_size_in_bytes=67108864 --xla_tpu_sparse_core_all_gather_offload_min_size_in_bytes=268435456"
fi
case "${TRAINER_SC_OFFLOAD_THRESHOLDS:-false}" in
true)
if [[ " ${TRAINER_LIBTPU_INIT_ARGS} " != *" --xla_tpu_sparse_core_all_reduce_offload_min_size_in_bytes="* ]]; then
export TRAINER_LIBTPU_INIT_ARGS="${TRAINER_LIBTPU_INIT_ARGS} --xla_tpu_sparse_core_all_reduce_offload_min_size_in_bytes=67108864"
fi
if [[ " ${TRAINER_LIBTPU_INIT_ARGS} " != *" --xla_tpu_sparse_core_all_gather_offload_min_size_in_bytes="* ]]; then
export TRAINER_LIBTPU_INIT_ARGS="${TRAINER_LIBTPU_INIT_ARGS} --xla_tpu_sparse_core_all_gather_offload_min_size_in_bytes=268435456"
fi
;;
false)
;;
*)
echo "ERROR: TRAINER_SC_OFFLOAD_THRESHOLDS must be true or false, got '${TRAINER_SC_OFFLOAD_THRESHOLDS}'" >&2
exit 1
;;
esac
References
  1. Fail loud and fast: Never mask missing attributes, invalid types, or broken invariants with silent default values. Let Python raise ... or raise an explicit ValueError / specific exception immediately. (link)

# (decoder_layer_input). offload (default) parks it in host memory; device keeps it in HBM, which
# drops the per-layer host round trip (~115 ms of DMA wait per micro-batch on the RL trainer bench,
# AI-Hypercomputer/maxtext#5701) for ~1 GiB of HBM (AOT, tpu7x-256).
export REMAT_DECODER_LAYER_INPUT="${REMAT_DECODER_LAYER_INPUT:-offload}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Validate the REMAT_DECODER_LAYER_INPUT environment variable to ensure it is strictly set to either offload or device to fail loud and fast on invalid inputs.

Suggested change
export REMAT_DECODER_LAYER_INPUT="${REMAT_DECODER_LAYER_INPUT:-offload}"
export REMAT_DECODER_LAYER_INPUT="${REMAT_DECODER_LAYER_INPUT:-offload}"
case "${REMAT_DECODER_LAYER_INPUT}" in
offload|device)
;;
*)
echo "ERROR: REMAT_DECODER_LAYER_INPUT must be 'offload' or 'device', got '${REMAT_DECODER_LAYER_INPUT}'" >&2
exit 1
;;
esac
References
  1. Fail loud and fast: Never mask missing attributes, invalid types, or broken invariants with silent default values. Let Python raise ... or raise an explicit ValueError / specific exception immediately. (link)

@khatwanimohit

Copy link
Copy Markdown
Collaborator Author

Superseded by #2896 (same changes, based on atwigg/mlperf instead of #2878).

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.

2 participants