問題文
A team stores a list of layers as self.layers = [nn.Linear(10, 10) for _ in range(3)] inside a module. The optimizer receives no parameters from those layers. What is the correct container?
選択肢
- nn.ModuleList, which registers the contained modules so their parameters are discovered.
- nn.Sequential, which is required for any collection of layers whose parameters must be found.
- A plain tuple instead of a list, because immutable containers are traversed when the framework collects the parameters of a module while mutable ones are skipped to avoid inconsistent state.
- A dictionary with string keys, and the framework walks it when it gathers the parameters of the module.