tristandeleu / pytorch-maml

An Implementation of Model-Agnostic Meta-Learning in PyTorch with Torchmeta
MIT License
227 stars 42 forks source link

Any solution for 'TypeError: _conv_forward() takes 3 positional arguments but 4 were given'? #20

Open raidria opened 2 years ago

raidria commented 2 years ago

Hi, thank you for your nice code. I tried to run your code but here's an issue

    python train.py /path/to/data --dataset omniglot --num-ways 5 --num-shots 1 --use-cuda --step-size 0.4 --batch-size 32 --num-workers 8 --num-epochs 600 --output-folder /path/to/results

    INFO:root:Saving configuration file in `/path/to/results/2021-10-18_160408/config.json
    Traceback (most recent call last):
      File "train.py", line 155, in <module>
        main(args)
      File "train.py", line 72, in main
        leave=False)
      File "/root/project/pytorch-maml/maml/metalearners/maml.py", line 172, in train
        for results in self.train_iter(dataloader, max_batches=max_batches):
      File "/root/project/pytorch-maml/maml/metalearners/maml.py", line 200, in train_iter
        outer_loss, results = self.get_outer_loss(batch)
      File "/root/project/pytorch-maml/maml/metalearners/maml.py", line 125, in get_outer_loss
        step_size=self.step_size, first_order=self.first_order)
      File "/root/project/pytorch-maml/maml/metalearners/maml.py", line 156, in adapt
        logits = self.model(inputs, params=params)
      File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
        result = self.forward(*input, **kwargs)
      File "/root/project/pytorch-maml/maml/model.py", line 60, in forward
        features = self.features(inputs, params=self.get_subdict(params, 'features'))
      File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
        result = self.forward(*input, **kwargs)
      File "/opt/conda/lib/python3.6/site-packages/torchmeta/modules/container.py", line 12, in forward
        input = module(input, params=self.get_subdict(params, name))
      File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
        result = self.forward(*input, **kwargs)
      File "/opt/conda/lib/python3.6/site-packages/torchmeta/modules/container.py", line 12, in forward
        input = module(input, params=self.get_subdict(params, name))
      File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
        result = self.forward(*input, **kwargs)
      File "/opt/conda/lib/python3.6/site-packages/torchmeta/modules/conv.py", line 25, in forward
        return self._conv_forward(input, params['weight'], bias)
    TypeError: _conv_forward() takes 3 positional arguments but 4 were given

I just copy&pasted your command and got this error. Can you help me with this?

Thank you

tristandeleu commented 2 years ago

Hi! What is your version of PyTorch and Torchmeta? Looking at that stacktrace, it seems like you are using the latest version of Torchmeta (1.8.0) with PyTorch < 1.9.

raidria commented 2 years ago

You're right. My PyTorch version is 1.8.0. Can I ask what Torchmeta version is recommended for PyTorch 1.8.0?

tristandeleu commented 2 years ago

Try Torchmeta v1.7.0, this version should be compatible with PyTorch 1.8.0.