-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add MNIST training in RayCluster with CodeFlare SDK
- Loading branch information
1 parent
8237d22
commit 01718c4
Showing
7 changed files
with
235 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
Copyright 2023. | ||
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. | ||
*/ | ||
|
||
package e2e | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
|
||
batchv1 "k8s.io/api/batch/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
. "github.com/project-codeflare/codeflare-operator/test/support" | ||
) | ||
|
||
func TestMNISTRayClusterSDK(t *testing.T) { | ||
test := With(t) | ||
test.T().Parallel() | ||
|
||
test.T().Skip("Requires https://github.com/project-codeflare/codeflare-sdk/pull/146") | ||
|
||
// Create a namespace | ||
namespace := test.NewTestNamespace() | ||
|
||
// SDK script | ||
sdk := &corev1.ConfigMap{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: corev1.SchemeGroupVersion.String(), | ||
Kind: "ConfigMap", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "sdk", | ||
Namespace: namespace.Name, | ||
}, | ||
BinaryData: map[string][]byte{ | ||
"sdk.py": ReadFile(test, "sdk.py"), | ||
}, | ||
Immutable: Ptr(true), | ||
} | ||
sdk, err := test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Create(test.Ctx(), sdk, metav1.CreateOptions{}) | ||
test.Expect(err).NotTo(HaveOccurred()) | ||
test.T().Logf("Created ConfigMap %s/%s successfully", sdk.Namespace, sdk.Name) | ||
|
||
// pip requirements | ||
requirements := &corev1.ConfigMap{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: corev1.SchemeGroupVersion.String(), | ||
Kind: "ConfigMap", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "requirements", | ||
Namespace: namespace.Name, | ||
}, | ||
BinaryData: map[string][]byte{ | ||
"requirements.txt": ReadFile(test, "requirements.txt"), | ||
}, | ||
Immutable: Ptr(true), | ||
} | ||
requirements, err = test.Client().Core().CoreV1().ConfigMaps(namespace.Name).Create(test.Ctx(), requirements, metav1.CreateOptions{}) | ||
test.Expect(err).NotTo(HaveOccurred()) | ||
test.T().Logf("Created ConfigMap %s/%s successfully", requirements.Namespace, requirements.Name) | ||
|
||
job := &batchv1.Job{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: batchv1.SchemeGroupVersion.String(), | ||
Kind: "Job", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "sdk", | ||
Namespace: namespace.Name, | ||
}, | ||
Spec: batchv1.JobSpec{ | ||
Completions: Ptr(int32(1)), | ||
Parallelism: Ptr(int32(1)), | ||
BackoffLimit: Ptr(int32(0)), | ||
Template: corev1.PodTemplateSpec{ | ||
Spec: corev1.PodSpec{ | ||
Containers: []corev1.Container{ | ||
{ | ||
Name: "sdk", | ||
Image: "quay.io/opendatahub/notebooks:jupyter-minimal-ubi8-python-3.8-4c8f26e", | ||
Command: []string{"/bin/sh", "-c", "pip install -r /test/runtime/requirements.txt && python /test/job/sdk.py"}, | ||
VolumeMounts: []corev1.VolumeMount{ | ||
{ | ||
Name: "sdk", | ||
MountPath: "/test/job", | ||
}, | ||
{ | ||
Name: "requirements", | ||
MountPath: "/test/runtime", | ||
}, | ||
}, | ||
}, | ||
}, | ||
Volumes: []corev1.Volume{ | ||
{ | ||
Name: "sdk", | ||
VolumeSource: corev1.VolumeSource{ | ||
ConfigMap: &corev1.ConfigMapVolumeSource{ | ||
LocalObjectReference: corev1.LocalObjectReference{ | ||
Name: sdk.Name, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "requirements", | ||
VolumeSource: corev1.VolumeSource{ | ||
ConfigMap: &corev1.ConfigMapVolumeSource{ | ||
LocalObjectReference: corev1.LocalObjectReference{ | ||
Name: requirements.Name, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
RestartPolicy: corev1.RestartPolicyNever, | ||
}, | ||
}, | ||
}, | ||
} | ||
job, err = test.Client().Core().BatchV1().Jobs(namespace.Name).Create(test.Ctx(), job, metav1.CreateOptions{}) | ||
test.Expect(err).NotTo(HaveOccurred()) | ||
|
||
defer JobTroubleshooting(test, job) | ||
|
||
test.T().Logf("Waiting for Job %s/%s to complete successfully", job.Namespace, job.Name) | ||
test.Eventually(Job(test, job.Namespace, job.Name), TestTimeoutMedium). | ||
Should(WithTransform(ConditionStatus(batchv1.JobComplete), Equal(corev1.ConditionTrue))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
codeflare-sdk==0.4.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from codeflare_sdk.cluster.cluster import Cluster, ClusterConfiguration | ||
# from codeflare_sdk.cluster.auth import TokenAuthentication | ||
from codeflare_sdk.job.jobs import DDPJobDefinition | ||
|
||
cluster = Cluster(ClusterConfiguration( | ||
name='mnist', | ||
# namespace='default', | ||
min_worker=1, | ||
max_worker=1, | ||
min_cpus=0.2, | ||
max_cpus=1, | ||
min_memory=0.5, | ||
max_memory=1, | ||
gpu=0, | ||
instascale=False, | ||
)) | ||
|
||
cluster.up() | ||
|
||
cluster.status() | ||
|
||
cluster.wait_ready() | ||
|
||
cluster.status() | ||
|
||
cluster.details() | ||
|
||
jobdef = DDPJobDefinition( | ||
name="mnist", | ||
script="/test/job/mnist.py", | ||
scheduler_args={"requirements": "/test/runtime/requirements.txt"} | ||
) | ||
job = jobdef.submit(cluster) | ||
|
||
job.status() | ||
|
||
print(job.logs()) | ||
|
||
cluster.down() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters