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

Error of assert xt.grad is not None #2

Closed
jiajinghu19 opened this issue Jan 25, 2024 · 1 comment
Closed

Error of assert xt.grad is not None #2

jiajinghu19 opened this issue Jan 25, 2024 · 1 comment

Comments

@jiajinghu19
Copy link

jiajinghu19 commented Jan 25, 2024

Hi, I am trying to evaluate on tsp100 data, and have this error saying

File "/T2TCO/diffusion/pl_tsp_model.py", line 247, in test_step
    g_xt = self.guided_categorical_denoise_step(points, g_xt, t1, device, edge_index, target_t=t2)
  File "/T2TCO/diffusion/pl_tsp_model.py", line 91, in guided_categorical_denoise_step
    assert xt.grad is not None

The function has this assert statement to assert xt has gradient, but the input g_xt is converted to long type in line 238, and long type tensor cannot have gradient. Can someone help me with this? Thanks

(g_xt > 0).long()

@yangco-le
Copy link
Collaborator

Hi, @jiajinghu19

Please kindly note that this tensor has been converted to float format in line 61 xt = xt.float(). The gradient here is estimated based on x_t. This issue is likely caused by the incorrect version of PyTorch Lightning. PyTorch Lightning itself does not support gradient computation during the testing phase. Therefore, we added two lines of code, torch.set_grad_enabled(True) and with torch.inference_mode(False):, to enable gradient computation. If you still encounter gradient computation issues, please check the version of the libraries or refer to relevant solutions for the version you are using, such as those available at Lightning-AI/pytorch-lightning#13948.

Should you have any further inquiries, please feel free to reach out. By the way, kindly mention me in the comments (@ me) so that I can promptly receive notifications and address your question.

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

2 participants