Base Configuration#

class ablator.config.main.ConfigBase(*args: Any, debug: bool = False, **kwargs: Any)[source]

This class is the building block for all configuration objects within ablator. It serves as the base class for configurations such as ModelConfig, TrainConfig, OptimizerConfig, and more. Together with @configclass, it allows for the creation of config classes of customized attributes without the need to define a constructor. ConfigBase and @configclass take care of the initialization and parsing of the attributes. The example section below shows this in more detail.

In summary, to customize configurations for specific needs, you can create your own configuration class by inheriting it from ConfigBase. It’s essential to annotate it with @configclass. In the tutorial Search space for different types of optimizers and scheduler, a custom optimizer config class is created to enable ablation study on various optimizers and schedulers. You can refer to this tutorial for a realistic example of how to create your custom configuration class.

Note

One key takeaway is that when initializing a config object, you can look into the list of attributes defined in the config class to see what arguments you can pass.

Parameters:
*argsAny

This argument is just for disabling passing by positional arguments.

debugbool, optional

Whether to load the configuration in debug mode and ignore discrepancies/errors, by default False.

**kwargsAny

Keyword arguments. Possible arguments are from the annotations of the configuration class. You can look into the Examples section for more details.

Raises:
ValueError

If positional arguments are provided or there are missing required values.

KeyError

If unexpected arguments are provided.

RuntimeError

If the class is not decorated with @configclass.

Note

All config classes must be decorated with @configclass.

Examples

>>> @configclass
>>> class MyCustomConfig(ConfigBase):
...     attr1: int = 1
...     attr2: Tuple[str, int, str]
>>> my_config = MyCustomConfig(attr1=4, attr2=("hello", 1, "world"))  # Pass by named arguments
>>> kwargs = {"attr1": 4, "attr2": ("hello", 1, "world")}   # Pass by keyword arguments
>>> my_config = MyCustomConfig(**kwargs)

Note that since we defined MyCustomConfig as a config class with two annotated attributes attr1 and attr2 (without a constructor, which is automatically handled by ConfigBase and @configclass), when creating the config object, you can directly pass attr1 and attr2. You can also pass these arguments as keyword arguments.

Attributes:
config_classType

The class of the configuration object.