config#

class fkat.utils.config.SingletonResolver[source]#

A singleton class that resolves and manages training components.

This class serves as a central registry for training-related objects such as trainers, data, models, and checkpoint paths. It ensures that these components are accessible throughout the application while maintaining a single instance.

Example

>>> resolver = SingletonResolver()
>>> resolver.trainer = MyTrainer()
>>> resolver.model = MyModel()
>>> # Access the same instance elsewhere
>>> same_resolver = SingletonResolver()
>>> assert same_resolver.trainer is resolver.trainer
ckpt_path: Optional[Any] = None#

Path to checkpoint files for model loading/saving. Defaults to None.

data: Optional[Any] = None#

The dataset or data loader used for training and evaluation. Defaults to None.

model: Optional[Any] = None#

The model architecture to be trained or evaluated. Defaults to None.

return_predictions: Optional[Any] = None#

Flag or configuration for returning predictions. Defaults to None.

trainer: Trainer#

The trainer instance responsible for executing the training process.

tuners: Optional[Any] = None#

Hyperparameter tuners or optimization components. Defaults to None.

class fkat.utils.config.Trainer(*args, **kwargs)[source]#

Protocol defining the interface for training models.

This protocol establishes the required methods that any trainer implementation must provide. It serves as a structural subtyping interface for objects that can train, evaluate, and make predictions with machine learning models.

Implementations of this protocol should handle the complete training lifecycle, including model fitting, prediction, testing, and validation.

Note

As a Protocol class, this is not meant to be instantiated directly but rather used for type checking and interface definition.

fit(*args: Any, **kwargs: Any) Any[source]#

Train a model on the provided data.

This method handles the model training process, including data loading, optimization, and potentially checkpointing.

Parameters:
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns:

Training results, which may include training history,

trained model, or other relevant information.

Return type:

Any

predict(*args: Any, **kwargs: Any) Any[source]#

Generate predictions using a trained model.

This method applies the trained model to new data to produce predictions.

Parameters:
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns:

Model predictions, which could be probabilities, class labels,

regression values, or other outputs depending on the model type.

Return type:

Any

test(*args: Any, **kwargs: Any) Any[source]#

Evaluate a trained model on test data.

This method assesses model performance on a test dataset, typically calculating metrics such as accuracy, loss, or other relevant measures.

Parameters:
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns:

Test results, which may include metrics, predictions,

or other evaluation information.

Return type:

Any

validate(*args: Any, **kwargs: Any) Any[source]#

Evaluate a trained model on validation data.

This method assesses model performance on a validation dataset, which is typically used during the training process for hyperparameter tuning or early stopping.

Parameters:
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns:

Validation results, which may include metrics, predictions,

or other evaluation information.

Return type:

Any

fkat.utils.config.register_singleton_resolver() Any[source]#
fkat.utils.config.save(cfg: Any, trainer: Trainer) None[source]#
fkat.utils.config.to_primitive_container(cfg: Any) Any[source]#
fkat.utils.config.to_str(cfg: Any) str[source]#

Convert a configuration object to a formatted string representation.

This function takes a configuration object and converts it to a human-readable YAML string. It’s useful for logging, debugging, or displaying configuration settings.

Parameters:

cfg (Any) – The configuration object to convert to string.

Returns:

A formatted string representation of the configuration.

Return type:

str

Example

>>> config = {"model": {"type": "resnet", "layers": 50}, "batch_size": 32}
>>> print(to_str(config))
Config:
model:
  type: resnet
  layers: 50
batch_size: 32