-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathcommon_utils.py
953 lines (796 loc) · 28.5 KB
/
common_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"Bash helper commands for AOTC artifacts"
import os
import tempfile
import yaml
from google.cloud import storage
from airflow.decorators import task
from airflow.hooks.subprocess import SubprocessHook
from xlml.utils import metric
from xlml.apis import metric_config
from dags.map_reproducibility.utils.benchmarkdb_utils import write_run
from datetime import datetime, timezone
PROJECT = "supercomputer-testing"
BUCKET_NAME = "regression-testing-xlml"
MAX_TFLOP = {"a3ultra": 989, "a3mega": 989, "a4": 2237}
# This is required to get auth to access
def git_cookie_authdaemon():
auth_cmds = (
"git clone https://gerrit.googlesource.com/gcompute-tools",
"echo 'trying to run git-cookie-authdaemon'",
# Check if the daemon is already running
"if (( $(ps aux | grep git-cookie-authdaemon | grep -v -E 'airflow|grep|bash' | wc -l)>0 )) ; then " # greater than one because one would be the main job
" echo 'git-cookie-authdaemon is already running' ",
"else "
" (./gcompute-tools/git-cookie-authdaemon >/dev/null 2>&1 &) ", # Run if not running
"sleep 4",
"fi",
"ps aux | grep git-cookie-authdaemon | grep -v -E 'airflow|grep|bash'",
)
return auth_cmds
def clone_recipes_gob():
gob_clone_cmds = (
"echo 'trying to clone GoB repo from outside'",
"git clone https://ai-hypercomputer-benchmarks.googlesource.com/"
"reproducible-benchmark-recipes",
)
return gob_clone_cmds
def clone_internal_recipes_gob():
gob_clone_cmds = (
"echo 'trying to clone internal GoB repo'",
"git clone https://jax3p-gpu-benchmarking.googlesource.com/"
"internal-gpu-recipes",
)
return gob_clone_cmds
def get_internal_pre_workload_cmds(model_id, framework, is_pgle):
prepare_workload_cmds = (
"NOW=$(date +%s)",
f"export JOB_NAME=internal-reg-{model_id}-$NOW-{framework}",
)
if is_pgle:
prepare_workload_cmds += (
"export JAX_ENABLE_PGLE=true",
"export JAX_PGLE_PROFILING_RUNS=2",
)
return prepare_workload_cmds
def get_bq_writer_repo():
gob_clone_cmds = (
"echo 'trying to clone GoB bq writer repo'",
"git clone https://cmcs-perf-tooling-internal.googlesource.com/"
"benchmark-automation",
)
return gob_clone_cmds
def configure_project_and_cluster(cluster: str, cluster_region: str):
set_project_command = (
f"gcloud config set project {PROJECT}",
"sudo chown -R airflow:airflow /home/airflow/composer_kube_config",
"gcloud container clusters get-credentials "
f"{cluster} --region {cluster_region}",
)
return set_project_command
def get_gpu_recipe_cmd(hypercomputer, model_id, framework, recipe_repo_root):
gpu_recipe_cmd = (
"cd reproducible-benchmark-recipes/projects/gpu-recipes",
"export RECIPE_ROOT="
f"{recipe_repo_root}/training/{hypercomputer}/{model_id}/{framework}-pretraining-gke",
"cd $RECIPE_ROOT",
)
return gpu_recipe_cmd
def get_pre_workload_cmds(model_id, framework):
prepare_workload_cmds = (
"NOW=$(date +%s)",
f"export JOB_NAME=imo-team-regr-test-{model_id}-$NOW-{framework}",
)
return prepare_workload_cmds
def install_helm_cmds():
install_helm_cmd = (
"curl -fsSL -o get_helm.sh "
"https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3",
"chmod 700 get_helm.sh",
"./get_helm.sh",
)
return install_helm_cmd
# By default the composer environment overwrites the
# namespaces to airflow namespaces.
# In order to prevent that it is necessary explicitly
# change the namespace to default.
def namespace_cmds():
namespace = (
"kubectl config view | grep namespace",
"kubectl config set-context --current --namespace=default",
"kubectl config set-context helm --namespace=default",
)
return namespace
def helm_apply_cmds(
framework: str,
hypercomputer: str,
config_file,
recipe_repo_root,
docker_image,
aotc: bool = False,
cluster_name: str = "a3plus-benchmark",
kueue_name: str = None,
additional_cmds: str = "",
num_steps: int = None,
):
gcs_cmd = ""
if hypercomputer in ("a3ultra", "a4"):
if framework != "maxtext" and kueue_name:
gcs_cmd = f" --set queue={kueue_name}"
gcs_cmd += f" --set volumes.gcsMounts[0].bucketName={BUCKET_NAME}"
else:
gcs_cmd = f" --set workload.gcsBucketForDataCataPath={BUCKET_NAME}"
if num_steps:
additional_cmds += f" --set workload.steps={num_steps} "
cluster_cmd = ""
if framework == "nemo" and hypercomputer == "a3ultra":
cluster_cmd = f" --set clusterName={cluster_name}"
run_name_cmd = ""
if framework == "maxtext":
run_name_cmd = "--set workload.run_name=$JOB_NAME"
set_aotc = ""
if aotc:
set_aotc = " --set-string workload.aotc=true "
helm_cmds = (
" helm install -f values.yaml "
"--namespace default "
"--set namespace=default"
f" --set-file {framework}_config"
f"={config_file}"
" --set workload.image"
f"={docker_image} "
f"{cluster_cmd} {run_name_cmd} {gcs_cmd} {set_aotc}"
f"{additional_cmds}"
f" $JOB_NAME {recipe_repo_root}/src/helm-charts/{hypercomputer}/{framework}-training",
)
return helm_cmds
def helm_apply_cmds_internal_run(
framework: str,
hypercomputer: str,
config_file,
recipe_repo_root,
values_file_path,
docker_image,
aotc: bool = False,
cluster_name: str = "a3plus-benchmark",
kueue_name: str = "a3-ultra",
additional_cmds: str = "",
):
gcs_cmd = ""
if framework == "maxtext":
gcs_cmd += f" --set volumes.gcsMounts[0].bucketName={BUCKET_NAME} "
if hypercomputer == "a3ultra":
if framework != "maxtext":
gcs_cmd += f" --set queue={kueue_name} "
else:
gcs_cmd += f" --set workload.gcsBucketForDataCataPath={BUCKET_NAME} "
cluster_cmd = ""
if framework == "nemo" and hypercomputer == "a3ultra":
cluster_cmd = f" --set clusterName={cluster_name} "
run_name_cmd = ""
if framework == "maxtext":
run_name_cmd = " --set workload.run_name=$JOB_NAME "
set_aotc = ""
if aotc:
set_aotc = " --set-string workload.aotc=true "
if hypercomputer == "a3mega":
helm_template_path = f"/home/airflow/gcs/dags/dags/map_reproducibility/helm-charts/{hypercomputer}/{framework}-training"
else:
helm_template_path = f"{recipe_repo_root}/src/helm-charts/{hypercomputer}/{framework}-training"
helm_cmds = (
f" helm install -f {values_file_path} "
"--namespace default "
"--set namespace=default"
f" --set-file {framework}_config"
f"={config_file}"
" --set workload.image"
f"={docker_image} "
f"{cluster_cmd} {run_name_cmd} {gcs_cmd} {set_aotc}"
f"{additional_cmds}"
# f" $JOB_NAME {recipe_repo_root}/src/helm-charts/{hypercomputer}/{framework}-training",
f" $JOB_NAME {helm_template_path}",
)
print("*******helm cmd is*******")
print(helm_cmds)
return helm_cmds
def wait_for_jobs_cmds():
wait_for_job = (
"echo 'will wait for jobs to finish'",
"kubectl wait --for=condition=complete "
"job/$JOB_NAME --namespace=default --timeout=100m",
)
return wait_for_job
def copy_bucket_cmds_nemo(recipe_repo_root, hypercomputer: str = "a3mega"):
gcs_location = ""
if hypercomputer in ("a3ultra", "a4"):
gcs_location = f"gs://{BUCKET_NAME}/nemo-experiments/megatron_gpt/"
else:
gcs_location = f"gs://{BUCKET_NAME}/nemo-experiments/"
copy_bucket_contents = (
"export COMPLETE_JOB_NAME=$(gcloud storage ls "
f"{gcs_location} | grep $JOB_NAME)",
'echo "COMPLETE_JOB_NAME ${COMPLETE_JOB_NAME}"',
f"cd {recipe_repo_root}/src/utils/training_metrics",
"gcloud storage cp ${COMPLETE_JOB_NAME}"
"dllogger/rank-0/dllogger.json .",
)
return copy_bucket_contents
def copy_bucket_cmds_maxtext(tmpdir, recipe_repo_root):
gcs_location = f"gs://{BUCKET_NAME}/maxtext/"
cmds = (
f"METRICS_FILE={tmpdir}/tflog/metrics",
"export BUCKET_FOLDER=$(gcloud storage ls "
f"{gcs_location} | grep $JOB_NAME)",
'echo "BUCKET_FOLDER ${BUCKET_FOLDER}"',
"export COMPLETE_JOB_NAME=$(gcloud storage ls "
"${BUCKET_FOLDER}tensorboard/ | grep $JOB_NAME)",
'echo "COMPLETE_JOB_NAME ${COMPLETE_JOB_NAME}"',
"export LOG_FILE=$(gcloud storage ls "
"${COMPLETE_JOB_NAME} | grep events)",
'echo "LOG_FILE ${LOG_FILE}"',
"gcloud storage cp $LOG_FILE $METRICS_FILE",
)
return cmds
def calculate_maxtext_metrics(log_location: str, hardware: str = "a3ultra"):
metrics, _ = metric.read_from_tb(log_location, None, None)
print(f"metrics - {metrics}")
step_time_metrics = metrics["perf/step_time_seconds"]
avg_step_time = metric.aggregate_metrics(
step_time_metrics, metric_config.AggregationStrategy.AVERAGE
)
tflop_per_device_per_sec_metrics = metrics["perf/per_device_tflops_per_sec"]
avg_tflop_per_device_per_sec = metric.aggregate_metrics(
tflop_per_device_per_sec_metrics,
metric_config.AggregationStrategy.AVERAGE,
)
mfu = avg_tflop_per_device_per_sec / MAX_TFLOP[hardware]
return mfu, avg_step_time
def get_nemo_metrics_cmds(
batch_size,
num_accelerators,
precision,
model_id,
accelertator_type,
temdir,
two_node: bool = False,
):
step_cmd = ""
if two_node:
step_cmd = "--start_step 0 --end_step 0 "
cmds = (
f"METRICS_FILE={temdir}/metrics.txt",
"python3 process_training_results.py --file"
f" dllogger.json --batch_size {batch_size} "
f"--num_accelerators {num_accelerators} "
f"--precision {precision} "
f"--model_type {model_id} "
f"{step_cmd}"
f"--accelerator_type {accelertator_type} | "
"gsutil cp - $METRICS_FILE",
)
return cmds
def cleanup_cmds():
cleanup = (
"helm uninstall $JOB_NAME -n default",
"kubectl get pods "
"--no-headers=true | awk '{print $1}' "
"| grep $JOB_NAME | xargs kubectl delete pods",
'echo "pods cleaned up"',
)
return cleanup
def get_nemo_metrics(temdir):
file_content = ""
with open(temdir + "/metrics.txt", "r", encoding="utf-8") as file:
file_content = file.read()
# Parse the metrics (adjust based on your file format)
lines = file_content.splitlines()
average_step_time = float(lines[0].split(": ")[1])
tflops_per_accelerator = float(lines[1].split(": ")[1])
mfu = float(lines[2].split(": ")[1])
print(f"Average Step Time: {average_step_time}")
print(f"TFLOPS/Accelerator: {tflops_per_accelerator}")
print(f"MFU: {mfu}")
return average_step_time, mfu
def get_internal_recipe_repo_path(tmpdir):
recipe_repo_root = os.path.join(tmpdir, "internal-gpu-recipes")
return recipe_repo_root
def extract_gpus(tmpdir, yaml_file):
gpus = None
try:
yaml_file_path = os.path.join(tmpdir, yaml_file)
with open(yaml_file_path, "r", encoding="utf-8") as file:
config = yaml.safe_load(file)
gpus = config.get("workload", {}).get("gpus")
except (FileNotFoundError, yaml.YAMLError) as e:
print(f"Error: {e}")
return None
return gpus
def extract_run_details(root, config_path):
batch_size = None
optimizer = None
try:
config_path = os.path.join(root, config_path)
with open(config_path, "r", encoding="utf-8") as file:
config = yaml.safe_load(file)
batch_size = config.get("model", {}).get("global_batch_size")
precision = config.get("trainer", {}).get("precision")
optimizer = config.get("model", {}).get("optim", {}).get("name")
seq_length = config.get("model", {}).get("data", {}).get("seq_length")
max_steps = config.get("trainer", {}).get("max_steps")
except (FileNotFoundError, yaml.YAMLError) as e:
print(f"Error: {e}")
return None
return batch_size, optimizer, precision, seq_length, max_steps
def get_accelerator_type(hypercomputer: str):
if hypercomputer == "a3ultra":
return "h200"
elif hypercomputer == "a3mega":
return "h100"
elif hypercomputer == "a4":
return "b200"
def get_bq_writer_path(tempdir):
return os.path.join(tempdir, "benchmark-automation/benchmark_db_writer/src")
def get_recipe_repo_path(tmpdir):
recipe_repo_root = os.path.join(
tmpdir, "reproducible-benchmark-recipes/projects/gpu-recipes"
)
return recipe_repo_root
def get_cluster(hardware: str = "a3ultra"):
if hardware == "a3mega":
return "a3plus-benchmark", "australia-southeast1"
if hardware == "a3ultra":
return "gke-a3ultra-bm-map-3", "europe-west1"
if hardware == "a4":
return "map-a4-gke", "us-central1"
def get_scheduled_time(hardware: str, model: str, framework: str):
"""
Returns a cron expression for the DAG schedule based on
the given hardware, model, and framework.
Each model runs on Thursday on a unique time so
that we have free nodes for each.
The alloted time for these tests is 6 pm - 10 pm PST on Thursday.
6 PM pst - 0 2 * * 5
10 PM pst - 0 6 * * 5
Args:
hardware: The hardware type (e.g., "a3ultra", "a3mega").
model: The model ID (e.g., "mixtral-8x7b", "llama-3.1-70b").
framework: The framework (e.g., "nemo", "maxtext").
Returns:
A cron expression string (e.g., "0 12 * * 4") or None
if no schedule is defined
for the given combination.
"""
schedule_map = {
"a3ultra": {
"mixtral-8x7b": {
"nemo": "0 3 * * 5",
"maxtext": "0 2 * * 5", # 6 PM PST on Thursday
},
"llama3-1-70b": {
"nemo": "0 4 * * 5",
"maxtext": "0 4 * * 5",
},
"llama3-1-405b": {
"nemo": "0 5 * * 5",
"maxtext": "0 5 * * 5",
},
},
"a3mega": {
"mixtral-8x7b": {
"nemo": "0 4 * * 5",
"maxtext": "0 3 * * 5",
},
"llama-3-70b": {
"nemo": "0 2 * * 5",
"maxtext": "0 5 * * 5",
},
"llama3-1-70b": {
"nemo": "0 2 * * 5",
"maxtext": "0 4 * * 5",
},
"gpt3-175b": {
"nemo": "0 4 * * 5",
},
},
"a4": {
"mixtral-8x7b": {
"nemo": "0 2 * * 5",
},
"llama3-1-70b": {
"nemo": "0 3 * * 5",
"maxtext": "0 3 * * 5",
},
"llama3-1-405b": {
"nemo": "0 4 * * 5",
"maxtext": "0 4 * * 5",
},
},
}
if hardware in schedule_map:
if model in schedule_map[hardware]:
if framework in schedule_map[hardware][model]:
return schedule_map[hardware][model][framework]
return None # Return None if no schedule is found for the given combination
def get_docker_image(hardware: str, framework: str):
"""
Returns the appropriate Docker image based on the given hardware, model, and framework.
Args:
hardware: The hardware type (e.g., "a3ultra", "a3mega").
framework: The framework (e.g., "nemo", "maxtext").
Returns:
A Docker image string or None if no image is defined for the given combination.
"""
image_map = {
"a3ultra": {
"nemo": "us-central1-docker.pkg.dev/deeplearning-images/reproducibility/pytorch-gpu-nemo-nccl:nemo24.07-gib1.0.3-A3U",
"maxtext": "us-central1-docker.pkg.dev/supercomputer-testing/gunjanjalori/maxtext-benchmark",
},
"a3mega": {
"nemo": "us-central1-docker.pkg.dev/deeplearning-images/reproducibility/pytorch-gpu-nemo:nemo24.07-A3Mega",
"maxtext": "us-central1-docker.pkg.dev/supercomputer-testing/gunjanjalori/maxtext-benchmark",
},
"a4": {
"nemo": "us-central1-docker.pkg.dev/deeplearning-images/reproducibility/pytorch-gpu-nemo-nccl:nemo25.02-gib1.0.5-A4",
"maxtext": "us-central1-docker.pkg.dev/deeplearning-images/reproducibility/jax-maxtext-gpu:jax0.5.1-cuda_dl25.02-rev1-maxtext-20150317",
},
}
if hardware in image_map:
if framework in image_map[hardware]:
return image_map[hardware][framework]
return None # Return None if no image is found for the given combination
def get_internal_docker_image(hardware: str, framework: str):
"""
Returns the appropriate Docker image based on the given hardware, model, and framework.
Args:
hardware: The hardware type (e.g., "a3ultra", "a3mega").
framework: The framework (e.g., "nemo", "maxtext").
Returns:
A Docker image string or None if no image is defined for the given combination.
"""
utc_date = datetime.now(timezone.utc).strftime("%Y-%m-%d")
utc_date = "2025-03-10"
image_map = {
"a3ultra": {
"nemo": "us-central1-docker.pkg.dev/deeplearning-images/reproducibility/pytorch-gpu-nemo-nccl:nemo24.07-gib1.0.3-A3U",
"maxtext": f"gcr.io/supercomputer-testing/jax3p_nightly:{utc_date}",
},
"a3mega": {
"nemo": "us-central1-docker.pkg.dev/deeplearning-images/reproducibility/pytorch-gpu-nemo:nemo24.07-A3Mega",
"maxtext": f"gcr.io/supercomputer-testing/jax3p_nightly:{utc_date}",
},
}
if hardware in image_map:
if framework in image_map[hardware]:
return image_map[hardware][framework]
return None # Return None if no image is found for the given combination
def get_two_node_cmds(hypercomputer: str = "a3ultra"):
cmd = ' --set workload.arguments="{trainer.max_steps=1}" --set workload.gpus=16 '
if hypercomputer == "a3mega":
cmd += '--set workload.arguments="{model.pipeline_model_parallel_size=2}"'
return cmd
def parse_internal_config_filename(filename):
"""
Parse a config filename to extract config values.
Args:
filename (str): Config filename like 'a3ultra_llama3.1-70b_256gpus_bf16_maxtext.yaml'
Returns:
object: Config values accessible via dot notation
"""
# Simple dot notation class
class Config:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
# Remove file extension and split by underscore
parts = filename.split(".yaml")[0].split("_")
# Extract components
hypercomputer = parts[0]
model_id_raw = parts[1]
model_id = model_id_raw.replace("llama", "llama-")
num_gpus = int(parts[2].replace("gpus", ""))
precision = parts[3]
framework = parts[4]
is_pgle = False
if len(parts) >= 6 and parts[5] == "pgle":
is_pgle = True
# Create software ID based on framework
software_id = f"{'jax' if framework == 'maxtext' else 'pytorch'}_{framework}"
# Return config object with dot notation access
return Config(
MODEL_ID=model_id,
HELM_NAME_MODEL_ID=model_id_raw.replace(".", "-"),
PRECISION=precision,
HYPERCOMPUTER=hypercomputer,
FRAMEWORK=framework,
SOFTWARE_ID=software_id,
NUM_GPUS=num_gpus,
IS_PGLE=is_pgle,
)
def parse_internal_config_content(yaml_path):
"""
Parse the internal content of a config YAML file.
Args:
yaml_path (str): Path to the YAML file
Returns:
object: Config values accessible via dot notation
"""
import yaml
# Simple dot notation class with dictionary-like representation
class Config:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def __repr__(self):
return repr(self.__dict__)
def __str__(self):
return str(self.__dict__)
try:
# Open and read the YAML file
with open(yaml_path, "r") as file:
result = yaml.safe_load(file)
# Return config object with dot notation access
return Config(
SEQUENCE_LENGTH=result.get("max_target_length", None),
BATCH_SIZE_PER_DEVICE=result.get("per_device_batch_size", None)
# Add other mappings here as needed
)
except Exception as e:
print(f"Unexpected error: {e}")
raise e
@task
def run_nemo_workload(
hypercomputer: str,
model_id: str,
framework: str,
precision: str,
metrics_model_id: str,
num_gpus: int = None,
num_steps: int = None,
two_node: bool = False,
kueue_name: str = None,
config_model_name: str = None,
):
with tempfile.TemporaryDirectory() as tmpdir:
hook = SubprocessHook()
result = hook.run_command(
[
"bash",
"-c",
";".join(
git_cookie_authdaemon()
+ clone_recipes_gob()
+ get_bq_writer_repo()
),
],
cwd=tmpdir,
)
recipe_repo_root = get_recipe_repo_path(tmpdir)
bq_writer_repo_root = get_bq_writer_path(tmpdir)
value_yaml_path = f"training/{hypercomputer}/{model_id}/{framework}-pretraining-gke/values.yaml"
num_gpus_file = extract_gpus(recipe_repo_root, value_yaml_path)
if config_model_name:
config_yaml_path = f"src/frameworks/{hypercomputer}/{framework}-configs/{config_model_name}"
else:
config_hardware = f"{'a3u-' if hypercomputer == 'a3ultra' else ''}"
config_yaml_path = f"src/frameworks/{hypercomputer}/{framework}-configs/{model_id}-{num_gpus_file}gpus-{config_hardware}{precision}.yaml"
full_config_yaml_path = os.path.join(recipe_repo_root, config_yaml_path)
(
global_batch_size,
optimizer,
precision,
seq_length,
num_steps,
) = extract_run_details(recipe_repo_root, config_yaml_path)
accelerator_type = get_accelerator_type(hypercomputer)
print(
f"batch size: {global_batch_size}, num gpus: {num_gpus}, precision: {precision}, seq length: {seq_length}, num steps: {num_steps}"
)
additional_cmds = ""
if two_node == True:
additional_cmds += get_two_node_cmds(hypercomputer, framework)
if num_gpus:
additional_cmds += f" --set workload.gpus={num_gpus} "
else:
num_gpus = num_gpus_file
cluster, cluster_region = get_cluster(hypercomputer)
result = hook.run_command(
[
"bash",
"-c",
";".join(
configure_project_and_cluster(cluster, cluster_region)
+ get_gpu_recipe_cmd(
hypercomputer, model_id, framework, recipe_repo_root
)
+ install_helm_cmds()
+ namespace_cmds()
+ get_pre_workload_cmds(model_id, framework)
+ helm_apply_cmds(
framework,
hypercomputer,
full_config_yaml_path,
recipe_repo_root,
get_docker_image(hypercomputer, framework),
cluster_name=cluster,
kueue_name=kueue_name,
additional_cmds=additional_cmds,
)
+ wait_for_jobs_cmds()
+ copy_bucket_cmds_nemo(
recipe_repo_root,
hypercomputer=hypercomputer,
)
+ get_nemo_metrics_cmds(
global_batch_size,
num_gpus,
precision,
metrics_model_id,
accelerator_type,
tmpdir,
two_node=two_node,
)
+ cleanup_cmds()
),
],
cwd=tmpdir,
)
assert result.exit_code == 0, f"Command failed with code {result.exit_code}"
average_step_time, mfu = get_nemo_metrics(tmpdir)
write_run(
model_id=model_id,
hardware_id=hypercomputer,
software_id=get_software_id(framework),
number_of_nodes=num_gpus / 8,
number_of_chips=num_gpus,
container_image_name=get_image_version(framework),
global_batch_size=global_batch_size,
precision=precision,
optimizer=optimizer,
seq_length=seq_length,
median_step_time=average_step_time,
e2e_time=0,
number_of_steps=num_steps,
mfu=mfu,
tokens_per_second=1,
writer_path=bq_writer_repo_root,
topology="2X2",
comment="Regression tests",
is_test=False,
)
@task
def run_maxtext_workload(
hypercomputer: str,
model_id: str,
framework: str,
precision: str,
num_steps: int,
batch_size_per_device: int,
kueue_name: str,
optimizer: str,
sequence_length: int,
helm_model_id: str,
num_gpus: int = None,
gpu_overide: bool = True,
):
with tempfile.TemporaryDirectory() as tmpdir:
hook = SubprocessHook()
result = hook.run_command(
[
"bash",
"-c",
";".join(
git_cookie_authdaemon()
+ clone_recipes_gob()
+ get_bq_writer_repo()
),
],
cwd=tmpdir,
)
value_yaml_path = f"training/{hypercomputer}/{model_id}/{framework}-pretraining-gke/values.yaml"
recipe_repo_root = get_recipe_repo_path(tmpdir)
bq_writer_repo_root = get_bq_writer_path(tmpdir)
num_gpus_in_file = extract_gpus(recipe_repo_root, value_yaml_path)
gpu_helm_cmd = ""
if num_gpus == None:
num_gpus = num_gpus_in_file
elif num_gpus != num_gpus_in_file:
gpu_helm_cmd = f" --set workload.gpus={num_gpus} "
if gpu_overide == False:
num_gpus = num_gpus_in_file # This is for two node tests, they'll use the same config of more nodes
config_hardware = (
f"{'a3u' if hypercomputer == 'a3ultra' else hypercomputer}"
)
config_yaml_path = f"src/frameworks/{hypercomputer}/maxtext-configs/{model_id}-{num_gpus}gpus-{config_hardware}-{precision}.yaml"
full_config_yaml_path = os.path.join(recipe_repo_root, config_yaml_path)
cluster, cluster_region = get_cluster(hypercomputer)
result = hook.run_command(
[
"bash",
"-c",
";".join(
configure_project_and_cluster(cluster, cluster_region)
+ get_gpu_recipe_cmd(
hypercomputer, model_id, framework, recipe_repo_root
)
+ install_helm_cmds()
+ namespace_cmds()
+ get_pre_workload_cmds(helm_model_id, framework)
+ helm_apply_cmds(
framework,
hypercomputer,
full_config_yaml_path,
recipe_repo_root,
get_docker_image(hypercomputer, framework),
cluster_name=cluster,
kueue_name=kueue_name,
additional_cmds=gpu_helm_cmd,
num_steps=num_steps,
)
+ wait_for_jobs_cmds()
+ copy_bucket_cmds_maxtext(
tmpdir, recipe_repo_root=recipe_repo_root
)
+ cleanup_cmds()
),
],
cwd=tmpdir,
)
assert result.exit_code == 0, f"Command failed with code {result.exit_code}"
log_location = os.path.join(tmpdir, "tflog/metrics")
mfu, step_time = calculate_maxtext_metrics(log_location, hypercomputer)
print(f"mfu: {mfu}")
print(f"step_time: {step_time}")
write_run(
model_id=model_id,
hardware_id=hypercomputer,
software_id=get_software_id(framework),
number_of_nodes=num_gpus / 8,
number_of_chips=num_gpus,
container_image_name=get_image_version(framework),
global_batch_size=batch_size_per_device * num_gpus,
precision=precision,
optimizer=optimizer,
seq_length=sequence_length,
median_step_time=step_time,
e2e_time=step_time * num_steps,
number_of_steps=num_steps,
mfu=mfu,
tokens_per_second=-1,
writer_path=bq_writer_repo_root,
topology="",
comment="Regression tests",
is_test=False,
)
def get_software_id(framework: str):
if framework == "maxtext":
return "jax_maxtext"
elif framework == "nemo":
return "pytorch_nemo"
else:
return None
def get_image_version(framework: str):
if framework == "maxtext":
return "maxtext_nightly"
elif framework == "nemo":
return "nemo24.07-A3U"
else:
return None
def get_two_node_cmds(hypercomputer: str = "a3ultra", framework: str = "nemo"):
cmd = ' --set workload.arguments="{trainer.max_steps=1}" '
if framework == "nemo":
cmd += " --set workload.gpus=16 "
if hypercomputer == "a3mega" and framework == "nemo":
cmd += '--set workload.arguments="{model.pipeline_model_parallel_size=2}"'
if framework == "maxtext":
cmd += " --set dcn_fsdp_parallelism=1 --set ici_fsdp_parallelism=1 --set dcn_data_parallelism=1 "
return cmd