LazyConfig#

class LazyConfig(target)#

Bases: object

Deferred-instantiation config builder.

A LazyConfig stores a reference to a target class or callable. Calling the instance with keyword arguments produces an OmegaConf DictConfig that encodes the target and its arguments under the __target__ key — the standard format consumed by instantiate().

Two-step usage:

# Step 1: declare the config (no import of the target needed at this point)
cfg = LazyConfig(torch.nn.Dropout)(p=0.5, inplace=True)

# Step 2: create the object when ready
dropout = instantiate(cfg)
isinstance(dropout, torch.nn.Dropout)  # True

Nesting

LazyConfigs can be nested: passing a LazyConfig result as a keyword argument to another LazyConfig call is supported. instantiate() resolves nested configs recursively when recursive_instantiate=True.

String targets

The target may be a dotted-path string (e.g. "torch.nn.LayerNorm"), a class, or any callable that has __module__ and __name__ attributes.

Parameters:

target (Type | Callable | str) – The class, callable, or fully-qualified dotted string that will be used as __target__ in the resulting config dict.

Example:

cfg = LazyConfig(torch.nn.Dropout)(p=0.5, inplace=True)
module = instantiate(cfg)
isinstance(module, torch.nn.Dropout)  # True
__init__(target)#

Store the target class or callable reference.

Parameters:

target (Type | Callable | str) – A class, callable, or fully-qualified dotted-path string.