Skip to content

Commit

Permalink
feat(lmeval): Add operator online and execution feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ruivieira committed Dec 10, 2024
1 parent 6f88955 commit 94afdbe
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 30 deletions.
3 changes: 2 additions & 1 deletion config/base/params.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ lmes-image-pull-policy=Always
lmes-max-batch-size=24
lmes-default-batch-size=8
lmes-detect-device=true

lmes-allow-online=true
lmes-allow-code-execution=true
2 changes: 2 additions & 0 deletions config/overlays/odh-kueue/params.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ lmes-image-pull-policy=Always
lmes-max-batch-size=24
lmes-default-batch-size=8
lmes-detect-device=true
lmes-allow-online=true
lmes-allow-code-execution=true
2 changes: 2 additions & 0 deletions config/overlays/odh/params.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ lmes-image-pull-policy=Always
lmes-max-batch-size=24
lmes-default-batch-size=8
lmes-detect-device=true
lmes-allow-online=true
lmes-allow-code-execution=true
2 changes: 2 additions & 0 deletions config/overlays/rhoai/params.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ lmes-image-pull-policy=Always
lmes-max-batch-size=24
lmes-default-batch-size=8
lmes-detect-device=true
lmes-allow-online=false
lmes-allow-code-execution=false
4 changes: 4 additions & 0 deletions controllers/lmes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var Options *serviceOptions = &serviceOptions{
MaxBatchSize: DefaultMaxBatchSize,
DetectDevice: DefaultDetectDevice,
DefaultBatchSize: DefaultBatchSize,
AllowOnline: false,
AllowCodeExecution: false,
}

type serviceOptions struct {
Expand All @@ -47,6 +49,8 @@ type serviceOptions struct {
MaxBatchSize int
DefaultBatchSize string
DetectDevice bool
AllowOnline bool
AllowCodeExecution bool
}

func constructOptionsFromConfigMap(log *logr.Logger, configmap *corev1.ConfigMap) error {
Expand Down
2 changes: 2 additions & 0 deletions controllers/lmes/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const (
MaxBatchSizeKey = "lmes-max-batch-size"
DefaultBatchSizeKey = "lmes-default-batch-size"
DetectDeviceKey = "lmes-detect-device"
AllowOnline = "lmes-allow-online"
AllowCodeExecution = "lmes-allow-code-execution"
DefaultPodImage = "quay.io/trustyai/ta-lmes-job:latest"
DefaultDriverImage = "quay.io/trustyai/ta-lmes-driver:latest"
DefaultPodCheckingInterval = time.Second * 10
Expand Down
74 changes: 45 additions & 29 deletions controllers/lmes/lmevaljob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ var (
"DefaultBatchSize": DefaultBatchSizeKey,
"MaxBatchSize": MaxBatchSizeKey,
"DetectDevice": DetectDeviceKey,
"AllowOnline": AllowOnline,
"AllowCodeExecution": AllowCodeExecution,
}

labelFilterPrefixes = []string{}
Expand Down Expand Up @@ -713,41 +715,55 @@ func CreatePod(svcOpts *serviceOptions, job *lmesv1alpha1.LMEvalJob, log logr.Lo
volumes = append(volumes, outputPVC)
}

// Disable remote code execution by default
if job.Spec.AllowCodeExecution == nil || *job.Spec.AllowCodeExecution == false {
remoteCodeEnvVars := []corev1.EnvVar{
{
Name: "TRUST_REMOTE_CODE",
Value: "0",
},
{
Name: "HF_DATASETS_TRUST_REMOTE_CODE",
Value: "0",
},
remoteCodeEnvVars := []corev1.EnvVar{
{
Name: "TRUST_REMOTE_CODE",
Value: "0",
},
{
Name: "HF_DATASETS_TRUST_REMOTE_CODE",
Value: "0",
},
}

if job.Spec.AllowCodeExecution != nil && *job.Spec.AllowCodeExecution {
// Disable remote code execution by default

if !svcOpts.AllowCodeExecution {
log.Error(fmt.Errorf("code execution not allowed by the operator"), "change this setting and redeploy the operator")
envVars = append(envVars, remoteCodeEnvVars...)
}
} else {
envVars = append(envVars, remoteCodeEnvVars...)
}

offlineHuggingFaceEnvVars := []corev1.EnvVar{
{
Name: "HF_DATASETS_OFFLINE",
Value: "1",
},
{
Name: "HF_HUB_OFFLINE",
Value: "1",
},
{
Name: "TRANSFORMERS_OFFLINE",
Value: "1",
},
{
Name: "HF_EVALUATE_OFFLINE",
Value: "1",
},
}

// Enforce offline mode by default
if job.Spec.AllowOnline == nil || *job.Spec.AllowOnline == false {
offlineHuggingFaceEnvVars := []corev1.EnvVar{
{
Name: "HF_DATASETS_OFFLINE",
Value: "1",
},
{
Name: "HF_HUB_OFFLINE",
Value: "1",
},
{
Name: "TRANSFORMERS_OFFLINE",
Value: "1",
},
{
Name: "HF_EVALUATE_OFFLINE",
Value: "1",
},
if job.Spec.AllowOnline != nil && *job.Spec.AllowOnline {

if !svcOpts.AllowOnline {
log.Error(fmt.Errorf("online mode not allowed by the operator"), "change this setting and redeploy the operator")
envVars = append(envVars, offlineHuggingFaceEnvVars...)
}
} else {
envVars = append(envVars, offlineHuggingFaceEnvVars...)
}

Expand Down

0 comments on commit 94afdbe

Please sign in to comment.