33
44This DAG performs a series of tests to save and validate checkpoints
55for 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
910import datetime
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
84158with 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 ]
0 commit comments