composite
optimus_dl.modules.optim.composite
¶
CompositeOptimizer
¶
Bases: Optimizer
A meta-optimizer that wraps multiple PyTorch optimizers and conforms to the standard torch.optim.Optimizer interface. Supports named optimizers via dictionary.
Source code in optimus_dl/modules/optim/composite.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
load_state_dict(state_dict)
¶
Restores the state dict and repairs the state dictionary reference aliases.
step(closure=None)
¶
Performs a single optimization step across all internal optimizers.
Source code in optimus_dl/modules/optim/composite.py
zero_grad(set_to_none=True)
¶
Clears the gradients of all optimized torch.Tensors across sub-optimizers.
CompositeOptimizerConfig
dataclass
¶
Bases: RegistryConfigStrict
CompositeOptimizerConfig(_name: str | None = None, optimizers: dict[str, optimus_dl.modules.optim.composite.CompositeOptimizerConfigEntry] =
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
optimizers
|
dict[str, CompositeOptimizerConfigEntry]
|
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2) |
<class 'dict'>
|
Source code in optimus_dl/modules/optim/composite.py
CompositeOptimizerConfigEntry
dataclass
¶
Bases: RegistryConfig
CompositeOptimizerConfigEntry(_name: str | None = None, params_regexp: str = '.*', optimizer_config: optimus_dl.core.registry.RegistryConfig =
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params_regexp
|
str
|
|
'.*'
|
optimizer_config
|
RegistryConfig
|
Flexible configuration base class for registry components. This extends RegistryConfigStrict to allow arbitrary additional fields via dictionary inheritance. Use this when you need custom configuration parameters beyond static fields or for dynamic configurations. Attributes: _name: The registered name of the component to instantiate. extra_fields: Additional fields can be added as dictionary keys. |
<dynamic>
|
Source code in optimus_dl/modules/optim/composite.py
get_subgroup(params, predicate)
¶
Utility function to filter parameters based on a predicate applied to their names. Expects params to be an iterable of (name, tensor) tuples or iterable of dicts (subgroups).