Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for target_modules List #439

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions api/v1alpha1/params_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,38 @@
return &config, nil
}

func validateLoraConfigViaConfigMap(cm *corev1.ConfigMap) *apis.FieldError {
config, err := UnmarshalTrainingConfig(cm)
if err != nil {
return err

Check warning on line 114 in api/v1alpha1/params_validation.go

View check run for this annotation

Codecov / codecov/patch

api/v1alpha1/params_validation.go#L114

Added line #L114 was not covered by tests
}
loraConfig := config.TrainingConfig.LoraConfig
if loraConfig != nil {
loraConfigRaw, loraConfigExists := loraConfig["LoraConfig"]
if loraConfigExists {
targetModulesValue, found, err := utils.SearchRawExtension(loraConfigRaw, "target_modules")
if err != nil {
return apis.ErrGeneric(fmt.Sprintf("Failed to parse 'target_modules' in ConfigMap '%s' in namespace '%s': %v", cm.Name, cm.Namespace, err), "target_modules")

Check warning on line 122 in api/v1alpha1/params_validation.go

View check run for this annotation

Codecov / codecov/patch

api/v1alpha1/params_validation.go#L122

Added line #L122 was not covered by tests
}
if found {
switch v := targetModulesValue.(type) {
case string:
// Valid single string
case []interface{}:
for _, item := range v {
if _, ok := item.(string); !ok {
return apis.ErrInvalidValue(fmt.Sprintf("All elements in 'target_modules' must be strings in ConfigMap '%s' in namespace '%s'", cm.Name, cm.Namespace), "target_modules")

Check warning on line 131 in api/v1alpha1/params_validation.go

View check run for this annotation

Codecov / codecov/patch

api/v1alpha1/params_validation.go#L131

Added line #L131 was not covered by tests
}
}
default:
return apis.ErrInvalidValue(fmt.Sprintf("'target_modules' must be either a string or an array of strings in ConfigMap '%s' in namespace '%s'", cm.Name, cm.Namespace), "target_modules")

Check warning on line 135 in api/v1alpha1/params_validation.go

View check run for this annotation

Codecov / codecov/patch

api/v1alpha1/params_validation.go#L134-L135

Added lines #L134 - L135 were not covered by tests
}
}
}
}
return nil
}

func validateTrainingArgsViaConfigMap(cm *corev1.ConfigMap) *apis.FieldError {
config, err := UnmarshalTrainingConfig(cm)
if err != nil {
Expand Down Expand Up @@ -273,6 +305,9 @@
if err := validateTrainingArgsViaConfigMap(&cm); err != nil {
errs = errs.Also(err)
}
if err := validateLoraConfigViaConfigMap(&cm); err != nil {
errs = errs.Also(err)

Check warning on line 309 in api/v1alpha1/params_validation.go

View check run for this annotation

Codecov / codecov/patch

api/v1alpha1/params_validation.go#L309

Added line #L309 was not covered by tests
}
}
return errs
}
2 changes: 1 addition & 1 deletion api/v1alpha1/workspace_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func defaultConfigMapManifest() *v1.ConfigMap {
LoraConfig:
r: 16
lora_alpha: 32
target_modules: "query_key_value"
target_modules: ["query_key_value"]
lora_dropout: 0.05
bias: "none"

Expand Down
4 changes: 4 additions & 0 deletions presets/tuning/text-generation/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def flatten_config_to_cli_args(config, prefix=''):
for key, value in config.items():
if isinstance(value, dict):
cli_args.extend(flatten_config_to_cli_args(value, prefix=f'{prefix}{key}_'))
elif isinstance(value, list):
cli_arg = f'--{prefix}{key}'
cli_args.append(cli_arg)
cli_args.extend(map(str, value))
else:
cli_arg = f'--{prefix}{key}'
cli_args.append(cli_arg)
Expand Down
Loading