Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loss don't go down when finetune and about requires_grad option in backward() #21

Open
graykode opened this issue Jan 28, 2019 · 3 comments

Comments

@graykode
Copy link

I tried finetuning with SS-Youtube dataset on examples/finetune_youtube_last. but There are some minor errors in there :(...
First. The loss are not decrease well about each epochs when finetune using SS-Youtube. I tried training as setting original val loss 0.01, but Each epochs loss almost same

1 Epoch val acc 62.54 val loss 0.67718
2 Epoch val acc 62.54 val loss 0.67718
3 Epoch val acc 62.54 val loss 0.67718
...

Second. In finetune.py, There is error element 0 of tensors does not require grad and does not have a grad_fn if i not include loss = Variable(loss, requires_grad=True) in code.

@graykode graykode changed the title loss don't go down when finetune and about requires_grad option loss don't go down when finetune and about requires_grad option in backward() Jan 28, 2019
@vladimirG123
Copy link

vladimirG123 commented Feb 6, 2019

Same thing. But in TF version everything works fine

@tomgun132
Copy link

tomgun132 commented Jul 18, 2019

I just started to use Torchmoji and had the same problem.
I tried adding loss = Variable(loss, requires_grad=True) like OP but the loss doesn't improve. Then I looked into the root of the problem why the element 0 of tensors does not require grad and does not have a grad_fn error appears. I noticed in model_def line 249-250 the code tries to get the tensor data from what was supposed to be Variable (if return_tensor: outputs = outputs.data). However since Variable has long been deprecated, I figured that this might be the one that removes the grad_fn from loss so I removed those lines of code then the loss starts improving when I finetuned the model.

@Ling312
Copy link

Ling312 commented Jul 23, 2019

I just started to use Torchmoji and had the same problem.
I tried adding loss = Variable(loss, requires_grad=True) like OP but the loss doesn't improve. Then I looked into the root of the problem why the element 0 of tensors does not require grad and does not have a grad_fn error appears. I noticed in model_def line 249-250 the code tries to get the tensor data from what was supposed to be Variable (if return_tensor: outputs = outputs.data). However since Variable has long been deprecated, I figured that this might be the one that removes the grad_fn from loss so I removed those lines of code then the loss starts improving when I finetuned the model.

works for me, I think it's caused by the different version of pytorch (Variables is deprecated from version 0.4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants