Holds submodules in a list. The interface is consistent with PyTorch. The documentation is referenced from: https://pytorch.org/docs/1.10/generated/torch.nn.ModuleList.html?#torch.nn.ModuleList. :class:`~oneflow.nn.ModuleList` can be indexed like a regular Python list, but
| 58 | |
| 59 | |
| 60 | class ModuleList(get_list(Module)): |
| 61 | """Holds submodules in a list. |
| 62 | |
| 63 | The interface is consistent with PyTorch. |
| 64 | The documentation is referenced from: https://pytorch.org/docs/1.10/generated/torch.nn.ModuleList.html?#torch.nn.ModuleList. |
| 65 | |
| 66 | :class:`~oneflow.nn.ModuleList` can be indexed like a regular Python list, but |
| 67 | modules it contains are properly registered, and will be visible by all |
| 68 | :class:`~oneflow.nn.Module` methods. |
| 69 | |
| 70 | Args: |
| 71 | modules (iterable, optional): an iterable of modules to add |
| 72 | |
| 73 | .. code-block:: python |
| 74 | |
| 75 | >>> import oneflow.nn as nn |
| 76 | |
| 77 | >>> class MyModule(nn.Module): |
| 78 | ... def __init__(self): |
| 79 | ... super(MyModule, self).__init__() |
| 80 | ... self.linears = nn.ModuleList([nn.Linear(10, 10) for i in range(10)]) |
| 81 | ... def forward(self, x): |
| 82 | ... # ModuleList can act as an iterable, or be indexed using ints |
| 83 | ... for i, l in enumerate(self.linears): |
| 84 | ... x = self.linears[i // 2](x) + l(x) |
| 85 | ... return x |
| 86 | |
| 87 | >>> model = MyModule() |
| 88 | >>> model.linears |
| 89 | ModuleList( |
| 90 | (0): Linear(in_features=10, out_features=10, bias=True) |
| 91 | (1): Linear(in_features=10, out_features=10, bias=True) |
| 92 | (2): Linear(in_features=10, out_features=10, bias=True) |
| 93 | (3): Linear(in_features=10, out_features=10, bias=True) |
| 94 | (4): Linear(in_features=10, out_features=10, bias=True) |
| 95 | (5): Linear(in_features=10, out_features=10, bias=True) |
| 96 | (6): Linear(in_features=10, out_features=10, bias=True) |
| 97 | (7): Linear(in_features=10, out_features=10, bias=True) |
| 98 | (8): Linear(in_features=10, out_features=10, bias=True) |
| 99 | (9): Linear(in_features=10, out_features=10, bias=True) |
| 100 | ) |
| 101 | |
| 102 | |
| 103 | """ |
| 104 | |
| 105 | pass |
| 106 | |
| 107 | |
| 108 | class ModuleDict(get_dict(Module)): |