MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / state_dict

Method state_dict

imperative/python/megengine/module/module.py:456–467  ·  view source on GitHub ↗

r"""Returns a dictionary containing whole states of the module.

(self, rst=None, prefix="", keep_var=False)

Source from the content-addressed store, hash-verified

454 return offset
455
456 def state_dict(self, rst=None, prefix="", keep_var=False):
457 r"""Returns a dictionary containing whole states of the module."""
458 _rst = self._state_dict(rst=rst, prefix=prefix, keep_var=keep_var)
459 rst = OrderedDict()
460 XNorm_typeclass = _get_XNorm_typeclass()
461 for (module_type, k), v in _rst.items():
462 # for performance reasons, parameters in XNorm (e.g., BatchNorm2d) are 4-dim tensors,
463 # however they will be reshaped to 1-dim tensors before returned by `statr_dict()`
464 if issubclass(module_type, XNorm_typeclass):
465 v = v.reshape(-1)
466 rst[k] = v
467 return rst
468
469 def _state_dict(self, rst=None, prefix="", keep_var=False):
470 r"""Returns a dictionary containing whole states of the module."""

Callers 9

_state_dictMethod · 0.45
update_modelFunction · 0.45
workerFunction · 0.45
test_save_loadFunction · 0.45
_test_optimizerFunction · 0.45
test_state_dictFunction · 0.45
_check_moduleFunction · 0.45

Calls 4

_state_dictMethod · 0.95
_get_XNorm_typeclassFunction · 0.85
itemsMethod · 0.80
reshapeMethod · 0.45

Tested by 7

update_modelFunction · 0.36
workerFunction · 0.36
test_save_loadFunction · 0.36
_test_optimizerFunction · 0.36
test_state_dictFunction · 0.36
_check_moduleFunction · 0.36