Skip to content

Commit

Permalink
Added resources list for CPU based usecase, updated requirements.txt …
Browse files Browse the repository at this point in the history
…to resolve fsspec/numpy package compatibility issue and added license in MNIST script
  • Loading branch information
abhijeet-dhumal committed Jan 2, 2025
1 parent 4b92b1d commit 5674d65
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 18 deletions.
46 changes: 30 additions & 16 deletions tests/kfto/kfto_mnist_training_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

func TestPyTorchJobMnistCpu(t *testing.T) {
runKFTOPyTorchMnistJob(t, 0, 2, "", GetCudaTrainingImage(), "resources/requirements.txt")
runKFTOPyTorchMnistJob(t, 0, 1, "", GetCudaTrainingImage(), "resources/requirements.txt")
}

func TestPyTorchJobMnistWithCuda(t *testing.T) {
Expand Down Expand Up @@ -149,6 +149,12 @@ func createKFTOPyTorchMnistJob(test Test, namespace string, config corev1.Config
MountPath: "/mnt/output",
},
},
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("6Gi"),
},
},
},
},
Volumes: []corev1.Volume{
Expand Down Expand Up @@ -226,6 +232,12 @@ func createKFTOPyTorchMnistJob(test Test, namespace string, config corev1.Config
MountPath: "/tmp",
},
},
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("6Gi"),
},
},
},
},
Volumes: []corev1.Volume{
Expand Down Expand Up @@ -255,21 +267,9 @@ func createKFTOPyTorchMnistJob(test Test, namespace string, config corev1.Config
}

if useGPU {
// Update resource lists
tuningJob.Spec.PyTorchReplicaSpecs["Master"].Template.Spec.Containers[0].Resources = corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("2"),
corev1.ResourceMemory: resource.MustParse("8Gi"),
corev1.ResourceName(gpuLabel): resource.MustParse(fmt.Sprint(numGpus)),
},
}
tuningJob.Spec.PyTorchReplicaSpecs["Worker"].Template.Spec.Containers[0].Resources = corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("2"),
corev1.ResourceMemory: resource.MustParse("8Gi"),
corev1.ResourceName(gpuLabel): resource.MustParse(fmt.Sprint(numGpus)),
},
}
// Update resource lists for GPU (NVIDIA/ROCm) usecase
tuningJob.Spec.PyTorchReplicaSpecs["Master"].Template.Spec.Containers[0].Resources.Limits[corev1.ResourceName(gpuLabel)] = resource.MustParse(fmt.Sprint(numGpus))
tuningJob.Spec.PyTorchReplicaSpecs["Worker"].Template.Spec.Containers[0].Resources.Limits[corev1.ResourceName(gpuLabel)] = resource.MustParse(fmt.Sprint(numGpus))

// Update tolerations
tuningJob.Spec.PyTorchReplicaSpecs["Master"].Template.Spec.Tolerations = []corev1.Toleration{
Expand All @@ -284,6 +284,20 @@ func createKFTOPyTorchMnistJob(test Test, namespace string, config corev1.Config
Operator: corev1.TolerationOpExists,
},
}
} else {
// Update resource lists for CPU usecase
tuningJob.Spec.PyTorchReplicaSpecs["Master"].Template.Spec.Containers[0].Resources = corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("6Gi"),
},
}
tuningJob.Spec.PyTorchReplicaSpecs["Worker"].Template.Spec.Containers[0].Resources = corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("6Gi"),
},
}
}

tuningJob, err := test.Client().Kubeflow().KubeflowV1().PyTorchJobs(namespace).Create(test.Ctx(), tuningJob, metav1.CreateOptions{})
Expand Down
14 changes: 14 additions & 0 deletions tests/kfto/resources/mnist.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# 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.

import argparse
import os

Expand Down
4 changes: 3 additions & 1 deletion tests/kfto/resources/requirements-rocm.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
--extra-index-url https://download.pytorch.org/whl/rocm6.1
torchvision==0.19.0
tensorboard==2.18.0
tensorboard==2.18.0
fsspec[http]==2024.6.1
numpy==2.0.2
4 changes: 3 additions & 1 deletion tests/kfto/resources/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
torchvision==0.19.0
tensorboard==2.18.0
tensorboard==2.18.0
fsspec[http]==2024.6.1
numpy==2.0.2

0 comments on commit 5674d65

Please sign in to comment.