forked from kaito-project/kaito
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Factoring out reusable presets logic - Part 4 (kaito-project#332)
- Loading branch information
1 parent
cf7cf94
commit 77aa95b
Showing
2 changed files
with
101 additions
and
63 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,72 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
kaitov1alpha1 "github.com/azure/kaito/api/v1alpha1" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
const ( | ||
DefaultVolumeMountPath = "/dev/shm" | ||
) | ||
|
||
func ConfigSHMVolume(wObj *kaitov1alpha1.Workspace) (corev1.Volume, corev1.VolumeMount) { | ||
volume := corev1.Volume{} | ||
volumeMount := corev1.VolumeMount{} | ||
|
||
// Signifies multinode inference requirement | ||
if *wObj.Resource.Count > 1 { | ||
// Append share memory volume to any existing volumes | ||
volume = corev1.Volume{ | ||
Name: "dshm", | ||
VolumeSource: corev1.VolumeSource{ | ||
EmptyDir: &corev1.EmptyDirVolumeSource{ | ||
Medium: "Memory", | ||
}, | ||
}, | ||
} | ||
|
||
volumeMount = corev1.VolumeMount{ | ||
Name: volume.Name, | ||
MountPath: DefaultVolumeMountPath, | ||
} | ||
} | ||
|
||
return volume, volumeMount | ||
} | ||
|
||
func ConfigDataVolume() ([]corev1.Volume, []corev1.VolumeMount) { | ||
var volumes []corev1.Volume | ||
var volumeMounts []corev1.VolumeMount | ||
volumes = append(volumes, corev1.Volume{ | ||
Name: "data-volume", | ||
VolumeSource: corev1.VolumeSource{ | ||
EmptyDir: &corev1.EmptyDirVolumeSource{}, | ||
}, | ||
}) | ||
|
||
volumeMounts = append(volumeMounts, corev1.VolumeMount{ | ||
Name: "data-volume", | ||
MountPath: "/data", | ||
}) | ||
return volumes, volumeMounts | ||
} | ||
|
||
func ShellCmd(command string) []string { | ||
return []string{ | ||
"/bin/sh", | ||
"-c", | ||
command, | ||
} | ||
} | ||
|
||
func BuildCmdStr(baseCommand string, torchRunParams map[string]string) string { | ||
updatedBaseCommand := baseCommand | ||
for key, value := range torchRunParams { | ||
updatedBaseCommand = fmt.Sprintf("%s --%s=%s", updatedBaseCommand, key, value) | ||
} | ||
|
||
return updatedBaseCommand | ||
} |