Skip to content

Commit

Permalink
feat(lmeval): Add offline mode as default (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruivieira authored Nov 26, 2024
1 parent 3351631 commit 769fa0b
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 13 deletions.
30 changes: 17 additions & 13 deletions controllers/lmes/lmevaljob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,20 +713,24 @@ func CreatePod(svcOpts *serviceOptions, job *lmesv1alpha1.LMEvalJob, log logr.Lo
volumes = append(volumes, outputPVC)
}

// If the job is supposed to run offline, set the appropriate HuggingFace offline flags
if job.Spec.IsOffline() {
// Enforce offline mode by default
offlineHuggingFaceEnvVars := []corev1.EnvVar{
{
Name: "HF_DATASETS_OFFLINE",
Value: "1",
},
{
Name: "HF_HUB_OFFLINE",
Value: "1",
},
{
Name: "TRANSFORMERS_OFFLINE",
Value: "1",
},
}
envVars = append(envVars, offlineHuggingFaceEnvVars...)

offlineHuggingFaceEnvVars := []corev1.EnvVar{
{
Name: "HF_DATASETS_OFFLINE",
Value: "1",
},
{
Name: "HF_HUB_OFFLINE",
Value: "1",
},
}
envVars = append(envVars, offlineHuggingFaceEnvVars...)
if job.Spec.IsOffline() {

// If the job is offline, a storage must be set. PVC is the only supported storage backend at the moment.
offlinePVCMount := corev1.VolumeMount{
Expand Down
106 changes: 106 additions & 0 deletions controllers/lmes/lmevaljob_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ func Test_SimplePod(t *testing.T) {
MountPath: "/opt/app-root/src/bin",
},
},
Env: []corev1.EnvVar{
{
Name: "HF_DATASETS_OFFLINE",
Value: "1",
},
{
Name: "HF_HUB_OFFLINE",
Value: "1",
},
{
Name: "TRANSFORMERS_OFFLINE",
Value: "1",
},
},
},
},
SecurityContext: defaultPodSecurityContext,
Expand Down Expand Up @@ -282,6 +296,7 @@ func Test_WithCustomPod(t *testing.T) {
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
},

VolumeMounts: []corev1.VolumeMount{
{
Name: "shared",
Expand All @@ -297,6 +312,20 @@ func Test_WithCustomPod(t *testing.T) {
corev1.ResourceCPU: resource.MustParse("1"),
},
},
Env: []corev1.EnvVar{
{
Name: "HF_DATASETS_OFFLINE",
Value: "1",
},
{
Name: "HF_HUB_OFFLINE",
Value: "1",
},
{
Name: "TRANSFORMERS_OFFLINE",
Value: "1",
},
},
},
{
Name: "sidecar1",
Expand Down Expand Up @@ -462,6 +491,18 @@ func Test_EnvSecretsPod(t *testing.T) {
},
},
},
{
Name: "HF_DATASETS_OFFLINE",
Value: "1",
},
{
Name: "HF_HUB_OFFLINE",
Value: "1",
},
{
Name: "TRANSFORMERS_OFFLINE",
Value: "1",
},
},
Command: generateCmd(svcOpts, job),
Args: generateArgs(svcOpts, job, log),
Expand Down Expand Up @@ -591,6 +632,20 @@ func Test_FileSecretsPod(t *testing.T) {
Command: generateCmd(svcOpts, job),
Args: generateArgs(svcOpts, job, log),
SecurityContext: defaultSecurityContext,
Env: []corev1.EnvVar{
{
Name: "HF_DATASETS_OFFLINE",
Value: "1",
},
{
Name: "HF_HUB_OFFLINE",
Value: "1",
},
{
Name: "TRANSFORMERS_OFFLINE",
Value: "1",
},
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "shared",
Expand Down Expand Up @@ -1018,6 +1073,21 @@ func Test_ManagedPVC(t *testing.T) {
Command: generateCmd(svcOpts, job),
Args: generateArgs(svcOpts, job, log),
SecurityContext: defaultSecurityContext,
Env: []corev1.EnvVar{
{
Name: "HF_DATASETS_OFFLINE",
Value: "1",
},
{
Name: "HF_HUB_OFFLINE",
Value: "1",
},
{
Name: "TRANSFORMERS_OFFLINE",
Value: "1",
},
},

VolumeMounts: []corev1.VolumeMount{
{
Name: "shared",
Expand Down Expand Up @@ -1134,6 +1204,20 @@ func Test_ExistingPVC(t *testing.T) {
Command: generateCmd(svcOpts, job),
Args: generateArgs(svcOpts, job, log),
SecurityContext: defaultSecurityContext,
Env: []corev1.EnvVar{
{
Name: "HF_DATASETS_OFFLINE",
Value: "1",
},
{
Name: "HF_HUB_OFFLINE",
Value: "1",
},
{
Name: "TRANSFORMERS_OFFLINE",
Value: "1",
},
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "shared",
Expand Down Expand Up @@ -1268,6 +1352,20 @@ func Test_PVCPreference(t *testing.T) {
},
},
},
Env: []corev1.EnvVar{
{
Name: "HF_DATASETS_OFFLINE",
Value: "1",
},
{
Name: "HF_HUB_OFFLINE",
Value: "1",
},
{
Name: "TRANSFORMERS_OFFLINE",
Value: "1",
},
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "shared",
Expand Down Expand Up @@ -1442,6 +1540,10 @@ func Test_OfflineMode(t *testing.T) {
Name: "HF_HUB_OFFLINE",
Value: "1",
},
{
Name: "TRANSFORMERS_OFFLINE",
Value: "1",
},
},
VolumeMounts: []corev1.VolumeMount{
{
Expand Down Expand Up @@ -1594,6 +1696,10 @@ func Test_OfflineModeWithOutput(t *testing.T) {
Name: "HF_HUB_OFFLINE",
Value: "1",
},
{
Name: "TRANSFORMERS_OFFLINE",
Value: "1",
},
},
VolumeMounts: []corev1.VolumeMount{
{
Expand Down

0 comments on commit 769fa0b

Please sign in to comment.