Pydantic utilities¶
Functions and classes to handle the validation of hyperparameters using Pydantic.
- exception metatrain.utils.pydantic.MetatrainValidationError(model: Any, errors: list[dict])[source]¶
Bases:
ExceptionThis class transforms Pydantic validation errors into a more user-friendly format.
- Parameters:
- metatrain.utils.pydantic.validate(model_cls: Any, data: dict, **kwargs: Any) dict[source]¶
Validate with pydantic, raising custom metatrain errors.
- Parameters:
- Returns:
The validated options, which have been sanitized.
- Raises:
MetatrainValidationError – If validation fails.
- Return type:
- metatrain.utils.pydantic.validate_architecture_options(options: dict, model_hypers: type, trainer_hypers: type) dict[source]¶
Validate architecture-specific options using Pydantic.
- Parameters:
- Returns:
The validated options, which have been sanitized.
- Raises:
MetatrainValidationError – If validation fails.
- Return type:
- metatrain.utils.pydantic.validate_base_options(options: dict) dict[source]¶
Validate base options using Pydantic.
- Parameters:
options (dict) – The base options to validate.
- Returns:
The validated options, which have been sanitized.
- Raises:
MetatrainValidationError – If the options are invalid.
- Return type:
- metatrain.utils.pydantic.validate_eval_options(options: dict) dict[source]¶
Validate evaluation options using Pydantic.
- Parameters:
options (dict) – The evaluation options to validate.
- Returns:
The validated options, which have been sanitized.
- Raises:
MetatrainValidationError – If the options are invalid.
- Return type:
- metatrain.utils.pydantic.get_train_json_schema(allow_missing_hypers: bool) dict[source]¶
Generate a JSON schema for the training options.
This JSON schema is a full specification for the input yaml files of
mtt train. Therefore, it includes all possible architectures.- Parameters:
allow_missing_hypers (bool) – Whether to allow missing hyperparameters. If you want to use the JSON schema for validating user input, you should set this to
True, as it will allow users to omit fields that have default values. If you want to use the JSON schema for validating the input once filled in with defaults, you should set this toFalse.- Returns:
The JSON schema as a dictionary.
- Return type: