returnn.frontend.build_from_dict
¶
Construct modules (or other objects) from dictionaries.
- returnn.frontend.build_from_dict.build_from_dict(d: Dict[str, Any], *args, **kwargs) Module | Any [source]¶
Build a module (or other object) from a dictionary. “class” in the dict is required and specifies the class to be instantiated. The other options are passed to the class constructor.
- Parameters:
d – dictionary with the class name and other options
args – passed to the class constructor
kwargs – passed to the class constructor
- Returns:
cls(*args, **d, **kwargs)
(after “class” was popped fromd
)
- returnn.frontend.build_from_dict.build_dict(cls: Type | LambdaType | BuiltinMethodType | Callable[[...], Any], **kwargs) Dict[str, Any] [source]¶
Build a dictionary for
build_from_dict()
. The class name is stored in the “class” key.Note that this is intended to be used for serialization and also to get a unique stable hashable representation (e.g. for Sisyphus
sis_hash_helper()
) which should not change if the class is renamed or moved to keep the hash stable.- Parameters:
cls –
class or function. actually we do not expect any other Callable here. It’s just Callable in the type hint because MyPy/PyCharm don’t correctly support FunctionType
kwargs – other kwargs put into the dict. expect to contain only other serializable values.
- Returns:
build dict. can easily be serialized. to be used with
build_from_dict()
.