.modules() is a function defined under class nn.Module.
  
      github.com
  
  
    pytorch/pytorch/blob/75ee5756715e7161314ce037474843b68f69fc04/torch/nn/modules/module.py#L1367-L1392 6

def modules(self) -> Iterator['Module']:    r"""Returns 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.Linear(2, 2)        >>> net = nn.Sequential(l, l)        >>> for idx, m in enumerate(net.modules()):                print(idx, '->', m)        0 -> Sequential(          (0): Linear(in_features=2, out_features=2, bias=True)          (1): Linear(in_features=2, out_features=2, bias=True)


  This file has been truncated. show original

  
  
    
    
  
  


You need to rename the variable self.modules as it is conflicting with this function.