Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RayCluster] Adds aliyun.com/gpu-mem to known custom accelerators #2631

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions ray-operator/controllers/ray/common/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
NeuronCoreRayResourceName = "neuron_cores"
TPUContainerResourceName = "google.com/tpu"
TPURayResourceName = "TPU"
AliyunGPUContainerResourceName = "aliyun.com/gpu-mem"
)

var customAcceleratorToRayResourceMap = map[string]string{
Expand Down Expand Up @@ -795,9 +796,22 @@ func addWellKnownAcceleratorResources(rayStartParams map[string]string, resource
for _, resourceKeyString := range sortedResourceKeys {
resourceValue := resourceLimits[corev1.ResourceName(resourceKeyString)]

// Scan for resource keys that match "aliyun.com/gpu-mem"
if resourceKeyString == AliyunGPUContainerResourceName && !resourceValue.IsZero() {
if existingValue, ok := rayStartParams["num-gpus"]; ok {
existingIntValue, _ := strconv.ParseInt(existingValue, 10, 64)
rayStartParams["num-gpus"] = strconv.FormatInt(existingIntValue+resourceValue.Value(), 10)
} else {
rayStartParams["num-gpus"] = strconv.FormatInt(resourceValue.Value(), 10)
}
}

// Scan for resource keys ending with "gpu" like "nvidia.com/gpu"
if _, ok := rayStartParams["num-gpus"]; !ok {
if strings.HasSuffix(resourceKeyString, "gpu") && !resourceValue.IsZero() {
if strings.HasSuffix(resourceKeyString, "gpu") && !resourceValue.IsZero() {
if existingValue, ok := rayStartParams["num-gpus"]; ok {
existingIntValue, _ := strconv.ParseInt(existingValue, 10, 64)
rayStartParams["num-gpus"] = strconv.FormatInt(existingIntValue+resourceValue.Value(), 10)
} else {
rayStartParams["num-gpus"] = strconv.FormatInt(resourceValue.Value(), 10)
}
}
Expand Down
17 changes: 15 additions & 2 deletions ray-operator/controllers/ray/common/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,17 @@ func TestGenerateRayStartCommand(t *testing.T) {
},
expected: `ray start --resources='{"TPU":4}' `,
},
{
name: "WorkerNode with Aliyun's GPU Share",
nodeType: rayv1.WorkerNode,
rayStartParams: map[string]string{},
resource: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
"aliyun.com/gpu-mem": resource.MustParse("4"),
},
},
expected: `ray start --num-gpus=4 `,
},
{
name: "HeadNode with Neuron Cores",
nodeType: rayv1.HeadNode,
Expand All @@ -1261,24 +1272,26 @@ func TestGenerateRayStartCommand(t *testing.T) {
rayStartParams: map[string]string{},
resource: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
"aliyun.com/gpu-mem": resource.MustParse("3"),
"aws.amazon.com/neuroncore": resource.MustParse("4"),
"nvidia.com/gpu": resource.MustParse("1"),
},
},
expected: `ray start --head --num-gpus=1 --resources='{"neuron_cores":4}' `,
expected: `ray start --head --num-gpus=4 --resources='{"neuron_cores":4}' `,
},
{
name: "HeadNode with multiple custom accelerators",
nodeType: rayv1.HeadNode,
rayStartParams: map[string]string{},
resource: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
"aliyun.com/gpu-mem": resource.MustParse("4"),
"google.com/tpu": resource.MustParse("8"),
"aws.amazon.com/neuroncore": resource.MustParse("4"),
"nvidia.com/gpu": resource.MustParse("1"),
},
},
expected: `ray start --head --num-gpus=1 --resources='{"neuron_cores":4}' `,
expected: `ray start --head --num-gpus=5 --resources='{"neuron_cores":4}' `,
},
{
name: "HeadNode with existing resources",
Expand Down
Loading