feat: enhance training and experiment tracking functionality
- Updated `Activities` class to improve garbage collection handling. - Enhanced error messaging in `ExperimentTracking` for better clarity on update failures. - Refactored `Training` class to streamline exception handling and improve type hints. - Introduced new methods in `TrainModelParams` for better handling of experiment run IDs and model metadata. - Added functionality to extract model equations in `DataManagerRepository` for linear regression models.
This commit is contained in:
@@ -84,6 +84,8 @@ class TrainModelParams:
|
||||
Args:
|
||||
data: Dictionary containing training parameters with keys matching the
|
||||
attribute names (e.g. variable_columns, data_model_kwargs, model_kwargs, opt_params).
|
||||
model_metadata may be omitted or None until load_model_metadata fills it.
|
||||
experiment_run_id may be an int or numeric string.
|
||||
|
||||
Returns:
|
||||
TrainModelParams: Validated instance with all fields populated
|
||||
@@ -111,7 +113,7 @@ class TrainModelParams:
|
||||
train_size=cls._check_none(data.get('train_size'), int, 'train_size'),
|
||||
shuffle=cls._check_none(data.get('shuffle'), bool, 'shuffle'),
|
||||
random_state=cls._check_none(data.get('random_state', 42), int, 'random_state'),
|
||||
experiment_run_id=cls._check_none(data.get('experiment_run_id'), int, 'experiment_run_id'),
|
||||
experiment_run_id=cls._coerce_experiment_run_id(data.get('experiment_run_id')),
|
||||
model_name=model_name,
|
||||
experiment_name=model_name + '_experiment',
|
||||
val_file_name=data.get('val_file_name'),
|
||||
@@ -121,7 +123,7 @@ class TrainModelParams:
|
||||
model_type=cls._check_none(data.get('model_type'), str, 'model_type'),
|
||||
model_id=data.get('model_id'),
|
||||
|
||||
model_metadata=cls._check_none(data.get('model_metadata'), dict, 'model_metadata'),
|
||||
model_metadata=cls._parse_optional_model_metadata(data.get('model_metadata')),
|
||||
)
|
||||
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
@@ -181,6 +183,60 @@ class TrainModelParams:
|
||||
|
||||
return value
|
||||
|
||||
@staticmethod
|
||||
def _coerce_experiment_run_id(value: Any) -> int:
|
||||
"""
|
||||
Coerce experiment_run_id to int.
|
||||
|
||||
Workflow clients may send numeric strings; this keeps from_dict aligned with
|
||||
workflow validation.
|
||||
|
||||
Args:
|
||||
value: Raw experiment_run_id from the payload.
|
||||
|
||||
Returns:
|
||||
int: Parsed experiment run id.
|
||||
|
||||
Raises:
|
||||
ValueError: If the value is None.
|
||||
TypeError: If the value cannot be coerced to a non-boolean integer.
|
||||
"""
|
||||
if value is None:
|
||||
raise ValueError('experiment_run_id is required and cannot be None.')
|
||||
if isinstance(value, bool):
|
||||
raise TypeError('experiment_run_id must be an integer, got bool.')
|
||||
if isinstance(value, int):
|
||||
return value
|
||||
if isinstance(value, str) and value.strip().isdigit():
|
||||
return int(value.strip())
|
||||
if isinstance(value, float) and value.is_integer():
|
||||
return int(value)
|
||||
raise TypeError(
|
||||
f'experiment_run_id must be an integer or numeric string, but got {type(value).__name__}.'
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _parse_optional_model_metadata(value: Any) -> dict | None:
|
||||
"""
|
||||
Parse model_metadata for from_dict before load_model_metadata fills the index.
|
||||
|
||||
Args:
|
||||
value: model_metadata from the payload, or None if not sent yet.
|
||||
|
||||
Returns:
|
||||
dict | None: Dict when provided; None when absent (filled later by load_model_metadata).
|
||||
|
||||
Raises:
|
||||
TypeError: If value is neither None nor a dict.
|
||||
"""
|
||||
if value is None:
|
||||
return None
|
||||
if isinstance(value, dict):
|
||||
return value
|
||||
raise TypeError(
|
||||
f'model_metadata must be a dict or None, but got {type(value).__name__}.'
|
||||
)
|
||||
|
||||
def validate_business_rules(self) -> None:
|
||||
"""
|
||||
Validate business rules and constraints for training parameters.
|
||||
|
||||
Reference in New Issue
Block a user