LazyConfig#
- class LazyConfig(target)#
Bases:
objectDeferred-instantiation config builder.
A
LazyConfigstores a reference to a target class or callable. Calling the instance with keyword arguments produces an OmegaConfDictConfigthat encodes the target and its arguments under the__target__key — the standard format consumed byinstantiate().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
LazyConfigresult as a keyword argument to anotherLazyConfigcall is supported.instantiate()resolves nested configs recursively whenrecursive_instantiate=True.String targets
The
targetmay 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