@@ -201,6 +201,41 @@ def run(
201201
202202 return group
203203
204+ def run_with_interruption (
205+ self ,
206+ * ,
207+ gcs_location : Optional [airflow .XComArg ] = None ,
208+ use_vertex_tensorboard : bool = False ,
209+ use_pathways : bool = False ,
210+ skip_post_process : bool = False ,
211+ ramdisk_directory : str = "" ,
212+ mtc_enabled : bool = False ,
213+ xpk_branch : str = xpk .MAIN_BRANCH ,
214+ ) -> DAGNode :
215+ """Run a test job within a docker image.
216+
217+ Attributes:
218+ gcs_location: GCS path for all artifacts of the test.
219+ use_vertex_tensorboard: Set to True to view workload data on
220+ Vertex AI Tensorboard.
221+
222+ Returns:
223+ A task group with the following tasks chained: run_model and
224+ post_process.
225+ """
226+ with TaskGroup (group_id = self .task_test_config .benchmark_id ) as group :
227+ run_model , gcs_path = self .run_model_with_interruption (
228+ gcs_location ,
229+ use_vertex_tensorboard ,
230+ use_pathways ,
231+ ramdisk_directory ,
232+ mtc_enabled ,
233+ xpk_branch ,
234+ )
235+ if not skip_post_process :
236+ run_model >> self .post_process (gcs_path )
237+ return group
238+
204239 def run_with_name_gen_and_quarantine (
205240 self ,
206241 quarantine_task_group ,
@@ -333,6 +368,72 @@ def run_model(
333368 )
334369 return group , gcs_path
335370
371+ def run_model_with_interruption (
372+ self ,
373+ gcs_location : Optional [airflow .XComArg ] = None ,
374+ use_vertex_tensorboard : bool = False ,
375+ use_pathways : bool = False ,
376+ ramdisk_directory : str = "" ,
377+ mtc_enabled : bool = False ,
378+ xpk_branch : str = xpk .MAIN_BRANCH ,
379+ ) -> DAGNode :
380+ """Run the TPU/GPU test in `task_test_config` using xpk.
381+ Different behaviour for testing interruption.
382+
383+ Attributes:
384+ gcs_location: GCS path for all artifacts of the test.
385+ use_vertex_tensorboard: Set to True to view workload data on
386+ Vertex AI Tensorboard.
387+
388+ Returns:
389+ A DAG node that executes the model test.
390+ """
391+ with TaskGroup (group_id = "run_model" ) as group :
392+ workload_id = xpk .generate_workload_id (self .task_test_config .benchmark_id )
393+ if gcs_location :
394+ gcs_path = gcs_location
395+ else :
396+ gcs_path = name_format .generate_gcs_folder_location (
397+ self .task_test_config .gcs_subfolder ,
398+ self .task_test_config .benchmark_id ,
399+ )
400+
401+ launch_workload_with_interruption = (
402+ self .launch_workload_with_interruption (
403+ workload_id ,
404+ gcs_path ,
405+ use_vertex_tensorboard ,
406+ use_pathways ,
407+ ramdisk_directory ,
408+ mtc_enabled ,
409+ xpk_branch ,
410+ )
411+ )
412+
413+ wait_for_workload_completion = xpk .wait_for_workload_completion .override (
414+ timeout = int (self .task_test_config .timeout .total_seconds ()),
415+ )(
416+ workload_id = workload_id ,
417+ project_id = self .task_gcp_config .project_name ,
418+ region = self .task_gcp_config .zone [:- 2 ],
419+ cluster_name = self .task_test_config .cluster_name ,
420+ )
421+
422+ clean_up_workload = xpk .clean_up_workload (
423+ workload_id = workload_id ,
424+ project_id = self .task_gcp_config .project_name ,
425+ zone = self .task_gcp_config .zone ,
426+ cluster_name = self .task_test_config .cluster_name ,
427+ )
428+
429+ (
430+ (workload_id , gcs_path )
431+ >> launch_workload_with_interruption
432+ >> wait_for_workload_completion
433+ >> clean_up_workload
434+ )
435+ return group , gcs_path
436+
336437 def launch_workload (
337438 self ,
338439 workload_id : str ,
@@ -376,6 +477,61 @@ def launch_workload(
376477 run_workload >> wait_for_workload_start
377478 return group
378479
480+ def launch_workload_with_interruption (
481+ self ,
482+ workload_id : str ,
483+ gcs_path : str ,
484+ use_vertex_tensorboard : bool ,
485+ use_pathways : bool = False ,
486+ ramdisk_directory : str = "" ,
487+ mtc_enabled : bool = False ,
488+ xpk_branch : str = xpk .MAIN_BRANCH ,
489+ ) -> DAGNode :
490+ """Create the workload and wait for it to provision."""
491+ with TaskGroup (group_id = "launch_workload_with_interruption" ) as group :
492+ run_workload = xpk .run_workload .override (
493+ owner = self .task_test_config .task_owner
494+ )(
495+ task_id = "run_workload" ,
496+ cluster_project = self .task_gcp_config .project_name ,
497+ zone = self .task_gcp_config .zone ,
498+ cluster_name = self .task_test_config .cluster_name ,
499+ benchmark_id = self .task_test_config .benchmark_id ,
500+ workload_id = workload_id ,
501+ gcs_path = gcs_path ,
502+ docker_image = self .task_test_config .docker_image ,
503+ accelerator_type = self .task_test_config .accelerator .name ,
504+ run_cmds = self .task_test_config .test_script ,
505+ num_slices = self .task_test_config .num_slices ,
506+ use_vertex_tensorboard = use_vertex_tensorboard ,
507+ use_pathways = use_pathways ,
508+ ramdisk_directory = ramdisk_directory ,
509+ mtc_enabled = mtc_enabled ,
510+ xpk_branch = xpk_branch ,
511+ )
512+
513+ wait_for_workload_start = xpk .wait_for_workload_start .override (
514+ timeout = self .workload_provision_timeout .total_seconds ()
515+ )(
516+ workload_id = workload_id ,
517+ project_id = self .task_gcp_config .project_name ,
518+ region = self .task_gcp_config .zone [:- 2 ],
519+ cluster_name = self .task_test_config .cluster_name ,
520+ )
521+
522+ run_interruption_workload = xpk .run_interruption_cmd .override (
523+ owner = self .task_test_config .task_owner
524+ )(
525+ task_id = "run_interruption_cmd" ,
526+ workload_id = workload_id ,
527+ project_id = self .task_gcp_config .project_name ,
528+ region = self .task_gcp_config .zone [:- 2 ],
529+ cluster_name = self .task_test_config .cluster_name ,
530+ )
531+
532+ run_workload >> wait_for_workload_start >> run_interruption_workload
533+ return group
534+
379535 def post_process (self , result_location : Optional [str ] = None ) -> DAGNode :
380536 """Process metrics and metadata, and insert them into BigQuery tables.
381537
0 commit comments