-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathvalidations_wrapper.py
More file actions
79 lines (67 loc) · 3.22 KB
/
Copy pathvalidations_wrapper.py
File metadata and controls
79 lines (67 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file 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.
from functools import wraps
from typing import Any, Callable, TypeVar, cast
from omegaconf import DictConfig, OmegaConf
from pydantic import ValidationError
from launcher.config_validator.schema.llmft_schema_validation import (
LLMFTRecipeValidator,
LLMFTTrainerValidator,
)
from launcher.config_validator.schema.nova_schema_validation import NovaRecipeValidator
from launcher.config_validator.schema.verl_schema_validation import VerlRecipeValidator
from launcher.config_validator.type_validator import TypeValidator
from launcher.config_validator.value_validator import ValueValidator
_T = TypeVar("_T", bound=Callable[..., Any])
def validate_config(fn: _T) -> _T:
@wraps(fn)
def validations_wrapper(config: DictConfig, *args, **kwargs) -> DictConfig:
"""
Execute all validations in this function
"""
type_validator = TypeValidator(config)
type_validator.validate()
schema_validator = ValueValidator(config)
schema_validator.validate()
# Add Pydantic schema validation here
if "recipes" in config:
try:
recipes_dict = OmegaConf.to_container(config.recipes, resolve=True)
# Detect framework type based on model_type
model_type = recipes_dict.get("run", {}).get("model_type", "")
# Apply framework-specific validation
if model_type and model_type.startswith("amazon.nova"):
# Check if this is a distillation job
training_config = recipes_dict.get("training_config", {})
is_distillation = training_config.get("distillation_data") == "true"
if not is_distillation:
# Validate Nova config only for non-distillation jobs
NovaRecipeValidator(**recipes_dict)
elif model_type == "verl":
# Validate Verl config
VerlRecipeValidator(**recipes_dict)
elif model_type.startswith("llm_finetuning_aws"):
# Validate llmft config
LLMFTRecipeValidator(**recipes_dict)
elif model_type.startswith("hf"):
# For hf recipes, only validate the trainer section for now
if "trainer" in recipes_dict:
trainer_dict = recipes_dict.get("trainer", {})
LLMFTTrainerValidator(**trainer_dict)
else:
# Default to skip validation
pass
except ValidationError as e:
raise e
return fn(config, *args, **kwargs)
return cast(_T, validations_wrapper)