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

How to solve "UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed" #5299

Closed
skylaugher opened this issue Dec 27, 2022 · 1 comment
Assignees

Comments

@skylaugher
Copy link

Describe the issue:

execute: CUDA_VISIBLE_DEVICES=0 python taylorfo_lightning_evaluator.py

some warning:

[2022-12-27 10:01:54] Update the indirect sparsity for the model.classifier.3
/home/user/miniconda3/envs/prune/lib/python3.8/site-packages/nni/compression/pytorch/speedup/infer_mask.py:275:
UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad attribute won't be populated during autograd.backward().
If you indeed want the .grad field to be populated for a non-leaf Tensor, use .retain_grad() on the non-leaf Tensor.
If you access the non-leaf Tensor by mistake, make sure you access the leaf Tensor instead. See github.com/pytorch/pytorch/pull/30531 for more informations.
(Triggered internally at aten/src/ATen/core/TensorBody.h:480.)
if isinstance(self.output, torch.Tensor) and self.output.grad is not None:

[2022-12-27 10:01:54] Update the indirect sparsity for the model.classifier.2
/home/user/miniconda3/envs/prune/lib/python3.8/site-packages/nni/compression/pytorch/speedup/compressor.py:305:
UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad attribute won't be populated during autograd.backward().
If you indeed want the .grad field to be populated for a non-leaf Tensor, use .retain_grad() on the non-leaf Tensor.
If you access the non-leaf Tensor by mistake, make sure you access the leaf Tensor instead. See github.com/pytorch/pytorch/pull/30531 for more informations.
(Triggered internally at aten/src/ATen/core/TensorBody.h:480.)
if last_output.grad is not None and tin.grad is not None:
/home/user/miniconda3/envs/prune/lib/python3.8/site-packages/nni/compression/pytorch/speedup/compressor.py:307:
UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad attribute won't be populated during autograd.backward().
If you indeed want the .grad field to be populated for a non-leaf Tensor, use .retain_grad() on the non-leaf Tensor.
If you access the non-leaf Tensor by mistake, make sure you access the leaf Tensor instead. See github.com/pytorch/pytorch/pull/30531 for more informations.
(Triggered internally at aten/src/ATen/core/TensorBody.h:480.)
elif last_output.grad is None:

Environment:ubuntu20.04

  • NNI version:2.10
  • Training service (local|remote|pai|aml|etc):local
  • Client OS:ubuntu20.04
  • Server OS (for remote mode only):
  • Python version:3.8.15
  • PyTorch/TensorFlow version:1.13.1+ cu116
  • Is conda/virtualenv/venv used?:conda
  • Is running in Docker?:no
  • pytorch-lightning: 1.8.6

Configuration:

  • Experiment config (remember to remove secrets!):
  • Search space:

Log message:

  • nnimanager.log:
  • dispatcher.log:
  • nnictl stdout and stderr:

How to reproduce it?:
execute: python taylorfo_lightning_evaluator.py

@super-dainiu super-dainiu mentioned this issue Feb 9, 2023
6 tasks
liuzhe-lz pushed a commit that referenced this issue Feb 10, 2023
@J-shang J-shang assigned super-dainiu and unassigned Louis-J Feb 20, 2023
@J-shang
Copy link
Contributor

J-shang commented Feb 20, 2023

@skylaugher thanks for your report, seems this issue have been fixed, you could have a try on master branch, if there still have more issues, feel free to tell us.

@J-shang J-shang closed this as completed Feb 20, 2023
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