Skip to content

Commit c983e09

Browse files
authored
fix: Log complete badput breakdown to avoid missing metrics (GoogleCloudPlatform#1324)
This change refine `check_workload_goodput` to dynamically iterate through the `badput_breakdown` dictionary rather than using hardcoded metric extractions. This change ensures that any newly introduced `BadputType` metrics are automatically logged, eliminating the need for manual updates to the logging logic.
1 parent 34eb574 commit c983e09

1 file changed

Lines changed: 37 additions & 57 deletions

File tree

dags/maxtext_pathways/pw_mcjax_elastic_goodput.py

Lines changed: 37 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -88,63 +88,6 @@
8888
]
8989

9090

91-
@task
92-
def check_workload_goodput(
93-
workload_id: str,
94-
project_id: str,
95-
) -> bool:
96-
"""
97-
Query and log Goodput/Badput metrics for the MaxText XPK workload.
98-
"""
99-
goodput_logger_name = f"goodput_{workload_id}"
100-
os.environ["GOOGLE_CLOUD_PROJECT"] = project_id
101-
goodput_calculator = goodput.GoodputCalculator(
102-
job_name=workload_id,
103-
logger_name=goodput_logger_name,
104-
using_pathways=True,
105-
)
106-
(
107-
current_goodput,
108-
badput_breakdown,
109-
last_step,
110-
) = goodput_calculator.get_job_goodput(include_badput_breakdown=True)
111-
wasted_progress = badput_breakdown[
112-
goodput.BadputType.WASTED_PROGRESS_FROM_DISRUPTION
113-
]
114-
checkpoint_save = badput_breakdown[
115-
goodput.BadputType.UNPRODUCTIVE_CHECKPOINT_SAVE_TIME
116-
]
117-
checkpoint_restore = badput_breakdown[
118-
goodput.BadputType.UNPRODUCTIVE_CHECKPOINT_RESTORE_TIME
119-
]
120-
other_badput = badput_breakdown[goodput.BadputType.OTHER]
121-
122-
logging.info(f"Last step recorded: {last_step}")
123-
logging.info(f"Goodput (%): {current_goodput:.2f}%")
124-
logging.info(
125-
"Badput due to TPU initialization (%): "
126-
f"{badput_breakdown[goodput.BadputType.TPU_INITIALIZATION]:.2f}%"
127-
)
128-
logging.info(
129-
"Badput due to training preparation: "
130-
f"{badput_breakdown[goodput.BadputType.TRAINING_PREP]:.2f}%"
131-
)
132-
logging.info(
133-
"Badput due to program startup: "
134-
f"{badput_breakdown[goodput.BadputType.PROGRAM_STARTUP]:.2f}%"
135-
)
136-
logging.info(
137-
"Badput due to data loading: "
138-
f"{badput_breakdown[goodput.BadputType.DATA_LOADING_SYNC]:.2f}%"
139-
)
140-
logging.info(
141-
f"Badput due to disruption and wasted progress: {wasted_progress:.2f}%"
142-
)
143-
logging.info(f"Badput due to checkpoint save: {checkpoint_save:.2f}%")
144-
logging.info(f"Badput due to checkpoint restore: {checkpoint_restore:.2f}%")
145-
logging.info(f"Badput due to Unknown/Other: {other_badput:.2f}%")
146-
147-
14891
@task.sensor(poke_interval=10, timeout=3600, mode="reschedule")
14992
def check_goodput_logname(
15093
project_id: str,
@@ -189,6 +132,43 @@ def check_goodput_logname(
189132
return True
190133

191134

135+
@task
136+
def check_workload_goodput(
137+
workload_id: str,
138+
project_id: str,
139+
) -> bool:
140+
"""
141+
Query and log Goodput/Badput metrics for the MaxText XPK workload.
142+
"""
143+
goodput_logger_name = f"goodput_{workload_id}"
144+
os.environ["GOOGLE_CLOUD_PROJECT"] = project_id
145+
goodput_calculator = goodput.GoodputCalculator(
146+
job_name=workload_id,
147+
logger_name=goodput_logger_name,
148+
using_pathways=True,
149+
)
150+
(
151+
current_goodput,
152+
badput_breakdown,
153+
last_step,
154+
) = goodput_calculator.get_job_goodput(include_badput_breakdown=True)
155+
156+
logging.info(f"Last step recorded: {last_step}")
157+
logging.info(f"Goodput (%): {current_goodput:.2f}%")
158+
logging.info("\n--- Badput Breakdown ---")
159+
160+
for badput_type, percentage in badput_breakdown.items():
161+
if badput_type == goodput.BadputType.CUSTOM_BADPUT_EVENTS:
162+
logging.info(f"Badput due to {badput_type}:")
163+
custom_events = percentage
164+
if isinstance(custom_events, dict):
165+
for event_name, event_percentage in custom_events.items():
166+
logging.info(f" - {event_name}: {event_percentage:.2f}%")
167+
else:
168+
# Access the name attribute of the enum member
169+
logging.info(f"Badput due to {badput_type.name}: {percentage:.2f}%")
170+
171+
192172
@task
193173
def generate_commands(
194174
dag_params: dict, derived_params: dict, recipe_instance: recipe_cfg.Recipe

0 commit comments

Comments
 (0)