|
| 1 | +""" |
| 2 | +A DAG to run MaxText multi-tier checkpointing with replicator enabled |
| 3 | +validates the local checkpoints are replicated (copy) to bucket |
| 4 | +with HNS (Hierarchical Namespace) |
| 5 | +""" |
| 6 | + |
| 7 | +import datetime |
| 8 | + |
| 9 | +from airflow import models |
| 10 | + |
| 11 | +from dags import composer_env |
| 12 | +from dags.common import test_owner |
| 13 | +from dags.common.vm_resource import XpkClusters |
| 14 | +from dags.multipod.configs import gke_config |
| 15 | +from dags.orbax.util import checkpoint_util |
| 16 | +from dags.orbax.util import validation_util |
| 17 | +from xlml.utils.xpk import BRANCH_ABHINAV_MTC |
| 18 | +from xlml.utils.gke import zone_to_region |
| 19 | +from dags.orbax.util import test_config_util |
| 20 | + |
| 21 | + |
| 22 | +SCHEDULE = "0 14 * * *" if composer_env.is_prod_env() else None |
| 23 | +DAG_TEST_NAME = "maxtext_emc_save_gcs" |
| 24 | + |
| 25 | + |
| 26 | +with models.DAG( |
| 27 | + dag_id=DAG_TEST_NAME, |
| 28 | + start_date=datetime.datetime(2025, 6, 30), |
| 29 | + schedule_interval=SCHEDULE, |
| 30 | + catchup=False, |
| 31 | + tags=[ |
| 32 | + "multipod_team", |
| 33 | + "maxtext", |
| 34 | + "emergency_checkpointing", |
| 35 | + "nightly", |
| 36 | + "orbax", |
| 37 | + ], |
| 38 | + description="DAG that verifies the orbax multi-tier checkpointing saving functionality with replicator to GCS bucket", |
| 39 | + doc_md=""" |
| 40 | + # Multi-tier Checkpoint Validation DAG |
| 41 | +
|
| 42 | + ### Description |
| 43 | + This DAG (Directed Acyclic Graph) automates the process of validating |
| 44 | + checkpoint saving when using **Emergency Checkpointer Manager** features. |
| 45 | + It will check that the checkpoints are being stored in the GCS bucket. |
| 46 | + Also the steps flag controls how many steps the job will run. |
| 47 | +
|
| 48 | + ### Prerequisites |
| 49 | + To run this test, you need an existing cluster with the Multi-tier |
| 50 | + Checkpointing configuration enabled, as well as a bucket with HNS |
| 51 | + (Hierarchical Namespace) enabled. |
| 52 | +
|
| 53 | + ### Procedures |
| 54 | + 1. **Apply Configuration:** A Checkpoint Configuration YAML file is |
| 55 | + applied to the cluster, enabling Multi-tier Checkpoint (MTC) features. |
| 56 | + 2. **Run Maxtext Jobsets:** The DAG runs a Maxtext jobset. |
| 57 | + 3. The DAG validates that **GCS checkpoints** are being saved correctly |
| 58 | + in the `GCS bucket` by checking bucket and pod logs. |
| 59 | + """, |
| 60 | + concurrency=2, |
| 61 | +) as dag: |
| 62 | + checkpointing = test_config_util.Checkpointing( |
| 63 | + name="emc", enable_multi_tier_checkpointing=False |
| 64 | + ) |
| 65 | + test_configs = [ |
| 66 | + test_config_util.TestConfig( |
| 67 | + cluster=XpkClusters.TPU_V5P_128_CLUSTER, |
| 68 | + machine_type="ct5p-hightpu-4t", |
| 69 | + accelerator="v5p-128", |
| 70 | + slices=[2], |
| 71 | + model_name="llama2-7b", |
| 72 | + short_id="max-sv-gcs", |
| 73 | + replicator_backup_time=30, |
| 74 | + step=75, |
| 75 | + local_checkpoint_step=20, |
| 76 | + checkpoint_step=25, |
| 77 | + base_dir=test_config_util.DEFAULT_BUCKET, |
| 78 | + ), |
| 79 | + ] |
| 80 | + for mode, image in test_config_util.DOCKER_IMAGES: |
| 81 | + for test_config in test_configs: |
| 82 | + for slice_num in test_config.slices: |
| 83 | + # We conditionally set the trigger_rule on the first task. |
| 84 | + # If first task group failed the next one can execute. |
| 85 | + wait_delete_cpc = checkpoint_util.wait_for_cpc_deletion.override( |
| 86 | + trigger_rule="all_done" |
| 87 | + )(test_config.cpc_config) |
| 88 | + apply_cpc = checkpoint_util.apply_cpc(test_config.cpc_config) |
| 89 | + |
| 90 | + # Generate consistent run name for both training phases |
| 91 | + run_name = validation_util.generate_run_name( |
| 92 | + short_id=test_config.short_id, |
| 93 | + checkpointing_type=checkpointing.name, |
| 94 | + slice_number=slice_num, |
| 95 | + accelerator=test_config.accelerator, |
| 96 | + ) |
| 97 | + |
| 98 | + workload_command = test_config.generate_workload_command( |
| 99 | + checkpoint_dir=test_config_util.DEFAULT_RAM_DISK, |
| 100 | + run_name=run_name, |
| 101 | + out_folder=f"maxtext_emc_orbax_save_gcs", |
| 102 | + enable_multi_tier_checkp=checkpointing.enable_multi_tier_checkpointing, |
| 103 | + slice_num=slice_num, |
| 104 | + ) |
| 105 | + |
| 106 | + start_time = validation_util.generate_timestamp() |
| 107 | + |
| 108 | + maxtext_chkpt_run_test = gke_config.get_gke_config( |
| 109 | + num_slices=slice_num, |
| 110 | + cluster=test_config.cluster, |
| 111 | + time_out_in_min=60, |
| 112 | + test_name=f"{test_config.short_id}-emc", |
| 113 | + run_model_cmds=workload_command, |
| 114 | + docker_image=image.value, |
| 115 | + test_owner=test_owner.CAMILO_Q, |
| 116 | + ).run( |
| 117 | + ramdisk_directory=test_config_util.DEFAULT_RAM_DISK, |
| 118 | + mtc_enabled=True, |
| 119 | + xpk_branch=BRANCH_ABHINAV_MTC, |
| 120 | + skip_post_process=True, |
| 121 | + ) |
| 122 | + |
| 123 | + end_time = validation_util.generate_timestamp() |
| 124 | + |
| 125 | + steps_to_validate = test_config.generate_step_to_validate( |
| 126 | + is_local=False |
| 127 | + ) |
| 128 | + |
| 129 | + validate_steps = validation_util.validate_checkpoint_at_steps_are_saved( |
| 130 | + project_id=test_config.cluster.project, |
| 131 | + location=zone_to_region(test_config.cluster.zone), |
| 132 | + cluster_name=test_config.cluster.name, |
| 133 | + ram_disk="gcs", |
| 134 | + pod_pattern=".*-0-0", |
| 135 | + start_time=start_time, |
| 136 | + end_time=end_time, |
| 137 | + steps_to_validate=steps_to_validate, |
| 138 | + ) |
| 139 | + |
| 140 | + # Validate that GCS restore happened during the second training run |
| 141 | + validate_checkpoints_steps_gcs = validation_util.validate_gcs_checkpoint_files( |
| 142 | + bucket_path=f"{test_config_util.DEFAULT_BUCKET}/maxtext_emc_orbax_save_gcs/{run_name}", |
| 143 | + steps_to_validate=steps_to_validate, |
| 144 | + ) |
| 145 | + |
| 146 | + # Final CPC cleanup to ensure symmetric start/end |
| 147 | + wait_delete_cpc_final = checkpoint_util.wait_for_cpc_deletion.override( |
| 148 | + trigger_rule="all_done", task_id="wait_delete_cpc_final" |
| 149 | + )(test_config.cpc_config).as_teardown(setups=apply_cpc) |
| 150 | + |
| 151 | + ( |
| 152 | + wait_delete_cpc |
| 153 | + >> apply_cpc |
| 154 | + >> run_name |
| 155 | + >> start_time |
| 156 | + >> maxtext_chkpt_run_test |
| 157 | + >> end_time |
| 158 | + >> validate_steps |
| 159 | + >> validate_checkpoints_steps_gcs |
| 160 | + >> wait_delete_cpc_final |
| 161 | + ) |
0 commit comments