sage.core.config

Filename : config.py Description : Short description of the file

Created on 2025-11-27 00:24:23

__author__ = Narenraju Nagarajan __copyright__ = Copyright 2025, Sage __license__ = MIT Licence __version__ = 0.0.1 __maintainer__ = Narenraju Nagarajan __affiliation__ = N/A __email__ = N/A __status__ = [‘inProgress’, ‘Archived’, ‘inUsage’, ‘Debugging’]

GitHub Repository: NULL

Documentation: NULL

Attributes

logger

AVAILABLE_STYLES

Classes

ConfiguredModule

Base nn.Module that automatically attaches the global cfg and

StyleConfig

Base configuration class for Sage.

Functions

register_configs(cfg, data_cfg)

Register the global training and data configuration objects.

get_cfg()

Return the globally registered training configuration.

get_data_cfg()

Return the globally registered data configuration.

inject_configs(cfg_cls, data_cfg_cls)

Class decorator that attaches cfg and data_cfg instances to any

Module Contents

logger[source]
AVAILABLE_STYLES[source]
register_configs(cfg, data_cfg)[source]

Register the global training and data configuration objects.

Must be called once at the start of each run (typically inside set_configs() in the run-specific config.py). All Sage modules that call get_cfg() or get_data_cfg() depend on this having been called first.

Parameters:
  • cfg (BaseConfig) – Wrapped training configuration (batch size, device, dtype, …).

  • data_cfg (BaseDataConfig) – Wrapped data configuration (file paths, sample rate, sequence length, …).

get_cfg()[source]

Return the globally registered training configuration.

Returns:

The configuration object registered via register_configs().

Return type:

BaseConfig

Raises:

RuntimeError – If register_configs() has not been called yet.

get_data_cfg()[source]

Return the globally registered data configuration.

Returns:

The data configuration object registered via register_configs().

Return type:

BaseDataConfig

Raises:

RuntimeError – If register_configs() has not been called yet.

inject_configs(cfg_cls, data_cfg_cls)[source]

Class decorator that attaches cfg and data_cfg instances to any class at construction time.

This is an alternative to inheriting from ConfiguredModule for non-nn.Module classes that still need access to the configuration.

Parameters:
  • cfg_cls (type) – Config class to instantiate and assign to self.cfg.

  • data_cfg_cls (type) – Data config class to instantiate and assign to self.data_cfg.

Returns:

A decorator that wraps the target class’s __init__.

Return type:

Callable

Example

@inject_configs(MyCFG, MyDataCFG)
class MyProcessor:
    def __init__(self):
        pass  # self.cfg and self.data_cfg are already set
class ConfiguredModule[source]

Bases: torch.nn.Module

Base nn.Module that automatically attaches the global cfg and data_cfg objects to self at construction time.

Subclass this instead of nn.Module to avoid calling get_cfg() and get_data_cfg() manually in every __init__.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

cfg = None[source]
data_cfg = None[source]
class StyleConfig[source]

Base configuration class for Sage.

Users should subclass this and can optionally set:
  1. mplstyle : str (e.g., “dark”) Upon instantiation, the chosen style is automatically applied.

mplstyle: str = 'classic'[source]
apply_style()[source]

Load the user’s chosen matplotlib style file.