FewShotLearning icon indicating copy to clipboard operation
FewShotLearning copied to clipboard

RuntimeError: One of the differentiated Variables appears to not have been used in the graph

Open dragen1860 opened this issue 7 years ago • 10 comments

Learner nParams: 32901 Traceback (most recent call last): File "main.py", line 38, in results = importlib.import_module(opt['metaLearner']).run(opt, data) File "/home/i/meta/FewShotLearning/model/lstm/train-lstm.py", line 121, in run opt['batchSize'][opt['nTrainShot']]) File "/home/i/conda/envs/py27/lib/python2.7/site-packages/torch/nn/modules/module.py", line 325, in call result = self.forward(*input, **kwargs) File "/home/i/meta/FewShotLearning/model/lstm/metaLearner.py", line 174, in forward torch.autograd.grad(loss, self.lstm2.parameters()) File "/home/i/conda/envs/py27/lib/python2.7/site-packages/torch/autograd/init.py", line 158, in grad inputs, only_inputs, allow_unused) RuntimeError: One of the differentiated Variables appears to not have been used in the graph

I run your code with py27 env. However the error occurs and I don't know what goes wrong?

dragen1860 avatar Dec 21 '17 02:12 dragen1860

Hi @dragen1860 @gitabcworld How did you solve this?

SinghGauravKumar avatar Jan 11 '18 18:01 SinghGauravKumar

Hi, I did n't solve this problem. Have you got any solution?

dragen1860 avatar Jan 12 '18 03:01 dragen1860

I change metaLearner.py, line 174 like following: torch.autograd.grad(loss, self.lstm2.parameters(), allow_unused=True, retain_graph=True)

It runs but Grads lstm + lstm2 print None . Pricision goes up. avg / total 0.21 0.22 0.19 7500

Not sure yet.

elviswf avatar Feb 04 '18 06:02 elviswf

@elviswf can it work now? how about your final precision?

dragen1860 avatar Feb 04 '18 06:02 dragen1860

@dragen1860 I just get the script run. I think you can get it run too. The final precision is just like above. Some params may need changed. I will try it in next week since I'm working on another project. If I get something new I will update this comment.

elviswf avatar Feb 04 '18 15:02 elviswf

@elviswf How is your latest progress?

dragen1860 avatar Feb 15 '18 05:02 dragen1860

Hi! I am sorry I could not work at this code for long. As @elviswf I am really busy working with other projects and I have not been able to dedicate more time to this project. So any help will be appreciated. I will try to do the changes @elviswf proposes and see if it solves the backprop problem as soon as possible.

gitabcworld avatar Feb 16 '18 18:02 gitabcworld

Have anyone solve this problem(One of the differentiated Variables appears to not have been used in the graph)?

Jorewang avatar Jul 29 '19 06:07 Jorewang

Have you encountered this problem? RuntimeError: CUDA out of memory. Tried to allocate 18.00 MiB (GPU 0; 8.00 GiB total capacity; 5.57 GiB already allocated; 10.05 MiB free; 607.43 MiB cached) This problem(One of the differentiated Variables appears to not have been used in the graph) can be solved by adding allow_unused=True.

lwzhaojun avatar Dec 17 '19 01:12 lwzhaojun

I change metaLearner.py, line 174 like following: torch.autograd.grad(loss, self.lstm2.parameters(), allow_unused=True, retain_graph=True)

It runs but Grads lstm + lstm2 print None . Pricision goes up. avg / total 0.21 0.22 0.19 7500

Not sure yet. Hello.Have you encountered this problem? RuntimeError: CUDA out of memory. Tried to allocate 18.00 MiB (GPU 0; 8.00 GiB total capacity; 5.57 GiB already allocated; 10.05 MiB free; 607.43 MiB cached) Isn't memory released? I tried reducing batch-size but it didn't work either. do you have any good advice? Can you help me? Grateful.friend.

lwzhaojun avatar Dec 17 '19 03:12 lwzhaojun