Skip to content

Commit b3f7b4b

Browse files
committed
Add a new goodput elastic utils function record_slice_state()
1 parent c3d6fdc commit b3f7b4b

52 files changed

Lines changed: 541 additions & 2362 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/run_pathways_tests.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,9 @@ jobs:
7272
options: ${{ inputs.container_resource_option }}
7373
steps:
7474
- name: Checkout MaxText
75-
run: |
76-
git config --global --add safe.directory /__w/maxtext/maxtext
77-
git clone https://github.com/google/maxtext.git .
78-
git fetch origin ${{ inputs.maxtext_sha }}
79-
git checkout FETCH_HEAD
75+
uses: actions/checkout@v5
76+
with:
77+
ref: ${{ inputs.maxtext_sha }}
8078
- name: Download the maxtext wheel
8179
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
8280
with:

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ See our guide on running MaxText in decoupled mode, without any GCP dependencies
4242

4343
## 🔥 Latest news 🔥
4444

45-
- [June 9, 2026] Qwen3.5 35B & 397B is now [supported](https://github.com/AI-Hypercomputer/maxtext/blob/main/tests/end_to_end/tpu/qwen/moe/run_qwen_moe.md).
4645
- [May 29, 2026] A new eval framework is now available for running lm-eval, evalchemy, and custom benchmarks against MaxText checkpoints. See the [Evaluation guide](https://maxtext.readthedocs.io/en/latest/guides/eval_framework.html) to get started.
4746
- [May 6, 2026] Kimi-K2-Thinking, Kimi-K2.5 (text), and Kimi-K2.6 (text) are now supported. See [Run_Kimi.md](https://github.com/AI-Hypercomputer/maxtext/blob/main/tests/end_to_end/tpu/kimi/Run_Kimi.md#quantized-variants-k2-thinking-k25-k26) for details.
4847
- [April 18, 2026] Added a new notebook [maxtext_with_gepa.ipynb](https://github.com/AI-Hypercomputer/maxtext/blob/3c7d8d27864fc12cccac07786f02bd0e5262c982/src/maxtext/examples/maxtext_with_gepa.ipynb) for optimizing AIME prompts using the GEPA framework with Maxtext.
@@ -123,7 +122,6 @@ MaxText aims to provide you with the best OSS models, whether as a reference imp
123122
- Gemma 2 (2B, 9B, 27B)
124123
- Gemma 1 (2B, 7B)
125124
- Alibaba
126-
- Qwen 3.5 MoE (35B, 397B)
127125
- Qwen 3 Next (80B)
128126
- Qwen 3 MoE (30B, 235B), Qwen 3 MoE 2507 (235B, 480B)
129127
- Qwen 3 Dense (0.6B, 1.7B, 4B, 8B, 14B, 32B)

docs/guides/checkpointing_solutions/convert_checkpoint.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Use the `to_maxtext.py` script to convert a Hugging Face model checkpoint into a
3636
### Setup Environment
3737

3838
```bash
39+
# Install PyTorch and safetensors (in MaxText virtual environment)
40+
python3 -m pip install torch --index-url https://download.pytorch.org/whl/cpu
41+
python3 -m pip install safetensors --no-deps
42+
3943
# Setup environment variables
4044
export MODEL=<HF_MODEL> # e.g. 'llama3.1-8b-Instruct'
4145
export BASE_OUTPUT_DIRECTORY=<CKPT_PATH> # e.g., gs://my-bucket/my-checkpoint-directory
@@ -83,6 +87,10 @@ Use the `to_huggingface.py` script to convert a MaxText checkpoint into the Hugg
8387
### Setup Environment
8488

8589
```bash
90+
# Install PyTorch and safetensors (in MaxText virtual environment)
91+
python3 -m pip install torch --index-url https://download.pytorch.org/whl/cpu
92+
python3 -m pip install safetensors --no-deps
93+
8694
# Setup environment variables
8795
export MODEL=<MODEL_NAME> # e.g. 'qwen3-4b'
8896
export MAXTEXT_CKPT_PATH=<CKPT_PATH> # e.g., gs://my-bucket/my-model-checkpoint/0/items
@@ -128,9 +136,6 @@ To ensure the conversion was successful, you can use the [test script](https://g
128136
export MODEL=<MODEL_NAME> # e.g. 'qwen3-4b'
129137
export MAXTEXT_CKPT_PATH=<CKPT_PATH> # e.g., gs://my-bucket/my-model-checkpoint/0/items
130138
export HF_CKPT_PATH=<HF_CKPT_PATH> # e.g., gs://my-bucket/my-checkpoint-directory
131-
132-
# Install PyTorch (in MaxText virtual environment)
133-
python3 -m pip install torch --index-url https://download.pytorch.org/whl/cpu
134139
```
135140

136141
### Run Correctness Test

docs/reference/models/supported_models_and_architectures.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ MaxText is an open-source, high-performance LLM framework written in Python/JAX.
4747
- **Variants**: Dense (0.6B–32B); MoE (30B-A3B, 235B-A22B, 480B Coder), MoE with Hybrid Attention (Next-80B-A3B)
4848
- **Notes**: **QK-Norm**, GQA, SwiGLU, RMSNorm, RoPE, GatedDeltaNet.
4949

50-
### Qwen3.5
51-
52-
- **Variants** MoE with Hybrid Attention (35B-A3B, 397B-A17B)
53-
- **Notes**: GatedDeltaNet, GQA, Multimodal, MoE.
54-
5550
### GPT-OSS
5651

5752
- **Variants**: 20B, 120B
@@ -94,10 +89,7 @@ The following summarizes observed runtime efficiency and scaling behaviors of Ma
9489
- **Gemma**: [Guide](https://github.com/AI-Hypercomputer/maxtext/blob/main/tests/end_to_end/tpu/gemma/Run_Gemma.md) | [Gemma Source](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/models/gemma.py) | [Gemma2 Source](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/models/gemma2.py) | [Gemma3 Source](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/models/gemma3.py) | [Gemma4 Source](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/models/gemma4.py)
9590
- **Mixtral**: [Guide](https://github.com/AI-Hypercomputer/maxtext/blob/main/tests/end_to_end/tpu/mixtral/Run_Mixtral.md) | [Mixtral Source](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/models/mixtral.py) | [Mistral Source](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/models/mistral.py)
9691
- **DeepSeek**: [Guide](https://github.com/AI-Hypercomputer/maxtext/blob/main/tests/end_to_end/tpu/deepseek/Run_DeepSeek.md) | [DeepSeek Source](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/models/deepseek.py)
97-
- **Qwen**: [Guide](https://github.com/AI-Hypercomputer/maxtext/blob/main/tests/end_to_end/tpu/qwen/moe/run_qwen_moe.md) |
98-
[Qwen3-Next Guide](https://github.com/AI-Hypercomputer/maxtext/blob/main/tests/end_to_end/tpu/qwen/next/run_qwen3_next.md) |
99-
[Qwen3 Source](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/models/qwen3.py) | [Qwen3-Next Source](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/models/qwen3.py) |
100-
[Qwen3.5 Source](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/models/qwen3_5.py)
92+
- **Qwen3**: [Guide](https://github.com/AI-Hypercomputer/maxtext/blob/main/tests/end_to_end/tpu/qwen/moe/run_qwen_moe.md) | [Qwen3-Next Guide](https://github.com/AI-Hypercomputer/maxtext/blob/main/tests/end_to_end/tpu/qwen/next/run_qwen3_next.md) | [Qwen3 Source](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/models/qwen3.py) | [Qwen3-Next Source](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/models/qwen3.py)
10193
- **GPT-OSS**: [Guide](https://github.com/AI-Hypercomputer/maxtext/blob/main/tests/end_to_end/tpu/gpt_oss/run_gpt_oss.md) | [GPT-OSS Source](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/models/gpt_oss.py)
10294
- **Kimi**: [Guide](https://github.com/AI-Hypercomputer/maxtext/blob/main/tests/end_to_end/tpu/kimi/Run_Kimi.md) | [K2 reuses DeepSeek Source](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/models/deepseek.py)
10395

docs/release_notes.md

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,6 @@ MaxText is [available in PyPI](https://pypi.org/project/maxtext/) and can be ins
2222

2323
## Releases
2424

25-
### v0.2.3
26-
27-
#### Changes
28-
29-
- Upgraded JAX to version 0.10.0 for pre-training and 0.10.1 for post-training.
30-
- **New vLLM-Powered Evaluation Framework**: Introduced an eval framework for running lm-eval, evalchemy, and custom benchmarking against MaxText checkpoints. See the [evaluation guide](https://maxtext.readthedocs.io/en/latest/guides/eval_framework.html) for details.
31-
- Added support for pre-training new models:
32-
- **Qwen3.5**: Qwen3.5 35B & 397B is now [supported](https://github.com/AI-Hypercomputer/maxtext/blob/d938b91acaa3baaaf32956e21677bd29e14549a1/tests/end_to_end/tpu/qwen/moe/run_qwen_moe.md).
33-
- **Qwen3-Omni**: Support for multimodal SFT ([PR #3863](https://github.com/AI-Hypercomputer/maxtext/pull/3863)).
34-
- **Direct Preference Optimization (DPO/ORPO) Support**: Full support for DPO and ORPO alignment pipelines. See the [DPO tutorial](https://maxtext.readthedocs.io/en/latest/tutorials/posttraining/dpo.html) for details.
35-
- **Reinforcement Learning (RL) Recipe**: Added a pre-configured [RL recipe for Qwen3-30b-a3b](https://maxtext.readthedocs.io/en/latest/tutorials/posttraining/rl_qwen3_30b.html).
36-
- **Iterative Quality Monitoring (RL)**: Added intermediate evaluation hooks to automatically run quality benchmarks during RL training (every `eval_interval` steps), optimized with a new `eval_batch_size` configuration knob.
37-
- **Developer Extensibility**: Added `dataset_processor_path` CLI knob for custom dataset integration, and refactored shared post-training hooks to simplify custom SFT, DPO, and RL workflow development.
38-
- **Generalized Learn-to-Init (LTI) for Distillation**: Enhanced post-training distillation capabilities with generalized LTI support.
39-
- Added support for recording elastic goodput events during training to track efficiency ([PR #3901](https://github.com/AI-Hypercomputer/maxtext/pull/3901)).
40-
- **Installation Updates**: Updated the `[tpu-post-train]` installation command to require `UV_TORCH_BACKEND=cpu`(see [Installation Guide](install_maxtext.md)).
41-
- **Zero1 AOT Compilation**: Added zero1 support to Ahead-Of-Time (AOT) compilation in train compile, improving compilation capabilities for zero1 config.
42-
- **MoE Performance Optimization**: Integrated ragged gather reduce into Mixture of Experts (MoE) layers to optimize memory and performance by replacing ragged scatter and supporting backward pass.
43-
- Added [E2E scripts](https://github.com/AI-Hypercomputer/maxtext/tree/main/tests/end_to_end/tpu/gemma3/4b) to run checkpoint conversion, pre-training and post-training (SFT, RL) with Gemma3-4B model.
44-
- **Bug Fixes and Usability Enhancements**:
45-
- **Attention Masking Fix in RL**: Fixed an issue in `TunixMaxTextAdapter` where queries at non-pad positions could attend to pad-position keys during training, which was corrupting log-probabilities and affecting GRPO training reward trajectories ([PR #4016](https://github.com/AI-Hypercomputer/maxtext/pull/4016)).
46-
- **JAX/NNX Gradient Mutation Fix**: Refactored post-training loops (`train_distill`, `train_sft`, `train_rl`) to use `jax.value_and_grad` with explicit NNX state split/merge instead of nesting `nnx.value_and_grad` inside `nnx.jit` ([PR #3652](https://github.com/AI-Hypercomputer/maxtext/pull/3652)).
47-
- **Qwen3-MoE Checkpoint Conversion**: Fixed checkpoint conversion issues for Qwen3-MoE models ([PR #3868](https://github.com/AI-Hypercomputer/maxtext/pull/3868)).
48-
- **Duplicate Configuration Failures Fix**: Allowed identical config overrides and handled configuration exceptions cleanly ([PR #3933](https://github.com/AI-Hypercomputer/maxtext/pull/3933)).
49-
- **Documentation Improvements**: Updated [Getting started](https://maxtext.readthedocs.io/en/latest/getting_started.html) guide, including new guides for the [evaluation framework](https://maxtext.readthedocs.io/en/latest/guides/eval_framework.html) and the [DPO tutorial](https://maxtext.readthedocs.io/en/latest/tutorials/posttraining/dpo.html).
50-
51-
#### Deprecations
52-
53-
- Deleted [legacy DPO implementation](https://github.com/AI-Hypercomputer/maxtext/pull/3997) in favor of the integrated [DPO trainer](https://maxtext.readthedocs.io/en/latest/tutorials/posttraining/dpo.html).
54-
- Removed stack trace collection feature.
55-
5625
### v0.2.2
5726

5827
#### Changes

src/maxtext/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"""
2020

2121
__author__ = "Google LLC"
22-
__version__ = "0.2.3"
22+
__version__ = "0.2.2"
2323
__description__ = (
2424
"MaxText is a high performance, highly scalable, open-source LLM written in pure Python/Jax and "
2525
"targeting Google Cloud TPUs and GPUs for training and **inference."

src/maxtext/checkpoint_conversion/to_maxtext.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
from maxtext.common.common_types import MODEL_MODE_TRAIN
6868
from maxtext.checkpoint_conversion.utils.hf_model_configs import HF_MODEL_CONFIGS
6969
from maxtext.checkpoint_conversion.utils.param_mapping import HOOK_FNS, PARAM_MAPPING
70-
from maxtext.checkpoint_conversion.utils.utils import MemoryMonitorTqdm, apply_hook_fns, load_hf_dict_from_transformers, load_hf_dict_from_safetensors, param_key_parts_from_path, print_peak_memory, print_ram_usage, save_weights_to_checkpoint, validate_and_filter_param_map_keys
70+
from maxtext.checkpoint_conversion.utils.utils import MemoryMonitorTqdm, apply_hook_fns, load_hf_dict_from_transformers, load_hf_dict_from_safetensors, print_peak_memory, print_ram_usage, save_weights_to_checkpoint, validate_and_filter_param_map_keys
7171
from maxtext.inference.inference_utils import str2bool
7272
from maxtext.layers import quantizations
7373
from maxtext.models import models
@@ -333,7 +333,8 @@ def get_maxtext_model_info(config):
333333
# preprocess state
334334
maxtext_abstract_dict = {}
335335
for mt_target_idx, (path_tuple, abstract_leaf_value) in enumerate(abstract_params_flat):
336-
mt_param_key = "params-" + "-".join(param_key_parts_from_path(path_tuple))
336+
key_parts = [k.key for k in path_tuple if hasattr(k, "key")]
337+
mt_param_key = "params-" + "-".join(key_parts)
337338
mt_target_shape = abstract_leaf_value.shape
338339
maxtext_abstract_dict[mt_param_key] = (mt_target_idx, mt_target_shape)
339340

src/maxtext/checkpoint_conversion/utils/hf_shape.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,6 @@ def MIXTRAL_HF_WEIGHTS_TO_SHAPE(config):
11311131
"llama3.1-70b": LLAMA31_HF_WEIGHTS_TO_SHAPE,
11321132
"llama3.1-405b": LLAMA31_HF_WEIGHTS_TO_SHAPE,
11331133
"qwen3-30b-a3b": QWEN_HF_WEIGHTS_TO_SHAPE,
1134-
"qwen3-30b-a3b-base": QWEN_HF_WEIGHTS_TO_SHAPE,
11351134
"qwen3-235b-a22b": QWEN_HF_WEIGHTS_TO_SHAPE,
11361135
"qwen3-480b-a35b": QWEN_HF_WEIGHTS_TO_SHAPE,
11371136
"deepseek2-16b": DEEPSEEK_HF_WEIGHTS_TO_SHAPE,

src/maxtext/checkpoint_conversion/utils/utils.py

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -888,51 +888,6 @@ def save_adapter_files(output_dir, weights, config, found_modules, model_id):
888888
json.dump(adapter_config, f, indent=4)
889889

890890

891-
def param_key_parts_from_path(path_tuple) -> list[str]:
892-
"""Convert a JAX tree path into MaxText dash-joined key segments.
893-
894-
Normalizes two NNX storage artifacts so the result follows the MaxText-Linen
895-
naming convention and matches the param-mapping tables (e.g.
896-
``params-decoder-layers_0-self_attention-query-kernel``):
897-
898-
* ``nnx.List`` layer stacks flatten to an *integer* path key
899-
(``decoder -> layers -> 0 -> ...``), which Orbax may restore as a numeric
900-
*string* (``"0"``). Either form is folded into the preceding segment as
901-
``<name>_<idx>`` (``layers_0``), matching Linen's ``layers_0`` name. (A pure
902-
integer key would otherwise raise ``TypeError: sequence item N: expected str
903-
instance, int found`` when joined; a string ``"0"`` would mismatch the
904-
``layers_0`` mapping.)
905-
* ``nnx.Variable`` leaves flatten with a trailing ``value`` key
906-
(``...-kernel -> value``). That wrapper segment is dropped, since MaxText-Linen
907-
param keys have no such suffix.
908-
909-
Scanned / plain Linen string paths (no integer key, no trailing ``value``) are
910-
returned unchanged.
911-
912-
Args:
913-
path_tuple: A path produced by ``jax.tree_util.tree_flatten_with_path`` or
914-
``tree_leaves_with_path`` (a sequence of ``DictKey`` / ``SequenceKey`` /
915-
``GetAttrKey`` / ``FlattenedIndexKey`` entries).
916-
917-
Returns:
918-
The list of string key segments, e.g. ``["decoder", "layers_0", "kernel"]``.
919-
"""
920-
parts: list[str] = []
921-
for entry in path_tuple:
922-
key = getattr(entry, "key", getattr(entry, "idx", getattr(entry, "name", entry)))
923-
# Fold a layer/expert index (an int, or a numeric string after an Orbax
924-
# round-trip) into the preceding segment: ["layers", 0] -> "layers_0".
925-
if (isinstance(key, int) or (isinstance(key, str) and key.isdigit())) and parts:
926-
parts[-1] = f"{parts[-1]}_{key}"
927-
else:
928-
parts.append(str(key))
929-
# Drop the trailing ``value`` segment that NNX adds for each ``nnx.Variable``
930-
# leaf (``...-kernel -> value``); MaxText-Linen param keys have no such wrapper.
931-
if parts and parts[-1] == "value":
932-
parts.pop()
933-
return parts
934-
935-
936891
def extract_nnx_weights(weights_dict: dict) -> dict[str, np.ndarray]:
937892
"""Extract weights from NNX checkpoint structure.
938893
@@ -948,10 +903,13 @@ def extract_nnx_weights(weights_dict: dict) -> dict[str, np.ndarray]:
948903
result = {}
949904
leaves_with_paths = jax.tree_util.tree_leaves_with_path(weights_dict)
950905
for path_tuple, leaf_value in leaves_with_paths:
951-
path_keys = param_key_parts_from_path(path_tuple)
906+
path_keys = [k.key for k in path_tuple]
952907
# Skip NNX RNG state variables (not model weights)
953908
if "to_nnx__rngs" in path_keys or any(k.endswith("_rngs") for k in path_keys):
954909
continue
910+
# Skip if this is the "value" key itself - we want the parent path
911+
if path_keys[-1] == "value":
912+
path_keys = path_keys[:-1]
955913
maxtext_param_key = "params-" + "-".join(path_keys)
956914
if not isinstance(leaf_value, (jax.Array, np.ndarray)):
957915
raise ValueError(f"Leaf value for {maxtext_param_key} is not an array. Type: {type(leaf_value)}.")
@@ -974,7 +932,8 @@ def extract_linen_weights(weights_dict: dict) -> dict[str, np.ndarray]:
974932
result = {}
975933
leaves_with_paths = jax.tree_util.tree_leaves_with_path(weights_dict)
976934
for path_tuple, leaf_value in leaves_with_paths:
977-
path_keys = param_key_parts_from_path(path_tuple)
935+
path_keys = [k.key for k in path_tuple]
936+
# Construct maxtext_param_key from path_tuple
978937
maxtext_param_key = "params-" + "-".join(path_keys)
979938
if not isinstance(leaf_value, (jax.Array, np.ndarray)):
980939
raise ValueError(f"Leaf value for {maxtext_param_key} is not an array. Type: {type(leaf_value)}.")

src/maxtext/common/goodput.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import contextlib
2323
import jax
2424
from enum import Enum
25+
import pathwaysutils
2526
from maxtext.utils import max_logging
2627
from maxtext.common.gcloud_stub import goodput_modules
2728

@@ -66,18 +67,31 @@ def maybe_monitor_goodput(config):
6667
enable_gcp_goodput_metrics=config.enable_gcp_goodput_metrics,
6768
enable_gcp_step_deviation_metrics=config.enable_gcp_step_deviation_metrics,
6869
)
69-
goodput_monitor = monitoring.GoodputMonitor(
70+
monitor_class = monitoring.GoodputMonitor
71+
72+
if config.elastic_enabled:
73+
try:
74+
from ml_goodput_measurement import monitoring_elastic
75+
monitor_class = monitoring_elastic.ElasticGoodputMonitor
76+
except ImportError:
77+
max_logging.log("Elastic monitor failed!")
78+
pass
79+
80+
kwargs = dict(
7081
job_name=config.run_name,
7182
logger_name=f"goodput_{config.run_name}",
7283
tensorboard_dir=config.tensorboard_dir,
7384
upload_interval=config.goodput_upload_interval_seconds,
7485
monitoring_enabled=True,
75-
pathway_enabled=config.enable_pathways_goodput,
7686
include_badput_breakdown=True,
7787
include_step_deviation=config.monitor_step_time_deviation,
7888
step_deviation_interval_seconds=config.step_deviation_interval_seconds,
7989
gcp_options=gcp_options,
8090
)
91+
if monitor_class == monitoring.GoodputMonitor:
92+
kwargs["pathway_enabled"] = config.enable_pathways_goodput
93+
94+
goodput_monitor = monitor_class(**kwargs)
8195
goodput_monitor.start_goodput_uploader()
8296
max_logging.log("Started Goodput upload to Tensorboard & GCM in the background!")
8397
yield
@@ -121,8 +135,22 @@ def create_goodput_recorder(config):
121135
if config.enable_goodput_recording and jax.process_index() == 0:
122136
max_logging.log("[GOODPUT NO-OP] recorder skipped (decoupled stub).")
123137
return None
124-
if config.enable_goodput_recording:
125-
logger_name = f"goodput_{config.run_name}"
126-
recorder = goodput.GoodputRecorder(config.run_name, logger_name, jax.process_index() == 0)
127-
return recorder
128-
return None
138+
139+
if not config.enable_goodput_recording:
140+
return None
141+
142+
logger_name = f"goodput_{config.run_name}"
143+
144+
# Detect if we should use the elastic-aware recorder
145+
if config.elastic_enabled:
146+
try:
147+
from ml_goodput_measurement import goodput_elastic
148+
from maxtext.utils import elastic_utils
149+
recorder = goodput_elastic.ElasticGoodputRecorder(config.run_name, logger_name, jax.process_index() == 0)
150+
elastic_utils.record_slice_state(recorder)
151+
except ImportError as e:
152+
max_logging.log(f"Could not create elastic goodput recorder: {e}")
153+
else:
154+
return recorder
155+
156+
return goodput.GoodputRecorder(config.run_name, logger_name, jax.process_index() == 0)

0 commit comments

Comments
 (0)