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

AttributeError: 'NoneType' object has no attribute 'data' #2

Open
jrodriguezpuigvert opened this issue Mar 11, 2020 · 3 comments
Open

Comments

@jrodriguezpuigvert
Copy link

jrodriguezpuigvert commented Mar 11, 2020

Hello,
I am experimenting with VOGN and I am getting this error:

  File "/home/thom/anaconda3/envs/TUT_3/lib/python3.7/site-packages/torchsso-0.1.1-py3.7.egg/torchsso/optim/vi.py", line 215, in step
    grads = [p.grad.data for p in params]
  File "/home/thom/anaconda3/envs/TUT_3/lib/python3.7/site-packages/torchsso-0.1.1-py3.7.egg/torchsso/optim/vi.py", line 215, in <listcomp>
    grads = [p.grad.data for p in params]
AttributeError: 'NoneType' object has no attribute 'data'

Debugging I found that sometimes p.grad is None here
grads = [p.grad.data for p in params]

I didn't freeze any layer, I am learning from scratch.

Probably there is an error of my configuration. Do you have any hints about what could be the problem?

Here is the initialization of the optimizer:

model_optimizer = torchsso.optim.VIOptimizer(self.decoder,
                                                          dataset_size=300000,
                                                          num_mc_samples=10,
                                                          val_num_mc_samples=0,
                                                          lr=1e-4,
                                                          curv_type="Cov",
                                                          curv_shapes={
                                                              'Linear': 'Diag',
                                                              'Conv2d': 'Diag',
                                                              'BatchNorm1d': 'Diag',
                                                              'BatchNorm2d': 'Diag'
                                                          }, grad_ema_decay=0.1,
                                                          grad_ema_type="raw",
                                                          kl_weighting=1,
                                                          init_precision=8e-3,
                                                          prior_variance=1,
                                                          acc_steps=1,
                                                          curv_kwargs={
                                                              "damping": 0,
                                                              "ema_decay": 0.001
                                                          })
@kazukiosawa
Copy link
Collaborator

Thanks for sharing the error, and sorry for the late response.
Could you share (the part of) your training script so that I can reproduce your error?

As the p.grad is None according to your error message, I guess there's something wrong with the definition of the closure.

@jrodriguezpuigvert
Copy link
Author

I found already the bug. In the forward function, you must use all parameters of the model otherwise some p.grad will be None after calling backward. That could be a problem if anyone would like to use it for fine-tunning. Other optimizers like Adam are more flexible in that case.

@emtiyaz
Copy link
Contributor

emtiyaz commented Mar 17, 2020

Wonderful! Many thanks. Kazuki can fix this issue then and close it.

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

3 participants