|
| 1 | +"""A DAG to run MaxText multi-tier checkpointing tests (phase2: save & validate).""" |
| 2 | + |
| 3 | +import datetime |
| 4 | + |
| 5 | +from airflow import models |
| 6 | +from airflow.utils.task_group import TaskGroup |
| 7 | + |
| 8 | +from dags import composer_env, gcs_bucket |
| 9 | +from dags.common import test_owner |
| 10 | +from dags.common.vm_resource import DockerImage, XpkClusters |
| 11 | +from dags.multipod.configs import gke_config |
| 12 | +from dags.multipod.configs.common import SetupMode |
| 13 | +from dags.orbax.util import logging as log |
| 14 | +from dags.orbax.util import multi_tier_checkpoint_util as mtc |
| 15 | +from xlml.utils.xpk import BRANCH_ABHINAV_MTC |
| 16 | + |
| 17 | +SCHEDULE = "0 10 * * *" if composer_env.is_prod_env() else None |
| 18 | + |
| 19 | +with models.DAG( |
| 20 | + dag_id="maxtext_emtc_orbax_sav01_save_local", |
| 21 | + schedule_interval=SCHEDULE, |
| 22 | + tags=[ |
| 23 | + "multipod_team", |
| 24 | + "maxtext", |
| 25 | + "multi_tier_p2_chkpt_save_local", |
| 26 | + "nightly", |
| 27 | + "orbax", |
| 28 | + ], |
| 29 | + start_date=datetime.datetime(2025, 6, 12), |
| 30 | + catchup=False, |
| 31 | + concurrency=2, |
| 32 | +) as dag: |
| 33 | + base_output_directory = ( |
| 34 | + f"{gcs_bucket.MTC_AUTOMATION_BUCKET}/maxtext_emtc_orbax_sav01_save_local" |
| 35 | + ) |
| 36 | + docker_images = [( |
| 37 | + SetupMode.NIGHTLY, |
| 38 | + DockerImage.MAXTEXT_TPU_JAX_NIGHTLY, |
| 39 | + )] |
| 40 | + ram_disk = "/local" |
| 41 | + test_configs = {"v5p-128": [2]} |
| 42 | + clusters = {"v5p-128": XpkClusters.TPU_V5P_128_CLUSTER_ORBAX} |
| 43 | + step = 100 |
| 44 | + local_checkpoint_period = 20 |
| 45 | + replicator_backup_interval_minutes = 30 |
| 46 | + name_prefix = "max-p2-sv" |
| 47 | + model_name = "llama2-7b" |
| 48 | + tests_to_run_seq = [] |
| 49 | + # Define the flags for replicator usage to create two separate test cases |
| 50 | + use_replicator_flags = ["True", "False"] |
| 51 | + |
| 52 | + for i, use_replicator_flag in enumerate(use_replicator_flags): |
| 53 | + with TaskGroup( |
| 54 | + group_id=f"maxtext_emtc_orbax_sav01_save_local_replicator_{use_replicator_flag.lower()}" |
| 55 | + ) as task: |
| 56 | + for mode, image in docker_images: |
| 57 | + for accelerator, slices in test_configs.items(): |
| 58 | + for slice_num in slices: |
| 59 | + cpc = ( |
| 60 | + clusters[accelerator].project, |
| 61 | + clusters[accelerator].zone[:-2], |
| 62 | + clusters[accelerator].name, |
| 63 | + gcs_bucket.MTC_AUTOMATION_BUCKET.split("gs://")[1], |
| 64 | + "ct5p-hightpu-4t", |
| 65 | + "google.com/tpu", |
| 66 | + "800000Mi", |
| 67 | + ) |
| 68 | + # This is the key change. We conditionally set the trigger_rule |
| 69 | + # on the very first task of each task group (except the first one). |
| 70 | + # Start from fresh apply cpc yaml mtc driver |
| 71 | + delete_cpc = ( |
| 72 | + mtc.delete_cpc.override(trigger_rule="all_done")(*cpc) |
| 73 | + if i > 0 |
| 74 | + else mtc.delete_cpc(*cpc) |
| 75 | + ) |
| 76 | + apply_cpc = mtc.apply_cpc(*cpc) |
| 77 | + run_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M") |
| 78 | + run_name = f"{name_prefix}-{slice_num}x-{accelerator}-{run_time}" |
| 79 | + workload_command = ( |
| 80 | + "export TPU_PREMAPPED_BUFFER_SIZE=52428800000 && " |
| 81 | + "export TPU_PREMAPPED_BUFFER_TRANSFER_THRESHOLD_BYTES=52428800000 && " |
| 82 | + "python3 -m MaxText.train MaxText/configs/base.yml remat_policy=full " |
| 83 | + f"global_parameter_scale=1 base_output_directory={base_output_directory} " |
| 84 | + f"dataset_type=synthetic steps={step} per_device_batch_size=1 " |
| 85 | + f"max_target_length=256 model_name={model_name} per_device_batch_size=2 " |
| 86 | + "reuse_example_batch=1 enable_emergency_checkpoint=true " |
| 87 | + f"local_checkpoint_directory={ram_disk} local_checkpoint_period={local_checkpoint_period} " |
| 88 | + f"use_replicator_service={use_replicator_flag} replicator_backup_interval_minutes={replicator_backup_interval_minutes} " |
| 89 | + f"run_name={run_name}", |
| 90 | + ) |
| 91 | + |
| 92 | + start_time = log.generate_timestamp() |
| 93 | + |
| 94 | + maxtext_phase2_chkpt_test = gke_config.get_gke_config( |
| 95 | + num_slices=slice_num, |
| 96 | + cluster=clusters[accelerator], |
| 97 | + time_out_in_min=60, |
| 98 | + test_name=f"{name_prefix}-{use_replicator_flag.lower()}", |
| 99 | + run_model_cmds=workload_command, |
| 100 | + docker_image=image.value, |
| 101 | + test_owner=test_owner.CAMILO, |
| 102 | + ).run( |
| 103 | + ramdisk_directory=ram_disk, |
| 104 | + mtc_enabled=True, |
| 105 | + xpk_branch=BRANCH_ABHINAV_MTC, |
| 106 | + skip_post_process=True, |
| 107 | + ) |
| 108 | + |
| 109 | + cleanup_command = (f"rm -rf {ram_disk}/*",) |
| 110 | + ram_disk_cleanup = gke_config.get_gke_config( |
| 111 | + num_slices=slice_num, |
| 112 | + cluster=clusters[accelerator], |
| 113 | + time_out_in_min=60, |
| 114 | + test_name=f"{name_prefix}-cl", |
| 115 | + run_model_cmds=cleanup_command, |
| 116 | + docker_image=image.value, |
| 117 | + test_owner=test_owner.CAMILO, |
| 118 | + ).run( |
| 119 | + ramdisk_directory=ram_disk, |
| 120 | + mtc_enabled=True, |
| 121 | + xpk_branch=BRANCH_ABHINAV_MTC, |
| 122 | + skip_post_process=True, |
| 123 | + ) |
| 124 | + |
| 125 | + end_time = log.generate_timestamp() |
| 126 | + vali_step = step - 1 |
| 127 | + vali_step_list = [ |
| 128 | + i for i in range(0, vali_step, local_checkpoint_period) |
| 129 | + ] |
| 130 | + vali_step_list.append(vali_step) |
| 131 | + |
| 132 | + # Here we are looking for the string '(blocking + background)'. |
| 133 | + # We will compare expected steps with the ones we found when query this regex. Should be the same |
| 134 | + # If for some reason the restore start from 0 this task will fail because len(valid_step_list) != len(founded_steps) |
| 135 | + validate_log = log.validate_log_with_step( |
| 136 | + project_id=clusters[accelerator].project, |
| 137 | + location=clusters[accelerator].zone[:-2], |
| 138 | + cluster_name=clusters[accelerator].name, |
| 139 | + text_filter="(blocking + background).", |
| 140 | + start_time=start_time, |
| 141 | + end_time=end_time, |
| 142 | + vali_step_list=vali_step_list, |
| 143 | + ) |
| 144 | + |
| 145 | + ( |
| 146 | + delete_cpc |
| 147 | + >> apply_cpc |
| 148 | + >> start_time |
| 149 | + >> maxtext_phase2_chkpt_test |
| 150 | + >> ram_disk_cleanup |
| 151 | + >> end_time |
| 152 | + >> validate_log |
| 153 | + ) |
| 154 | + # Add to a global list of test to be run in a sequential way |
| 155 | + tests_to_run_seq.append(task) |
| 156 | + |
| 157 | + # Chain the task groups sequentially |
| 158 | + for idx_test in range(len(tests_to_run_seq) - 1): |
| 159 | + tests_to_run_seq[idx_test] >> tests_to_run_seq[idx_test + 1] |
0 commit comments