Skip to content

Commit f9dfcaf

Browse files
committed
Add a new DAG maxtext_multi_tier_save_local. This testcase test both save locally with MTC and EMC enabled.
1 parent 7a8fab2 commit f9dfcaf

9 files changed

Lines changed: 705 additions & 5 deletions

dags/common/test_owner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Team(enum.Enum):
6565
# Multi-tier Checkpointing
6666
ABHINAV_S = "abhinavclemson"
6767
XUEFENG_G = "xuefgu"
68+
CAMILO = "CAMILO P."
6869

6970
# MLCompass
7071
ORTI_B = "ortibazar"

dags/common/vm_resource.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ class XpkClusters:
259259
project=Project.CLOUD_TPU_MULTIPOD_DEV.value,
260260
zone=Zone.EUROPE_WEST4_B.value,
261261
)
262+
TPU_V5P_128_CLUSTER_ORBAX = XpkClusterConfig(
263+
name="orbax-ml-auto-solutions",
264+
device_version=TpuVersion.V5P,
265+
core_count=128,
266+
project=Project.CLOUD_TPU_MULTIPOD_DEV.value,
267+
zone=Zone.EUROPE_WEST4_B.value,
268+
)
262269
TPU_V5E_256_CLUSTER = XpkClusterConfig(
263270
name="v5e-256-bodaborg-europe-west4",
264271
device_version=TpuVersion.V5E,

dags/gcs_bucket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626

2727
# Multi-tier checkpointing need special permission for GCS Bucket
2828
# For further question reach out to Multi-tier Checkpointing Owners.
29-
MTC_BUCKET = "gs://mtc-bucket-us-east5/output"
29+
MTC_AUTOMATION_BUCKET = "gs://mtc-automation-bucket"

dags/multipod/maxtext_multi_tier_p2_checkpointing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
concurrency=2,
4040
) as dag:
4141
base_output_directory = (
42-
f"{gcs_bucket.MTC_BUCKET}/maxtext_multi_tier_p2_checkpointing"
42+
f"{gcs_bucket.MTC_AUTOMATION_BUCKET}/maxtext_multi_tier_p2_checkpointing"
4343
)
4444
dataset_path = gcs_bucket.MAXTEXT_DIR
4545
docker_images = [
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
"""
2+
A DAG to run MaxText multi-tier checkpointing tests.
3+
4+
This DAG performs a series of tests to save and validate checkpoints
5+
for the MaxText model. It runs tests in two modes: one with the replicator
6+
service enabled (Multi-tier Checkpointing). The tests are executed on a TPU multi-pod cluster.
7+
"""
8+
9+
import datetime
10+
from dataclasses import dataclass
11+
import posixpath
12+
13+
from airflow import models
14+
from airflow.utils.task_group import TaskGroup
15+
16+
from dags import composer_env, gcs_bucket
17+
from dags.common import test_owner
18+
from dags.common.vm_resource import DockerImage, XpkClusters
19+
from dags.multipod.configs import gke_config
20+
from dags.multipod.configs.common import SetupMode
21+
from dags.orbax.util import logging_mtc as log
22+
from dags.orbax.util import multi_tier_checkpoint_util as mtc
23+
from xlml.utils.xpk import BRANCH_ABHINAV_MTC
24+
from xlml.utils.gke import zone_to_region
25+
26+
# Global variables across test configurations.
27+
SCHEDULE = "0 10 * * *" if composer_env.is_prod_env() else None
28+
DAG_TEST_NAME = "maxtext_emc_and_mtc_orbax_save_local"
29+
BASE_OUTPUT_DIRECTORY = gcs_bucket.MTC_AUTOMATION_BUCKET
30+
31+
# The variable DOCKER_IMAGES will hold multiple configurations e.g nightly , stable.
32+
DOCKER_IMAGES = [(
33+
SetupMode.NIGHTLY,
34+
DockerImage.MAXTEXT_TPU_JAX_NIGHTLY,
35+
)]
36+
RAM_DISK = "/local"
37+
38+
@dataclass
39+
class Testcase:
40+
"""Holds a single test case configuration for multi-tier checkpointing.
41+
42+
This class is used to define the properties of a specific test run,
43+
including the name of the checkpoint and whether to use a replicator.
44+
"""
45+
checkpointing_name: str
46+
use_replicator: bool
47+
48+
@dataclass
49+
class Testconfig:
50+
"""Holds the general configuration for a multi-tier checkpointing test.
51+
52+
This class defines the environment and parameters for a single test run,
53+
including cluster details, model settings, and checkpointing intervals.
54+
55+
cluster (XpkClusters): The cluster to be used for the test.
56+
machine_type (str): The type of machine to run the test on.
57+
accelerator (str): The type of accelerator (e.g., GPU, TPU) to use.
58+
slices (list[int]): The number of slices to be used.
59+
model_name (str): The name of the model being tested.
60+
name_prefix (str): A prefix to be used for naming the test run.
61+
replicator_min (int): The minimum number of replicators required.
62+
step (int): The current step of the training process.
63+
local_checkpoint_step (int): The step interval for local checkpoints.
64+
checkpoint_step (int): The step interval for global checkpoints.
65+
ram_disk_mi (str): Information about the RAM disk.
66+
"""
67+
cluster: XpkClusters
68+
machine_type: str
69+
accelerator: str
70+
slices: list[int]
71+
model_name: str
72+
name_prefix: str
73+
replicator_min: int
74+
step: int
75+
local_checkpoint_step: int
76+
checkpoint_step: int
77+
ram_disk_mi: str
78+
79+
80+
with models.DAG(
81+
dag_id=DAG_TEST_NAME,
82+
start_date=datetime.datetime(2025, 6, 12),
83+
schedule_interval=SCHEDULE,
84+
catchup=False,
85+
tags=[
86+
"multipod_team",
87+
"maxtext",
88+
"emergency_checkpoint_manager",
89+
"multitier_checkpointing",
90+
"nightly",
91+
"orbax",
92+
],
93+
description="A DAG to run MaxText multi-tier checkpointing tests.",
94+
doc_md="",
95+
concurrency=2,
96+
params={},
97+
) as dag:
98+
test_configs = [
99+
Testconfig(
100+
cluster=XpkClusters.TPU_V5P_128_CLUSTER_ORBAX,
101+
machine_type="ct5p-hightpu-4t",
102+
accelerator="v5p-128",
103+
slices=[2],
104+
model_name="llama2-7b",
105+
name_prefix="max-sv",
106+
replicator_min=30,
107+
step=100,
108+
local_checkpoint_step=20,
109+
checkpoint_step=25,
110+
ram_disk_mi="800000Mi",
111+
),
112+
]
113+
tests_to_run_seq = []
114+
# Individual test cases for Multi-tier Checkpointing and Emergency Checkpointing
115+
for tc in [
116+
Testcase(checkpointing_name="mtc", use_replicator=True),
117+
Testcase(checkpointing_name="emc", use_replicator=False),
118+
]:
119+
folder = f"maxtext_{tc.checkpointing_name}_orbax_save_local"
120+
BASE_OUTPUT_DIRECTORY = posixpath.join(BASE_OUTPUT_DIRECTORY, folder)
121+
with TaskGroup(
122+
group_id=f"maxtext_{tc.checkpointing_name}_orbax_save_local"
123+
) as task:
124+
for mode, image in DOCKER_IMAGES:
125+
for test_config in test_configs:
126+
cpc_conf = mtc.CheckpointConfiguration(
127+
project_id=test_config.cluster.project,
128+
region=zone_to_region(test_config.cluster.zone),
129+
cluster_name=test_config.cluster.name,
130+
gcs_bucket=gcs_bucket.MTC_AUTOMATION_BUCKET.removeprefix("gs://"),
131+
ramdisk_memory=test_config.ram_disk_mi,
132+
machine_type=test_config.machine_type,
133+
)
134+
for slice_num in test_config.slices:
135+
136+
# We conditionally set the trigger_rule on the first task.
137+
# If first task group failed the next one can execute.
138+
init_delete_cpc = mtc.initiate_cpc_deletion(cpc_conf)
139+
wait_delete_cpc = mtc.wait_for_cpc_deletion.override(
140+
trigger_rule="all_done"
141+
)(cpc_conf)
142+
apply_cpc = mtc.apply_cpc(cpc_conf)
143+
run_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M")
144+
run_name = f"{test_config.name_prefix}-{tc.checkpointing_name}-{slice_num}x-{test_config.accelerator}-{run_time}"
145+
workload_command = (
146+
"export TPU_PREMAPPED_BUFFER_SIZE=52428800000 && "
147+
"export TPU_PREMAPPED_BUFFER_TRANSFER_THRESHOLD_BYTES=52428800000 && "
148+
"python3 -m MaxText.train MaxText/configs/base.yml remat_policy=full "
149+
f"global_parameter_scale=1 base_output_directory={BASE_OUTPUT_DIRECTORY} "
150+
f"dataset_type=synthetic steps={test_config.step} per_device_batch_size=1 "
151+
f"max_target_length=256 model_name={test_config.model_name} per_device_batch_size=2 "
152+
"reuse_example_batch=1 enable_emergency_checkpoint=true "
153+
f"local_checkpoint_directory={RAM_DISK} local_checkpoint_period={test_config.local_checkpoint_step} "
154+
f"use_replicator_service={tc.use_replicator} replicator_backup_interval_minutes={test_config.replicator_min} "
155+
f"run_name={run_name}",
156+
)
157+
158+
start_time = log.generate_timestamp()
159+
maxtext_chkpt_run_test = gke_config.get_gke_config(
160+
num_slices=slice_num,
161+
cluster=test_config.cluster,
162+
time_out_in_min=60,
163+
test_name=f"{test_config.name_prefix}-{tc.checkpointing_name}",
164+
run_model_cmds=workload_command,
165+
docker_image=image.value,
166+
test_owner=test_owner.CAMILO_Q,
167+
).run(
168+
ramdisk_directory=RAM_DISK,
169+
mtc_enabled=True,
170+
xpk_branch=BRANCH_ABHINAV_MTC,
171+
skip_post_process=True,
172+
)
173+
174+
cleanup_command = (f"rm -rf {RAM_DISK}/*",)
175+
ram_disk_cleanup = gke_config.get_gke_config(
176+
num_slices=slice_num,
177+
cluster=test_config.cluster,
178+
time_out_in_min=60,
179+
test_name=f"{test_config.name_prefix}-cl",
180+
run_model_cmds=cleanup_command,
181+
docker_image=image.value,
182+
test_owner=test_owner.CAMILO_Q,
183+
).run(
184+
ramdisk_directory=RAM_DISK,
185+
mtc_enabled=True,
186+
xpk_branch=BRANCH_ABHINAV_MTC,
187+
skip_post_process=True,
188+
)
189+
190+
end_time = log.generate_timestamp()
191+
vali_step = test_config.step - 1
192+
vali_step_list = [
193+
i for i in range(0, vali_step, test_config.local_checkpoint_step)
194+
]
195+
vali_step_list.append(vali_step)
196+
197+
# Here we are looking for the string '(blocking + background)'.
198+
# We will compare expected steps with the ones we found when query this regex. Should be the same
199+
# If for some reason the restore start from 0 this task will fail because len(valid_step_list) != len(founded_steps)
200+
validate_log = log.validate_log_with_step(
201+
project_id=test_config.cluster.project,
202+
location=zone_to_region(test_config.cluster.zone),
203+
cluster_name=test_config.cluster.name,
204+
text_filter="(blocking + background).",
205+
start_time=start_time,
206+
end_time=end_time,
207+
vali_step_list=vali_step_list,
208+
)
209+
210+
(
211+
init_delete_cpc
212+
>> wait_delete_cpc
213+
>> apply_cpc
214+
>> start_time
215+
>> maxtext_chkpt_run_test
216+
>> ram_disk_cleanup
217+
>> end_time
218+
>> validate_log
219+
)
220+
# Add to a global list of test to be run in a sequential way
221+
tests_to_run_seq.append(task)
222+
223+
# Chain the task groups sequentially
224+
for idx_test in range(len(tests_to_run_seq) - 1):
225+
tests_to_run_seq[idx_test] >> tests_to_run_seq[idx_test + 1]

dags/orbax/util/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)