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

Sinkhorn loss always renables gradient tracking #57

Open
mattcleigh opened this issue Mar 15, 2022 · 1 comment
Open

Sinkhorn loss always renables gradient tracking #57

mattcleigh opened this issue Mar 15, 2022 · 1 comment

Comments

@mattcleigh
Copy link

Essentially whenever I calculate the sinkhorn loss, pytorch's internal gradient tracking turns back on.

I believe this is to do with line 280 in geomloss/sinkhorn_divergence.py:
torch.autograd.set_grad_enabled(True)

This is obviously not an issue during training, but it is causing my memory to explode during inference or validation as the gradients are not cleared as there typically is no backwards pass.

I think this could be fixed by using something like:
cur_grad_status = torch.is_grad_enabled() ## At beginning of sinkhorn_loop()
torch.autograd.set_grad_enabled(cur_grad_status) ## At end of sinkhorn_loop()

jeanfeydy added a commit that referenced this issue Jun 18, 2022
@lopsided
Copy link

@jeanfeydy I just spent an hour or so coming to the same conclusion as to why I'm running out of memory during testing too. Looks like this PR would be a straight forward fix. Any chance you could merge it in? Thanks!

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