Skip to content

Commit 79be043

Browse files
committed
Fix linting errors
1 parent 7cbe10e commit 79be043

2 files changed

Lines changed: 61 additions & 33 deletions

File tree

dags/examples/maxtext_profile_sweep_example_dag.py

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""
16-
An example DAG to extract profile metrics from pretraining mixtral-8x7b model on v6-256.
17-
Profile extraction can be seamlessly integrated with maxtext_sweep_gke_config + (to_name_gen_and_quarantine_task + run).
15+
"""An example DAG to extract profile metrics.
16+
17+
Pretraining mixtral-8x7b model on v6-256.
18+
Profile extraction can be seamlessly integrated with
19+
maxtext_sweep_gke_config + (to_name_gen_and_quarantine_task + run).
1820
"""
1921

2022
import datetime
2123
from airflow import models
2224
from airflow.utils.task_group import TaskGroup
2325
from dags.common import test_owner
24-
from dags.common.vm_resource import XpkClusters, DockerImage, Project
26+
from dags.common.vm_resource import XpkClusters, Project
2527
from dags.multipod.configs import maxtext_sweep_gke_config
2628
from xlml.apis import metric_config
2729

@@ -35,7 +37,10 @@ def dict_to_arg(param_dict):
3537

3638

3739
docker_image = {
38-
"stable": "gcr.io/tpu-prod-env-multipod/maxtext_jax_stable_stack:2025-05-20",
40+
"stable": (
41+
"gcr.io/tpu-prod-env-multipod/"
42+
"maxtext_jax_stable_stack:2025-05-20"
43+
),
3944
}
4045

