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

Method named_modules

imperative/python/megengine/module/module.py:357–373  ·  view source on GitHub ↗

r"""Returns an iterable of key-module pairs for all the modules within this module, including itself, where 'key' is the dotted path from this module to the submodules. Args: prefix: prefix prepended to the path.

(
        self, prefix: Optional[str] = None, **kwargs
    )

Source from the content-addressed store, hash-verified

355 yield from self._flatten(with_key=False, predicate=_is_module, **kwargs)
356
357 def named_modules(
358 self, prefix: Optional[str] = None, **kwargs
359 ) -> "Iterable[Tuple[str, Module]]":
360 r"""Returns an iterable of key-module pairs for all the modules within this
361 module, including itself, where 'key' is the dotted path from this module to the
362 submodules.
363
364 Args:
365 prefix: prefix prepended to the path.
366 """
367 if "with_parent" in kwargs and kwargs["with_parent"]:
368 yield ("" if prefix is None else prefix), self, None
369 else:
370 yield ("" if prefix is None else prefix), self
371 yield from self._flatten(
372 with_key=True, prefix=prefix, predicate=_is_module, **kwargs
373 )
374
375 def apply(self, fn: "Callable[[Module], Any]") -> None:
376 r"""Applies function ``fn`` to all the modules within this module, including

Callers 8

module_statsFunction · 0.80
get_scaled_modelFunction · 0.80
test_module_apiFunction · 0.80
test_expand_structureFunction · 0.80
test_flatten_with_parentFunction · 0.80
_check_qat_moduleFunction · 0.80

Calls 1

_flattenMethod · 0.95

Tested by 6

test_module_apiFunction · 0.64
test_expand_structureFunction · 0.64
test_flatten_with_parentFunction · 0.64
_check_qat_moduleFunction · 0.64