Skip to content

Commit d157855

Browse files
Fixes for code review
1 parent 839a63d commit d157855

2 files changed

Lines changed: 149 additions & 81 deletions

File tree

dags/orbax/maxtext_mtc_emergency_save_local.py

Lines changed: 134 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
44
This DAG performs a series of tests to save and validate checkpoints
55
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.
6+
service enabled (Multi-tier Checkpointing). The tests are executed on a TPU
7+
multi-pod cluster.
78
"""
89

910
import datetime
@@ -37,48 +38,121 @@
3738

3839

3940
@dataclass
40-
class Testcase:
41+
class Checkpointing:
4142
"""
4243
Represents the information of a checkpointing mechanism.
4344
4445
Attributes:
4546
name: A unique name for the checkpointing configuration.
46-
use_replicator: Indicates whether a replicator is enabled for this test case.
47+
use_replicator: Indicates whether a replicator is enabled.
4748
"""
4849

4950
name: str
5051
use_replicator: bool
5152

5253

5354
@dataclass
54-
class Testconfig:
55-
"""Holds the general configuration for a checkpointing test.
56-
57-
Attributes:
58-
cluster: The specified cluster to be used for the test.
59-
machine_type: The type of machine (e.g., GPU, TPU).
60-
accelerator: The type of accelerator (e.g., GPU, TPU) to use.
61-
slices: The number of slices to be used.
62-
model_name: The name of the model being tested.
63-
short_id (str): A short id to be used for naming the test run.
64-
replicator_min: The time the replicator takes to backup checkpoints to bucket.
65-
step: The current step of the training process.
66-
local_checkpoint_step: The step interval for local checkpoints.
67-
checkpoint_step: The step interval for the checkpoints store in the bucket.
68-
ram_disk_mi: The size about the RAM disk in the CSI driver, in Mi.
69-
"""
55+
class TestConfig:
56+
"""Holds the general configuration for a checkpointing test."""
7057

7158
cluster: XpkClusters
7259
machine_type: str
7360
accelerator: str
7461
slices: list[int]
7562
model_name: str
7663
short_id: str
77-
replicator_min: int
64+
replicator_backup_time: int
7865
step: int
7966
local_checkpoint_step: int
8067
checkpoint_step: int
81-
ram_disk_mi: str
68+
ram_disk_size: str
69+
cpc_config: mtc.CheckpointConfiguration
70+
71+
def __init__(
72+
self,
73+
cluster: XpkClusters,
74+
machine_type: str,
75+
accelerator: str,
76+
slices: list[int],
77+
model_name: str,
78+
short_id: str,
79+
replicator_backup_time: int,
80+
step: int,
81+
local_checkpoint_step: int,
82+
checkpoint_step: int,
83+
ram_disk_size_in_mi: str,
84+
):
85+
"""
86+
Initializes the test configurations.
87+
88+
Args:
89+
cluster: The specified cluster to be used for the test.
90+
machine_type: The type of machine (e.g., GPU, TPU).
91+
accelerator: The type of accelerator (e.g., GPU, TPU) to use.
92+
slices: The number of slices to be used.
93+
model_name: The name of the model being tested.
94+
short_id: A short identifier for the test run.
95+
replicator_backup_time: The allowed time for replicator takes to backup
96+
and store checkpoint to bucket
97+
step: The current step of the training process.
98+
local_checkpoint_step: The step interval for local checkpoints.
99+
checkpoint_step: The step interval for the checkpoints store in the
100+
bucket.
101+
ram_disk_size_in_mi: The size in mebibytes (Mi) about the RAM disk in the
102+
CSI driver. The unit is in mebibytes (Mi) but the value should be passed
103+
as a string with the unit, e.g., "2G" or "2048M". Defaults to "100G"".
104+
"""
105+
106+
self.cluster = cluster
107+
self.machine_type = machine_type
108+
self.accelerator = accelerator
109+
self.slices = slices
110+
self.model_name = model_name
111+
self.short_id = short_id
112+
self.replicator_backup_time = replicator_backup_time
113+
self.step = step
114+
self.local_checkpoint_step = local_checkpoint_step
115+
self.checkpoint_step = checkpoint_step
116+
self.ram_disk_size = ram_disk_size_in_mi
117+
self.cpc_config = mtc.CheckpointConfiguration(
118+
project_id=self.cluster.project,
119+
region=zone_to_region(self.cluster.zone),
120+
cluster_name=self.cluster.name,
121+
gcs_bucket=gcs_bucket.MTC_AUTOMATION_BUCKET.removeprefix("gs://"),
122+
ramdisk_memory_in_mi=self.ram_disk_size,
123+
machine_type=self.machine_type,
124+
)
125+
126+
def generate_workload_command(
127+
self,
128+
cp: Checkpointing,
129+
checkpoint_dir: str,
130+
out_dir: str,
131+
slice_number: int,
132+
) -> str:
133+
run_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M")
134+
run_name = f"{self.short_id}-{cp.name}-{slice_number}x-{self.accelerator}-{run_time}"
135+
return (
136+
"export TPU_PREMAPPED_BUFFER_SIZE=52428800000 && "
137+
"export TPU_PREMAPPED_BUFFER_TRANSFER_THRESHOLD_BYTES=52428800000 && "
138+
"python3 -m MaxText.train MaxText/configs/base.yml "
139+
"remat_policy=full "
140+
"global_parameter_scale=1 "
141+
f"base_output_directory={out_dir} "
142+
"dataset_type=synthetic "
143+
f"steps={self.step} "
144+
"per_device_batch_size=1 "
145+
"max_target_length=256 "
146+
f"model_name={self.model_name} "
147+
"per_device_batch_size=2 "
148+
"reuse_example_batch=1 "
149+
"enable_emergency_checkpoint=true "
150+
f"local_checkpoint_directory={checkpoint_dir} "
151+
f"local_checkpoint_period={self.local_checkpoint_step} "
152+
f"use_replicator_service={cp.use_replicator} "
153+
f"replicator_backup_interval_minutes={self.replicator_backup_time} "
154+
f"run_name={run_name}",
155+
)
82156

83157

84158
with models.DAG(
@@ -97,71 +171,64 @@ class Testconfig:
97171
description="A DAG to run MaxText multi-tier checkpointing tests.",
98172
doc_md="",
99173
concurrency=2,
100-
params={},
101174
) as dag:
102175
test_configs = [
103-
Testconfig(
176+
TestConfig(
104177
cluster=XpkClusters.TPU_V5P_128_CLUSTER_ORBAX,
105178
machine_type="ct5p-hightpu-4t",
106179
accelerator="v5p-128",
107180
slices=[2],
108181
model_name="llama2-7b",
109182
short_id="max-sv",
110-
replicator_min=30,
183+
replicator_backup_time=30,
111184
step=100,
112185
local_checkpoint_step=20,
113186
checkpoint_step=25,
114-
ram_disk_mi="800000Mi",
187+
ram_disk_size_in_mi="800000Mi",
115188
),
116189
]
117-
tests_to_run_seq = []
118-
# Individual test cases for Multi-tier Checkpointing and Emergency Checkpointing
119-
for tc in [
120-
Testcase(name="mtc", use_replicator=True),
121-
Testcase(name="emc", use_replicator=False),
190+
191+
task_groups = []
192+
193+
for checkpointing in [
194+
Checkpointing(
195+
name="mtc", # Multi-tier Checkpointing
196+
use_replicator=True,
197+
),
198+
Checkpointing(
199+
name="emc", # Emergency Checkpointing
200+
use_replicator=False,
201+
),
122202
]:
123-
folder = f"maxtext_{tc.name}_orbax_save_local"
124-
run_dir_out = posixpath.join(BASE_OUTPUT_DIRECTORY, folder)
125-
with TaskGroup(group_id=f"maxtext_{tc.name}_orbax_save_local") as task:
203+
folder = f"maxtext_{checkpointing.name}_orbax_save_local"
204+
output_dir = posixpath.join(BASE_OUTPUT_DIRECTORY, folder)
205+
206+
with TaskGroup(
207+
group_id=f"maxtext_{checkpointing.name}_orbax_save_local",
208+
) as group:
126209
for mode, image in DOCKER_IMAGES:
127210
for test_config in test_configs:
128-
cpc_conf = mtc.CheckpointConfiguration(
129-
project_id=test_config.cluster.project,
130-
region=zone_to_region(test_config.cluster.zone),
131-
cluster_name=test_config.cluster.name,
132-
gcs_bucket=gcs_bucket.MTC_AUTOMATION_BUCKET.removeprefix("gs://"),
133-
ram_disk_memory_in_mi=test_config.ram_disk_mi,
134-
machine_type=test_config.machine_type,
135-
)
136211
for slice_num in test_config.slices:
137212
# We conditionally set the trigger_rule on the first task.
138213
# If first task group failed the next one can execute.
139-
init_delete_cpc = mtc.initiate_cpc_deletion(cpc_conf)
214+
init_delete_cpc = mtc.initiate_cpc_deletion(test_config.cpc_config)
140215
wait_delete_cpc = mtc.wait_for_cpc_deletion.override(
141216
trigger_rule="all_done"
142-
)(cpc_conf)
143-
apply_cpc = mtc.apply_cpc(cpc_conf)
144-
run_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M")
145-
run_name = f"{test_config.short_id}-{tc.name}-{slice_num}x-{test_config.accelerator}-{run_time}"
146-
workload_command = (
147-
"export TPU_PREMAPPED_BUFFER_SIZE=52428800000 && "
148-
"export TPU_PREMAPPED_BUFFER_TRANSFER_THRESHOLD_BYTES=52428800000 && "
149-
"python3 -m MaxText.train MaxText/configs/base.yml remat_policy=full "
150-
f"global_parameter_scale=1 base_output_directory={run_dir_out} "
151-
f"dataset_type=synthetic steps={test_config.step} per_device_batch_size=1 "
152-
f"max_target_length=256 model_name={test_config.model_name} per_device_batch_size=2 "
153-
"reuse_example_batch=1 enable_emergency_checkpoint=true "
154-
f"local_checkpoint_directory={RAM_DISK} local_checkpoint_period={test_config.local_checkpoint_step} "
155-
f"use_replicator_service={tc.use_replicator} replicator_backup_interval_minutes={test_config.replicator_min} "
156-
f"run_name={run_name}",
217+
)(test_config.cpc_config)
218+
apply_cpc = mtc.apply_cpc(test_config.cpc_config)
219+
workload_command = test_config.generate_workload_command(
220+
cp=checkpointing,
221+
checkpoint_dir=RAM_DISK,
222+
out_dir=output_dir,
223+
slice_number=slice_num,
157224
)
158225

159226
start_time = log.generate_timestamp()
160227
maxtext_chkpt_run_test = gke_config.get_gke_config(
161228
num_slices=slice_num,
162229
cluster=test_config.cluster,
163230
time_out_in_min=60,
164-
test_name=f"{test_config.short_id}-{tc.name}",
231+
test_name=f"{test_config.short_id}-{checkpointing.name}",
165232
run_model_cmds=workload_command,
166233
docker_image=image.value,
167234
test_owner=test_owner.CAMILO_Q,
@@ -197,8 +264,10 @@ class Testconfig:
197264
vali_step_list.append(vali_step)
198265

199266
# Here we are looking for the string '(blocking + background)'.
200-
# We will compare expected steps with the ones we found when query this regex. Should be the same
201-
# If for some reason the restore start from 0 this task will fail because len(valid_step_list) != len(founded_steps)
267+
# We will compare expected steps with the ones we found when query
268+
# this regex. Should be the same. If for some reason the restore
269+
# start from 0 this task will fail
270+
# because len(valid_step_list) != len(founded_steps)
202271
validate_log = log.validate_log_with_step(
203272
project_id=test_config.cluster.project,
204273
location=zone_to_region(test_config.cluster.zone),
@@ -219,9 +288,9 @@ class Testconfig:
219288
>> end_time
220289
>> validate_log
221290
)
222-
# Add to a global list of test to be run in a sequential way
223-
tests_to_run_seq.append(task)
291+
# Add to a list of test to chain them sequentially.
292+
task_groups.append(group)
224293

225-
# Chain the task groups sequentially
226-
for idx_test in range(len(tests_to_run_seq) - 1):
227-
tests_to_run_seq[idx_test] >> tests_to_run_seq[idx_test + 1]
294+
# Chain all task groups sequentially.
295+
for idx in range(len(task_groups) - 1):
296+
task_groups[idx] >> task_groups[idx + 1]

dags/orbax/util/multi_tier_checkpoint_util.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
"""Utility functions for managing Multi-tier Cluster Configuration.
22
33
This module provides tasks for creating, applying, and deleting
4-
Multi-tier Driver cluster Configurations for enebale Multi Tier Checkpointing.
4+
Multi-tier Driver cluster Configurations for enable Multi Tier Checkpointing.
55
"""
66

77
from absl import logging
88
import yaml
9-
import time
109
from dataclasses import dataclass
1110

1211
from kubernetes import client as k8s_client
@@ -17,7 +16,7 @@
1716
from xlml.utils import gke
1817

1918

20-
# ramdisk_memory_in_mi: This should be Mi
19+
@dataclass
2120
class CheckpointConfiguration:
2221
"""A dataclass to hold attributes of a Cloud Public Compute (CPC) instance."""
2322

@@ -26,7 +25,7 @@ class CheckpointConfiguration:
2625
cluster_name: str
2726
gcs_bucket: str
2827
machine_type: str
29-
ramdisk_memory_in_mi: str
28+
ramdisk_memory: str
3029
toleration_key: str
3130
cpc_yaml_template: str
3231

@@ -37,30 +36,30 @@ def __init__(
3736
cluster_name: str,
3837
gcs_bucket: str,
3938
machine_type: str,
40-
ram_disk_memory_in_mi: str,
39+
ramdisk_memory_in_mi: str,
4140
toleration_key: str = "google.com/tpu",
4241
):
4342
"""
4443
Initializes the CheckpointConfiguration.
4544
4645
Args:
47-
project_id (str): The Google Cloud project ID.
48-
region (str): The Google Cloud region.
49-
cluster_name (str): The name of the GKE cluster.
50-
gcs_bucket (str): The name of the GCS bucket for checkpoints.
51-
machine_type (str): The machine type for the instance.
52-
ramdisk_memory_in_mi (str): The size of the RAM disk in mebibytes (Mi).
53-
The unit is in mebibytes (Mi) but the value should be passed as a string
54-
with the unit, e.g., "2G" or "2048M". Defaults to "100G"".
55-
toleration_key (str): The toleration key for the Kubernetes pod.
56-
Defaults to "google.com/tpu".
46+
project_id (str): The Google Cloud project ID.
47+
region (str): The Google Cloud region.
48+
cluster_name (str): The name of the GKE cluster.
49+
gcs_bucket (str): The name of the GCS bucket for checkpoints.
50+
machine_type (str): The machine type for the instance.
51+
ram_disk_memory_in_mi (str): The size of the RAM disk in mebibytes (Mi).
52+
The unit is in mebibytes (Mi) but the value should be passed as a
53+
string with the unit, e.g., "2G" or "2048M". Defaults to "100G"".
54+
toleration_key (str): The toleration key for the Kubernetes pod.
55+
Defaults to "google.com/tpu".
5756
"""
5857
self.project_id = project_id
5958
self.region = region
6059
self.cluster_name = cluster_name
6160
self.gcs_bucket = gcs_bucket
6261
self.machine_type = machine_type
63-
self.ramdisk_memory = ram_disk_memory_in_mi
62+
self.ramdisk_memory = ramdisk_memory_in_mi
6463
self.toleration_key = toleration_key
6564
self.cpc_yaml_template = f"""
6665
apiVersion: checkpointing.gke.io/v1

0 commit comments

Comments
 (0)