I have a trouble after trying to parallelize data using nn.Dataparallel
I didn't have any probelm without data parallelization, but after I put JUST A ONE LINE "model = nn.DataParallel(model)" the error message "TypeError: 'list' object is not callable" comes. If I push out that damn line the source works clean. plz help me

I can't do anything but just mad. I search that google and there are some ways to solve that error message but I can't do anything. Because nn.Dataparallel is already used by other coders. Sorry English is not my mothertongue.

    if use_cuda:
            [[[model = nn.DataParallel(model)]]]
            model = model.cuda()
            criterion = criterion.cuda()
            print('cuda is used')


I just put model = nn.DataParallel(model) and error comes right after.


  Traceback (most recent call last):
    File "/home/scrcdeep2/YBJ/espnet_myself/Main.py", line 119, in 
      train(loader, model_, criterion_, optimizer_, use_cuda_, pretrained=None)
  
  File "/home/scrcdeep2/YBJ/espnet_myself/Main.py", line 83, in train
      outputs = model(inputs)
  
  File "/home/scrcdeep2/YBJ/lib/python3.5/site-packages/torch/nn/modules/module.py", line 493, in call
      result = self.forward(*input, **kwargs)
   File "/home/scrcdeep2/YBJ/lib/python3.5/site-packages/torch/nn/parallel/data_parallel.py", line 151, in forward
      replicas = self.replicate(self.module, self.device_ids[:len(inputs)])
  
  File "/home/scrcdeep2/YBJ/lib/python3.5/site-packages/torch/nn/parallel/data_parallel.py", line 156, in replicate
      return replicate(module, device_ids)
  
  File "/home/scrcdeep2/YBJ/lib/python3.5/site-packages/torch/nn/parallel/replicate.py", line 114, in replicate
      modules = list(network.modules())
  
  TypeError: 'list' object is not callable


I met the same problem, because I've set moules = [list].
I changed my code like this:
def __init__(self, embedding_size, activation_function='relu'):
    super().__init__()
    self.act_fn = getattr(F, activation_function)
    self.embedding_size = embedding_size
    self.conv1 = nn.Conv2d(3, 32, 4, stride=2)
    self.conv2 = nn.Conv2d(32, 64, 4, stride=2)
    self.conv3 = nn.Conv2d(64, 128, 4, stride=2)
    self.conv4 = nn.Conv2d(128, 256, 4, stride=2)
    self.fc = nn.Identity() if embedding_size == 1024 else nn.Linear(1024, embedding_size)
    if not args.MultiGPU:
      self.modules = [self.conv1, self.conv2, self.conv3, self.conv4]

