class_docstr: Holds submodules in a list.
  
  This class extends :class:`torch.nn.ModuleList` with an extra feature that
  optionally drops a random number of submodules at every iteration during
  training.
  
  Usage:
  
  >>> from torch.nn import Module
  >>>
  >>> from fairseq2.nn import ModuleList
  >>>
  >>> layer1 = Module()
  >>> layer2 = Module()
  >>> layer3 = Module()
  >>>
  >>> layers = ModuleList([layer1, layer2, layer3], drop_p=0.5)
  >>>
  >>> for layer in layers.drop_iter():  # This might iterate over layers 1 and 3.
  ...    x = layer(x)
  >>> for layer in layers.drop_iter():  # This might iterate over all layers.
  ...    x = layer(x)
  >>> for layer in layers.drop_iter():  # This might not iterate over any layers.
  ...    x = layer(x)
docstr: :param modules:
      An iterable of modules to add.
  :param drop_p:
      The probability of dropping a submodule during training.
docstr_tok: [":","param","modules",":","An","iterable","of","modules","to","add",".",":","param","drop_p",":","The","probability","of","dropping","a","submodule","during","training","."]
code: def __init__(
      self,
      modules: Optional[Iterable[Module]] = None,
      *,
      drop_p: float = 0.0,
  ) -> None:
      """
      :param modules:
          An iterable of modules to add.
      :param drop_p:
          The probability of dropping a submodule during training.
      """
      super().__init__(modules)
  
      self.drop_p = drop_p
  
file_path: fairseq2/src/fairseq2/nn/module_list.py
imports: from typing import Iterable, Iterator, Optional, final
  import torch
  from torch.nn import Module
  from torch.nn import ModuleList
  from fairseq2.typing import CPU
label_desc: Use image node_id 1 to create a new ModuleList object from inherited base classes: ModuleListBase with example: obj = ModuleList(modules)