Skip to content

Commit 2d52001

Browse files
authored
Example RayCluster spec with Labels and label_selector API (#4136)
* Add label selector example yaml Signed-off-by: Ryan O'Leary <[email protected]> * Refactor yaml Signed-off-by: Ryan O'Leary <[email protected]> --------- Signed-off-by: Ryan O'Leary <[email protected]>
1 parent 010cb06 commit 2d52001

File tree

1 file changed

+161
-0
lines changed

1 file changed

+161
-0
lines changed
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
apiVersion: ray.io/v1
2+
kind: RayCluster
3+
metadata:
4+
name: ray-label-cluster
5+
spec:
6+
enableInTreeAutoscaling: true
7+
autoscalerOptions:
8+
version: v2
9+
upscalingMode: Default
10+
idleTimeoutSeconds: 600
11+
imagePullPolicy: Always
12+
securityContext: {}
13+
env: []
14+
envFrom: []
15+
resources:
16+
limits:
17+
cpu: "500m"
18+
memory: "512Mi"
19+
requests:
20+
cpu: "500m"
21+
memory: "512Mi"
22+
headGroupSpec:
23+
labels:
24+
ray.io/region: us-central2
25+
resources:
26+
cpu: "0"
27+
template:
28+
spec:
29+
containers:
30+
- name: ray-head
31+
image: rayproject/ray:nightly
32+
ports:
33+
- containerPort: 6379
34+
name: gcs
35+
- containerPort: 8265
36+
name: dashboard
37+
- containerPort: 10001
38+
name: client
39+
resources:
40+
limits:
41+
cpu: "1"
42+
memory: "2G"
43+
requests:
44+
cpu: "1"
45+
memory: "2G"
46+
volumeMounts:
47+
- mountPath: /home/ray/samples
48+
name: ray-example-configmap
49+
volumes:
50+
- name: ray-example-configmap
51+
configMap:
52+
name: ray-example
53+
defaultMode: 0777
54+
items:
55+
- key: example_task.py
56+
path: example_task.py
57+
- key: example_actor.py
58+
path: example_actor.py
59+
- key: example_placement_group.py
60+
path: example_placement_group.py
61+
workerGroupSpecs:
62+
- replicas: 1
63+
minReplicas: 1
64+
maxReplicas: 10
65+
groupName: large-cpu-group
66+
labels:
67+
cpu-family: intel
68+
ray.io/market-type: on-demand
69+
rayStartParams: {}
70+
template:
71+
spec:
72+
containers:
73+
- name: ray-worker
74+
image: rayproject/ray:nightly
75+
resources:
76+
limits:
77+
cpu: "2"
78+
memory: "4G"
79+
requests:
80+
cpu: "2"
81+
memory: "4G"
82+
nodeSelector:
83+
cloud.google.com/machine-family: "N4"
84+
- replicas: 0
85+
minReplicas: 0
86+
maxReplicas: 10
87+
groupName: accelerator-group
88+
labels:
89+
ray.io/market-type: on-demand
90+
ray.io/region: us-central2
91+
rayStartParams: {}
92+
template:
93+
spec:
94+
containers:
95+
- name: ray-worker
96+
image: rayproject/ray:nightly-gpu
97+
resources:
98+
limits:
99+
cpu: "1"
100+
nvidia.com/gpu: "1"
101+
memory: "1G"
102+
requests:
103+
cpu: "1"
104+
nvidia.com/gpu: "1"
105+
memory: "1G"
106+
nodeSelector:
107+
cloud.google.com/gke-spot: "true"
108+
cloud.google.com/gke-accelerator: "nvidia-tesla-a100"
109+
- replicas: 0
110+
minReplicas: 0
111+
maxReplicas: 5
112+
groupName: spot-group
113+
labels:
114+
cpu-family: amd
115+
ray.io/market-type: spot
116+
rayStartParams: {}
117+
template:
118+
spec:
119+
containers:
120+
- name: ray-worker
121+
image: rayproject/ray:nightly
122+
resources:
123+
limits:
124+
cpu: "1"
125+
memory: "1G"
126+
requests:
127+
cpu: "1"
128+
memory: "1G"
129+
nodeSelector:
130+
cloud.google.com/gke-spot: "true"
131+
---
132+
apiVersion: v1
133+
kind: ConfigMap
134+
metadata:
135+
name: ray-example
136+
data:
137+
example_task.py: |
138+
import ray
139+
@ray.remote(num_cpus=1, label_selector={"ray.io/market-type": "on-demand", "cpu-family": "in(intel,amd)"})
140+
def test_task():
141+
pass
142+
ray.init()
143+
ray.get(test_task.remote())
144+
example_actor.py: |
145+
import ray
146+
@ray.remote(num_gpus=1, label_selector={"ray.io/accelerator-type": "A100"})
147+
class Actor:
148+
def ready(self):
149+
return True
150+
ray.init()
151+
my_actor = Actor.remote()
152+
ray.get(my_actor.ready.remote())
153+
example_placement_group.py: |
154+
import ray
155+
from ray.util.placement_group import placement_group
156+
ray.init()
157+
pg = placement_group(
158+
[{"CPU": 1}] * 2,
159+
bundle_label_selector=[{"ray.io/market-type": "spot", "ray.io/region": "!us-central2"},] * 2, strategy="SPREAD"
160+
)
161+
ray.get(pg.ready())

0 commit comments

Comments
 (0)