MCPcopy Create free account
hub / github.com/pytorch/pytorch / modules

Method modules

torch/nn/modules/module.py:2306–2331  ·  view source on GitHub ↗

r"""Return an iterator over all modules in the network. Yields: Module: a module in the network Note: Duplicate modules are returned only once. In the following example, ``l`` will be returned only once. Example:: >>> l = nn

(self)

Source from the content-addressed store, hash-verified

2304 yield name, module
2305
2306 def modules(self) -> Iterator['Module']:
2307 r"""Return an iterator over all modules in the network.
2308
2309 Yields:
2310 Module: a module in the network
2311
2312 Note:
2313 Duplicate modules are returned only once. In the following
2314 example, ``l`` will be returned only once.
2315
2316 Example::
2317
2318 >>> l = nn.Linear(2, 2)
2319 >>> net = nn.Sequential(l, l)
2320 >>> for idx, m in enumerate(net.modules()):
2321 ... print(idx, '->', m)
2322
2323 0 -> Sequential(
2324 (0): Linear(in_features=2, out_features=2, bias=True)
2325 (1): Linear(in_features=2, out_features=2, bias=True)
2326 )
2327 1 -> Linear(in_features=2, out_features=2, bias=True)
2328
2329 """
2330 for _, module in self.named_modules():
2331 yield module
2332
2333 def named_modules(self, memo: Optional[Set['Module']] = None, prefix: str = '', remove_duplicate: bool = True):
2334 r"""Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.

Callers 15

update_bnFunction · 0.45
__init__Method · 0.45
_check_graph_moduleMethod · 0.45
callMethod · 0.45
callMethod · 0.45
prepareFunction · 0.45
pruneMethod · 0.45
__init__Method · 0.45
_root_copy_hookMethod · 0.45
_ddp_init_helperMethod · 0.45

Calls 1

named_modulesMethod · 0.95