Course on MLOps by girafe.ai team
import hydra
from omegaconf import DictConfig


@hydra.main(config_path="conf", config_name="config", version_base="1.3")
def main(cfg: DictConfig) -> None:
    print(cfg)


if __name__ == "__main__":
    main()

04_data_management_and_configs/hydra/after/1-basic/example.py
girafe-ai/mlops
from dataclasses import dataclass


@dataclass
class Data:
    name: str
    path: str
    test_size: float
    seed: int


@dataclass
class Model:
    name: str
    layers: int
    output_dim: int


@dataclass
class Training:
    batch_size: int
    epochs: int
    learning_rate: float
    optimizer: str
    gpu_id: int
    grad_accumulate_batches: int
    precision: str


@dataclass
class Params:
    data: Data
    model: Model
    training: Training

04_data_management_and_configs/hydra/after/2-dataclasses/config.py
girafe-ai/mlops
import hydra
from hydra.core.config_store import ConfigStore

from config import Params


cs = ConfigStore.instance()
cs.store(name="params", node=Params)


@hydra.main(config_path="conf", config_name="config", version_base="1.3")
def main(cfg: Params) -> None:
    print(cfg)


if __name__ == "__main__":
    main()

04_data_management_and_configs/hydra/after/2-dataclasses/example.py
girafe-ai/mlops
from typing import Any
from dataclasses import dataclass


@dataclass
class CIFARData:
    name: str
    path: str
    test_size: float
    seed: int


@dataclass
class MNISTData:
    name: str
    path: str
    test_size: float
    seed: int


@dataclass
class Model:
    name: str
    layers: int
    output_dim: int


@dataclass
class Training:
    batch_size: int
    epochs: int
    learning_rate: float
    optimizer: str
    gpu_id: int
    grad_accumulate_batches: int
    precision: str


@dataclass
class Params:
    data: Any
    model: Model
    training: Training

04_data_management_and_configs/hydra/after/3-groups/config.py
girafe-ai/mlops
import hydra
from hydra.core.config_store import ConfigStore

from config import Params, CIFARData, MNISTData


cs = ConfigStore.instance()
cs.store(name="params", node=Params)
cs.store(group="data", name="base_cifar", node=CIFARData)
cs.store(group="data", name="base_mnist", node=MNISTData)


@hydra.main(config_path="conf", config_name="config", version_base="1.3")
def main(cfg: Params) -> None:
    print(dir(cfg))
    print(cfg)


# python example.py +data=cifar
# python example.py +data=mnist
if __name__ == "__main__":
    main()

04_data_management_and_configs/hydra/after/3-groups/example.py
girafe-ai/mlops
from typing import Dict, Any


config = {
    "data": {
        "name": "cifar",
        "path": "/data/to/cifar/dataset",
        "test_size": 0.2,
        "seed": 42,
    },
    "model": {
        "name": "resnet",
        "layers": 50,
        "output_dim": 128,
    },
    "training": {
        "batch_size": 32,
        "epochs": 10,
        "learning_rate": 1e-3,
        "optimizer": "adam",
        "gpu_id": 2,
        "grad_accumulate_batches": 4,
        "precision": "fp16",
    },
}


def main(cfg: Dict[str, Any]) -> None:
    print(cfg)


if __name__ == "__main__":
    main(config)

04_data_management_and_configs/hydra/before/example.py
girafe-ai/mlops