MCPcopy Create free account
hub / github.com/apple/axlearn / config_for_class

Function config_for_class

axlearn/common/config.py:1144–1179  ·  view source on GitHub ↗

Returns an instance of ClassConfigBase, which is an object factory for `cls`. In other words, instantiating the config produces an instance of `cls`, where the configured attributes will be provided as arguments to `__init__`. Example: ``` class MyClass: def

(cls: type[T])

Source from the content-addressed store, hash-verified

1142
1143
1144def config_for_class(cls: type[T]) -> Union[Any, ClassConfigBase[T]]:
1145 """Returns an instance of ClassConfigBase, which is an object factory for `cls`.
1146
1147 In other words, instantiating the config produces an instance of `cls`, where the configured
1148 attributes will be provided as arguments to `__init__`.
1149
1150 Example:
1151 ```
1152 class MyClass:
1153 def __init__(self, a: int, b: Optional[int] = None):
1154 self.a = a
1155 self.b = b
1156
1157 def values(self):
1158 return (self.a, self.b)
1159
1160 cfg = config_for_class(MyClass).set(a=2)
1161
1162 # Should produce unique instances.
1163 assert cfg.instantiate() is not cfg.instantiate()
1164
1165 # Should produce the correct values.
1166 assert cfg.instantiate().values() == cfg.instantiate().values()
1167 assert cfg.instantiate().values() == (2, None)
1168 assert cfg.set(b=3).instantiate().values() == (2, 3)
1169 ```
1170
1171 Args:
1172 cls: The class to configure.
1173
1174 Returns:
1175 A Config that when instantiated, invokes `cls.__init__` based on any config fields that have
1176 been set.
1177 """
1178 config_cls = _config_class_for_class(cls)
1179 return config_cls(klass=cls)
1180
1181
1182def maybe_set_config(cfg: _ConfigBase, **kwargs) -> _ConfigBase:

Callers 15

test_asr_inputMethod · 0.90
_vocab_configFunction · 0.90
_vocab_cfgFunction · 0.90
vocab_cfgMethod · 0.90
test_text_inputMethod · 0.90
test_asr_inputMethod · 0.90
_compute_metricsFunction · 0.90
ConfigClass · 0.90
ConfigClass · 0.90
set_retinanet_configFunction · 0.90
_vocab_cfgFunction · 0.90
maybe_to_iter_datasetFunction · 0.90

Calls 1

_config_class_for_classFunction · 0.85

Tested by 13

test_asr_inputMethod · 0.72
vocab_cfgMethod · 0.72
test_text_inputMethod · 0.72
test_asr_inputMethod · 0.72
_compute_metricsFunction · 0.72
_vocab_cfgFunction · 0.72
_cached_vocabFunction · 0.72
vocab_cfgMethod · 0.72
vocab_cfgMethod · 0.72
_mlm_processor_configMethod · 0.72
vocab_cfgMethod · 0.72
vocab_cfgMethod · 0.72