-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration Management
The MLFramework Template leverages Hydra to handle hyperparameter tuning, model composition, and execution settings. By utilizing Hydra, the framework completely decouples configuration parameters from the source code, enabling complex experimental tracking without requiring code modifications.
The fundamental principle of this configuration setup is dynamic object instantiation. Instead of writing boilerplate code to parse arguments and initialize classes, Hydra directly instantiates Python objects from YAML definitions.
Every component that requires initialization (e.g., DataModules, Architectures, Tasks) must define a _target_ key in its YAML configuration. The remaining keys must strictly map to the __init__ signature of the specified target class.
Below is an example of a configuration file for a model architecture, typically located in conf/model/my_model.yaml:
_target_: src.models.architectures.convkan_example.SimpleConvKAN
input_channels: 3
num_classes: 10
hidden_dims: [64, 128, 256]
dropout_rate: 0.3When the pipeline executes, Hydra automatically resolves this configuration into the equivalent Python instantiation:
# Internal Hydra behavior
model = SimpleConvKAN(
input_channels=3,
num_classes=10,
hidden_dims=[64, 128, 256],
dropout_rate=0.3
)Configurations are structured hierarchically. The primary entrypoint configuration (e.g., conf/example_config.yaml) acts as the root node, composing various sub-configurations from specialized directories.
# conf/example_config.yaml
defaults:
- _self_
- data: cifar10_example
- model: convkan_example
trainer:
_target_: lightning.Trainer
max_epochs: 100
accelerator: "gpu"
devices: 1
# Variable interpolation example
seed: 42In this setup, the defaults block dictates which sub-configurations to load. If data: cifar10_example is specified, Hydra looks for conf/data/cifar10_example.yaml and injects its contents into the data namespace of the final configuration tree.
One of the most powerful features of Hydra is the ability to override any parameter directly from the command line interface (CLI). This eliminates the need to maintain dozens of slightly modified YAML files for hyperparameter sweeps.
To override a parameter nested within the configuration tree, specify the exact dot-notation path:
python -m src.cli train -c example_config.yaml trainer.max_epochs=200 data.batch_size=128To entirely replace a sub-configuration module (e.g., swapping the model architecture from CNN to KAN), utilize the override syntax in the defaults list:
python -m src.cli train -c example_config.yaml model=resnet50_exampleHydra supports dynamic variable interpolation, allowing parameters to reference other values within the configuration tree. This is highly beneficial for maintaining consistency.
paths:
data_dir: "./data"
data:
_target_: src.data.cifar10_example.CIFAR10DataModule
# Resolves to "./data" dynamically
data_dir: ${paths.data_dir}If you utilize this framework template in your research or engineering workflows, please consider citing it to support ongoing development:
@software{MLFramework_Template_2026,
author = {Danylo Chystiakov},
title = {MLFramework Template: A Reproducible MLOps Environment},
year = {2026},
url = {[https://github.com/allllpina/MLTemplate](https://github.com/allllpina/MLTemplate)}
}This template is built upon the philosophies and architectural patterns established by the following foundational projects:
- Hydra for hierarchical configuration.
- PyTorch Lightning for hardware-agnostic training abstractions.
- Data Version Control (DVC) for Git-integrated data management.
Contact & Support For inquiries regarding architectural decisions, bug reports, or feature requests, please open an issue on the GitHub repository.
Maintained by Danylo Chystiakov.