ikostrikov / pytorch-meta-optimizer

A PyTorch implementation of Learning to learn by gradient descent by gradient descent
MIT License
312 stars 54 forks source link

Error when running main.py #3

Open ghost opened 7 years ago

ghost commented 7 years ago

Hi, I am using pytorch 0.2 and when I run the script, it generated following errors:

Traceback (most recent call last):
  File "main.py", line 142, in <module>
    main()
  File "main.py", line 116, in main
    meta_model = meta_optimizer.meta_update(model, loss.data)
  File "/home/rvl224/pytorch-meta-optimizer/meta_optimizer.py", line 135, in meta_update
    inputs = Variable(torch.cat((preprocess_gradients(flat_grads), flat_params.data, loss), 1))
  File "/home/rvl224/pytorch-meta-optimizer/utils.py", line 11, in preprocess_gradients
    return torch.cat((x1, x2), 1)
RuntimeError: dim out of range - got 1 but the tensor is only 1D

Is it because I am using a different version of pytorch?

ikostrikov commented 7 years ago

I think that it happened because they changed default parameters for some functions recently. Try to check all "sum", "mean" and similar functions and set keep dim to True.

RadZaeem commented 6 years ago

which pytorch version are you using?

Tried putting keepdim=True with pytorch 0.3, did not work.

cstsunfu commented 6 years ago

I got the same error. And the pytorch version is 0.2.

yunhunJang commented 6 years ago

Try this. return torch.cat((x1.view(-1,1), x2.view(-1,1), 1)

VeritasXu commented 6 years ago

I solved this problem, use return torch.cat((x1.view(-1,1), x2.view(-1,1)), 1) to update utils.py‘s output. And update meta_optimizer.py line135 to inputs = Variable(torch.cat((preprocess_gradients(flat_grads), flat_params.data.unsqueeze(1), loss.unsqueeze(1)), 1))