4146
# https://github.com/AI-Hypercomputer/maxtext/blob/main/benchmarks/maxtext_trillium_model_configs.py
@@ -45,9 +50,14 @@ def dict_to_arg(param_dict):
4550
"cluster": XpkClusters.TPU_V6E_256_MLPERF_CLUSTER,
4651
"train_command": [
4752
f"export BASE_OUTPUT_PATH={BASE_OUTPUT_PATH} && "
48-
"python3 -m maxtext.trainers.pre_train.train src/maxtext/configs/base.yml base_output_directory=${BASE_OUTPUT_PATH} model_name=mixtral-8x7b "
49-
# add profiler config: ensure steps > skip_first_n_steps_for_profiler + profiler_steps
50-
"steps=10 profiler=xplane skip_first_n_steps_for_profiler=5 profiler_steps=3 "
53+
"python3 -m maxtext.trainers.pre_train.train "
54+
"src/maxtext/configs/base.yml "
55+
"base_output_directory=${BASE_OUTPUT_PATH} "
56+
"model_name=mixtral-8x7b "
57+
# add profiler config: ensure steps >
58+
# skip_first_n_steps_for_profiler + profiler_steps
59+
"steps=10 profiler=xplane skip_first_n_steps_for_profiler=5 "
60+
"profiler_steps=3 "
5161
+ dict_to_arg({
5262
"per_device_batch_size": 12,
5363
"ici_fsdp_parallelism": -1,
@@ -81,9 +91,14 @@ def dict_to_arg(param_dict):
8191
"base_output_directory": "gs://runner-maxtext-logs",
8292
"train_command": [
8393
f"export BASE_OUTPUT_PATH={BASE_OUTPUT_PATH} && "
84-
"python3 -m maxtext.trainers.pre_train.train src/maxtext/configs/base.yml base_output_directory=${BASE_OUTPUT_PATH} model_name=mixtral-8x7b "
85-
# add profiler config: ensure steps > skip_first_n_steps_for_profiler + profiler_steps
86-
"steps=10 profiler=xplane skip_first_n_steps_for_profiler=5 profiler_steps=3 "
94+
"python3 -m maxtext.trainers.pre_train.train "
95+
"src/maxtext/configs/base.yml "
96+
"base_output_directory=${BASE_OUTPUT_PATH} "
97+
"model_name=mixtral-8x7b "
98+
# add profiler config: ensure steps >
99+
# skip_first_n_steps_for_profiler + profiler_steps
100+
"steps=10 profiler=xplane skip_first_n_steps_for_profiler=5 "
101+
"profiler_steps=3 "
87102
+ dict_to_arg({
88103
"per_device_batch_size": 12,
89104
"ici_fsdp_parallelism": -1,
@@ -120,25 +135,27 @@ def dict_to_arg(param_dict):
120135
)
121136

122137
for run_name, test_scripts_details in test_models_tpu.items():
123-
for image in docker_image.keys():
138+
for image, img_val in docker_image.items():
124139
# sweep num_slices and other training params
125140
# generate run_name and tensorboard/profile location for extraction
126141
num_slices = [1]
127142
sweep_params = {}
128-
maxtext_sweep_gke_test = maxtext_sweep_gke_config.get_maxtext_sweep_gke_config(
129-
test_owner=test_owner.SHUNING_J,
130-
dataset_project=Project.CLOUD_ML_AUTO_SOLUTIONS.value,
131-
composer_project=Project.CLOUD_ML_AUTO_SOLUTIONS.value,
132-
dataset_name=metric_config.DatasetOption.XLML_DATASET,
133-
cluster=test_scripts_details["cluster"],
134-
time_out_in_min=test_scripts_details["time_out_in_min"],
135-
base_output_directory=BASE_OUTPUT_PATH,
136-
num_slices=num_slices,
137-
docker_image=docker_image[image],
138-
run_name_prefix=f"maxtext_{image}_{run_name}",
139-
base_run_model_cmds=test_scripts_details["train_command"],
140-
sweep_params=sweep_params,
141-
enable_profile_config=True, # add flag to enable profile extraction
143+
maxtext_sweep_gke_test = (
144+
maxtext_sweep_gke_config.get_maxtext_sweep_gke_config(
145+
test_owner=test_owner.SHUNING_J,
146+
dataset_project=Project.CLOUD_ML_AUTO_SOLUTIONS.value,
147+
composer_project=Project.CLOUD_ML_AUTO_SOLUTIONS.value,
148+
dataset_name=metric_config.DatasetOption.XLML_DATASET,
149+
cluster=test_scripts_details["cluster"],
150+
time_out_in_min=test_scripts_details["time_out_in_min"],
151+
base_output_directory=BASE_OUTPUT_PATH,
152+
num_slices=num_slices,
153+
docker_image=img_val,
154+
run_name_prefix=f"maxtext_{image}_{run_name}",
155+
base_run_model_cmds=test_scripts_details["train_command"],
156+
sweep_params=sweep_params,
157+
enable_profile_config=True, # add flag to enable profile extraction
158+
)
142159
)
143160

144161
for test in maxtext_sweep_gke_test:

xlml/apis/task.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import dataclasses
1919
import datetime
2020
import shlex
21-
from typing import Optional, Tuple, Union
21+
from typing import Any, Optional, Tuple, Union
2222

2323
import airflow
2424
from airflow.models.taskmixin import DAGNode
@@ -42,7 +42,7 @@ def run(self) -> DAGNode:
4242
Returns:
4343
A DAG node that executes this test.
4444
"""
45-
...
45+
pass
4646

4747
def run_with_quarantine(self, quarantine_task_group):
4848
"""Run a test job. If the test job is flaky, wrap it in a special task grop.
@@ -67,7 +67,7 @@ def run_queued_resource_test(
6767
tpu_name_env_var: bool = False,
6868
all_workers: bool = True,
6969
skip_post_process: bool = False,
70-
custom_env: dict[str, str] = {},
70+
custom_env: Optional[dict[str, str]] = None,
7171
):
7272
"""This is a class to set up tasks for TPU provisioned by Queued Resource.
7373
@@ -94,6 +94,9 @@ def run_queued_resource_test(
9494
post_process and clean_up.
9595
"""
9696

97+
if custom_env is None:
98+
custom_env = {}
99+
97100
with TaskGroup(
98101
group_id=task_test_config.benchmark_id, prefix_group_id=True
99102
) as test:
@@ -324,7 +327,8 @@ class XpkTask(BaseTask):
324327
task_gcp_config: gcp_config.GCPConfig
325328
task_metric_config: Optional[metric_config.MetricConfig] = None
326329
workload_provision_timeout: datetime.timedelta = datetime.timedelta(
327-
# Set the provision timeout from 300 to 60 minutes for decreasing the duration of failed tasks
330+
# Set the provision timeout from 300 to 60 minutes for decreasing the
331+
# duration of failed tasks
328332
minutes=60
329333
)
330334

@@ -586,7 +590,10 @@ def run_model_with_node_interruption(
586590
xpk_branch: str = xpk.MAIN_BRANCH,
587591
max_restart: int = 0,
588592
) -> DAGNode:
589-
"""Run the TPU/GPU test in `task_test_config` using xpk with interruption."""
593+
"""Run the TPU/GPU test in `task_test_config` using xpk.
594+
595+
with interruption.
596+
"""
590597
with TaskGroup(group_id="run_model") as group:
591598
workload_id = xpk.generate_workload_id(self.task_test_config.benchmark_id)
592599
if gcs_location:
@@ -709,14 +716,18 @@ def launch_workload_with_node_reach_to_step(
709716
wait_for_file_to_exist = gcs.wait_for_file_to_exist.override(
710717
task_id=task_id_wait_file_exist
711718
)(
712-
file_path=f"{gcs_path}/{str(expect_reach_to_step)}/commit_success.txt",
719+
file_path=(
720+
f"{gcs_path}/{str(expect_reach_to_step)}/commit_success.txt"
721+
),
713722
)
714723
task_id_do_nothing = "do_nothing"
715724
do_nothing = EmptyOperator(task_id=task_id_do_nothing)
716725

717726
@task.branch
718727
def task_path_decider(check_file_exists: bool = False) -> str:
719-
"""Dynamically route the workflow depending on the `check_file_exists`."""
728+
"""Dynamically route the workflow depending on the
729+
`check_file_exists`.
730+
"""
720731
if check_file_exists:
721732
return f"{group.group_id}.{task_id_wait_file_exist}"
722733
return f"{group.group_id}.{task_id_do_nothing}"

0 commit comments

Comments
 (0)