@@ -138,35 +138,51 @@ <h1 class="title">Module <code>codeflare_sdk.utils.generate_yaml</code></h1>
138
138
139
139
140
140
def update_custompodresources(
141
- item, min_cpu, max_cpu, min_memory, max_memory, gpu, workers
141
+ item,
142
+ min_cpu,
143
+ max_cpu,
144
+ min_memory,
145
+ max_memory,
146
+ gpu,
147
+ workers,
148
+ head_cpus,
149
+ head_memory,
150
+ head_gpus,
142
151
):
143
152
if "custompodresources" in item.keys():
144
153
custompodresources = item.get("custompodresources")
145
154
for i in range(len(custompodresources)):
155
+ resource = custompodresources[i]
146
156
if i == 0:
147
157
# Leave head node resources as template default
148
- continue
149
- resource = custompodresources[i]
150
- for k, v in resource.items():
151
- if k == "replicas" and i == 1:
152
- resource[k] = workers
153
- if k == "requests" or k == "limits":
154
- for spec, _ in v.items():
155
- if spec == "cpu":
156
- if k == "limits":
157
- resource[k][spec] = max_cpu
158
- else:
159
- resource[k][spec] = min_cpu
160
- if spec == "memory":
161
- if k == "limits":
162
- resource[k][spec] = str(max_memory) + "G"
163
- else:
164
- resource[k][spec] = str(min_memory) + "G"
165
- if spec == "nvidia.com/gpu":
166
- if i == 0:
167
- resource[k][spec] = 0
168
- else:
169
- resource[k][spec] = gpu
158
+ resource["requests"]["cpu"] = head_cpus
159
+ resource["limits"]["cpu"] = head_cpus
160
+ resource["requests"]["memory"] = str(head_memory) + "G"
161
+ resource["limits"]["memory"] = str(head_memory) + "G"
162
+ resource["requests"]["nvidia.com/gpu"] = head_gpus
163
+ resource["limits"]["nvidia.com/gpu"] = head_gpus
164
+
165
+ else:
166
+ for k, v in resource.items():
167
+ if k == "replicas" and i == 1:
168
+ resource[k] = workers
169
+ if k == "requests" or k == "limits":
170
+ for spec, _ in v.items():
171
+ if spec == "cpu":
172
+ if k == "limits":
173
+ resource[k][spec] = max_cpu
174
+ else:
175
+ resource[k][spec] = min_cpu
176
+ if spec == "memory":
177
+ if k == "limits":
178
+ resource[k][spec] = str(max_memory) + "G"
179
+ else:
180
+ resource[k][spec] = str(min_memory) + "G"
181
+ if spec == "nvidia.com/gpu":
182
+ if i == 0:
183
+ resource[k][spec] = 0
184
+ else:
185
+ resource[k][spec] = gpu
170
186
else:
171
187
sys.exit("Error: malformed template")
172
188
@@ -236,11 +252,15 @@ <h1 class="title">Module <code>codeflare_sdk.utils.generate_yaml</code></h1>
236
252
instascale,
237
253
env,
238
254
image_pull_secrets,
255
+ head_cpus,
256
+ head_memory,
257
+ head_gpus,
239
258
):
240
259
if "generictemplate" in item.keys():
241
260
head = item.get("generictemplate").get("spec").get("headGroupSpec")
242
- worker = item.get( "generictemplate ").get( "spec ").get("workerGroupSpecs")[0]
261
+ head[ "rayStartParams "][ "num-gpus "] = str(int(head_gpus))
243
262
263
+ worker = item.get("generictemplate").get("spec").get("workerGroupSpecs")[0]
244
264
# Head counts as first worker
245
265
worker["replicas"] = workers
246
266
worker["minReplicas"] = workers
@@ -256,7 +276,9 @@ <h1 class="title">Module <code>codeflare_sdk.utils.generate_yaml</code></h1>
256
276
update_env(spec, env)
257
277
if comp == head:
258
278
# TODO: Eventually add head node configuration outside of template
259
- continue
279
+ update_resources(
280
+ spec, head_cpus, head_cpus, head_memory, head_memory, head_gpus
281
+ )
260
282
else:
261
283
update_resources(spec, min_cpu, max_cpu, min_memory, max_memory, gpu)
262
284
@@ -381,6 +403,9 @@ <h1 class="title">Module <code>codeflare_sdk.utils.generate_yaml</code></h1>
381
403
def generate_appwrapper(
382
404
name: str,
383
405
namespace: str,
406
+ head_cpus: int,
407
+ head_memory: int,
408
+ head_gpus: int,
384
409
min_cpu: int,
385
410
max_cpu: int,
386
411
min_memory: int,
@@ -406,7 +431,16 @@ <h1 class="title">Module <code>codeflare_sdk.utils.generate_yaml</code></h1>
406
431
update_labels(user_yaml, instascale, instance_types)
407
432
update_priority(user_yaml, item, dispatch_priority, priority_val)
408
433
update_custompodresources(
409
- item, min_cpu, max_cpu, min_memory, max_memory, gpu, workers
434
+ item,
435
+ min_cpu,
436
+ max_cpu,
437
+ min_memory,
438
+ max_memory,
439
+ gpu,
440
+ workers,
441
+ head_cpus,
442
+ head_memory,
443
+ head_gpus,
410
444
)
411
445
update_nodes(
412
446
item,
@@ -421,6 +455,9 @@ <h1 class="title">Module <code>codeflare_sdk.utils.generate_yaml</code></h1>
421
455
instascale,
422
456
env,
423
457
image_pull_secrets,
458
+ head_cpus,
459
+ head_memory,
460
+ head_gpus,
424
461
)
425
462
update_dashboard_route(route_item, cluster_name, namespace)
426
463
if local_interactive:
@@ -577,7 +614,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
577
614
</ details >
578
615
</ dd >
579
616
< dt id ="codeflare_sdk.utils.generate_yaml.generate_appwrapper "> < code class ="name flex ">
580
- < span > def < span class ="ident "> generate_appwrapper</ span > </ span > (< span > name: str, namespace: str, min_cpu: int, max_cpu: int, min_memory: int, max_memory: int, gpu: int, workers: int, template: str, image: str, instascale: bool, instance_types: list, env, local_interactive: bool, image_pull_secrets: list, dispatch_priority: str, priority_val: int)</ span >
617
+ < span > def < span class ="ident "> generate_appwrapper</ span > </ span > (< span > name: str, namespace: str, head_cpus: int, head_memory: int, head_gpus: int, min_cpu: int, max_cpu: int, min_memory: int, max_memory: int, gpu: int, workers: int, template: str, image: str, instascale: bool, instance_types: list, env, local_interactive: bool, image_pull_secrets: list, dispatch_priority: str, priority_val: int)</ span >
581
618
</ code > </ dt >
582
619
< dd >
583
620
< div class ="desc "> </ div >
@@ -588,6 +625,9 @@ <h2 class="section-title" id="header-functions">Functions</h2>
588
625
< pre > < code class ="python "> def generate_appwrapper(
589
626
name: str,
590
627
namespace: str,
628
+ head_cpus: int,
629
+ head_memory: int,
630
+ head_gpus: int,
591
631
min_cpu: int,
592
632
max_cpu: int,
593
633
min_memory: int,
@@ -613,7 +653,16 @@ <h2 class="section-title" id="header-functions">Functions</h2>
613
653
update_labels(user_yaml, instascale, instance_types)
614
654
update_priority(user_yaml, item, dispatch_priority, priority_val)
615
655
update_custompodresources(
616
- item, min_cpu, max_cpu, min_memory, max_memory, gpu, workers
656
+ item,
657
+ min_cpu,
658
+ max_cpu,
659
+ min_memory,
660
+ max_memory,
661
+ gpu,
662
+ workers,
663
+ head_cpus,
664
+ head_memory,
665
+ head_gpus,
617
666
)
618
667
update_nodes(
619
668
item,
@@ -628,6 +677,9 @@ <h2 class="section-title" id="header-functions">Functions</h2>
628
677
instascale,
629
678
env,
630
679
image_pull_secrets,
680
+ head_cpus,
681
+ head_memory,
682
+ head_gpus,
631
683
)
632
684
update_dashboard_route(route_item, cluster_name, namespace)
633
685
if local_interactive:
@@ -700,7 +752,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
700
752
</ details >
701
753
</ dd >
702
754
< dt id ="codeflare_sdk.utils.generate_yaml.update_custompodresources "> < code class ="name flex ">
703
- < span > def < span class ="ident "> update_custompodresources</ span > </ span > (< span > item, min_cpu, max_cpu, min_memory, max_memory, gpu, workers)</ span >
755
+ < span > def < span class ="ident "> update_custompodresources</ span > </ span > (< span > item, min_cpu, max_cpu, min_memory, max_memory, gpu, workers, head_cpus, head_memory, head_gpus )</ span >
704
756
</ code > </ dt >
705
757
< dd >
706
758
< div class ="desc "> </ div >
@@ -709,35 +761,51 @@ <h2 class="section-title" id="header-functions">Functions</h2>
709
761
< span > Expand source code</ span >
710
762
</ summary >
711
763
< pre > < code class ="python "> def update_custompodresources(
712
- item, min_cpu, max_cpu, min_memory, max_memory, gpu, workers
764
+ item,
765
+ min_cpu,
766
+ max_cpu,
767
+ min_memory,
768
+ max_memory,
769
+ gpu,
770
+ workers,
771
+ head_cpus,
772
+ head_memory,
773
+ head_gpus,
713
774
):
714
775
if "custompodresources" in item.keys():
715
776
custompodresources = item.get("custompodresources")
716
777
for i in range(len(custompodresources)):
778
+ resource = custompodresources[i]
717
779
if i == 0:
718
780
# Leave head node resources as template default
719
- continue
720
- resource = custompodresources[i]
721
- for k, v in resource.items():
722
- if k == "replicas" and i == 1:
723
- resource[k] = workers
724
- if k == "requests" or k == "limits":
725
- for spec, _ in v.items():
726
- if spec == "cpu":
727
- if k == "limits":
728
- resource[k][spec] = max_cpu
729
- else:
730
- resource[k][spec] = min_cpu
731
- if spec == "memory":
732
- if k == "limits":
733
- resource[k][spec] = str(max_memory) + "G"
734
- else:
735
- resource[k][spec] = str(min_memory) + "G"
736
- if spec == "nvidia.com/gpu":
737
- if i == 0:
738
- resource[k][spec] = 0
739
- else:
740
- resource[k][spec] = gpu
781
+ resource["requests"]["cpu"] = head_cpus
782
+ resource["limits"]["cpu"] = head_cpus
783
+ resource["requests"]["memory"] = str(head_memory) + "G"
784
+ resource["limits"]["memory"] = str(head_memory) + "G"
785
+ resource["requests"]["nvidia.com/gpu"] = head_gpus
786
+ resource["limits"]["nvidia.com/gpu"] = head_gpus
787
+
788
+ else:
789
+ for k, v in resource.items():
790
+ if k == "replicas" and i == 1:
791
+ resource[k] = workers
792
+ if k == "requests" or k == "limits":
793
+ for spec, _ in v.items():
794
+ if spec == "cpu":
795
+ if k == "limits":
796
+ resource[k][spec] = max_cpu
797
+ else:
798
+ resource[k][spec] = min_cpu
799
+ if spec == "memory":
800
+ if k == "limits":
801
+ resource[k][spec] = str(max_memory) + "G"
802
+ else:
803
+ resource[k][spec] = str(min_memory) + "G"
804
+ if spec == "nvidia.com/gpu":
805
+ if i == 0:
806
+ resource[k][spec] = 0
807
+ else:
808
+ resource[k][spec] = gpu
741
809
else:
742
810
sys.exit("Error: malformed template")</ code > </ pre >
743
811
</ details >
@@ -855,7 +923,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
855
923
</ details >
856
924
</ dd >
857
925
< dt id ="codeflare_sdk.utils.generate_yaml.update_nodes "> < code class ="name flex ">
858
- < span > def < span class ="ident "> update_nodes</ span > </ span > (< span > item, appwrapper_name, min_cpu, max_cpu, min_memory, max_memory, gpu, workers, image, instascale, env, image_pull_secrets)</ span >
926
+ < span > def < span class ="ident "> update_nodes</ span > </ span > (< span > item, appwrapper_name, min_cpu, max_cpu, min_memory, max_memory, gpu, workers, image, instascale, env, image_pull_secrets, head_cpus, head_memory, head_gpus )</ span >
859
927
</ code > </ dt >
860
928
< dd >
861
929
< div class ="desc "> </ div >
@@ -876,11 +944,15 @@ <h2 class="section-title" id="header-functions">Functions</h2>
876
944
instascale,
877
945
env,
878
946
image_pull_secrets,
947
+ head_cpus,
948
+ head_memory,
949
+ head_gpus,
879
950
):
880
951
if "generictemplate" in item.keys():
881
952
head = item.get("generictemplate").get("spec").get("headGroupSpec")
882
- worker = item.get( "generictemplate ").get( "spec ").get("workerGroupSpecs")[0]
953
+ head[ "rayStartParams "][ "num-gpus "] = str(int(head_gpus))
883
954
955
+ worker = item.get("generictemplate").get("spec").get("workerGroupSpecs")[0]
884
956
# Head counts as first worker
885
957
worker["replicas"] = workers
886
958
worker["minReplicas"] = workers
@@ -896,7 +968,9 @@ <h2 class="section-title" id="header-functions">Functions</h2>
896
968
update_env(spec, env)
897
969
if comp == head:
898
970
# TODO: Eventually add head node configuration outside of template
899
- continue
971
+ update_resources(
972
+ spec, head_cpus, head_cpus, head_memory, head_memory, head_gpus
973
+ )
900
974
else:
901
975
update_resources(spec, min_cpu, max_cpu, min_memory, max_memory, gpu)</ code > </ pre >
902
976
</ details >
0 commit comments