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

[bug] torch.polygamma inconsistent with scipy.special.polygamma for n >= 1 #55357

Closed
kshitij12345 opened this issue Apr 6, 2021 · 7 comments
Closed
Assignees
Labels
module: correctness (silent) issue that returns an incorrect result silently module: special Functions with no exact solutions, analogous to those in scipy.special triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@kshitij12345
Copy link
Collaborator

kshitij12345 commented Apr 6, 2021

n = 1

>>> t = torch.tensor([-1.])
>>> torch.polygamma(1, t)
tensor([1.2914e+15])
>>> scipy.special.polygamma(1, t.numpy())
array([inf], dtype=float32)

>>> t = torch.tensor([-501.])
>>> torch.polygamma(1, t)
tensor([2.0831e+09])
>>> scipy.special.polygamma(1, t.numpy())
array([inf], dtype=float32)

>>> t = torch.tensor([-float('inf')])
>>> torch.polygamma(1, t)
tensor([nan])
>>> scipy.special.polygamma(1, t.numpy())
array([inf], dtype=float32)
>>> 

n > 1

>>> t = torch.tensor([float('inf')])
>>> torch.polygamma(2, t)
tensor([nan])
>>> scipy.special.polygamma(2, t.numpy())
array([-0.], dtype=float32)
>>> torch.polygamma(3, t)
tensor([nan])
>>> scipy.special.polygamma(3, t.numpy())
array([0.], dtype=float32)
>>> torch.polygamma(4, t)
tensor([nan])
>>> scipy.special.polygamma(4, t.numpy())
array([-0.], dtype=float32)

cc @mruberry

@kshitij12345 kshitij12345 added the module: special Functions with no exact solutions, analogous to those in scipy.special label Apr 6, 2021
@kshitij12345 kshitij12345 self-assigned this Apr 6, 2021
@mruberry
Copy link
Collaborator

mruberry commented Apr 7, 2021

For the case where n=1, are we computing the correct values?

@kshitij12345
Copy link
Collaborator Author

I am planning to verify that and fix this issue in separate PR once #51966 is in

@mruberry
Copy link
Collaborator

mruberry commented Apr 7, 2021

Sounds good. Next question: for n > 2 are we only divergent for inf or other extremals, or also for real values?

@kshitij12345
Copy link
Collaborator Author

Only the extremals. (However on ROCM we are divergent on real values as well)

@mrshenli mrshenli added module: correctness (silent) issue that returns an incorrect result silently triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Apr 7, 2021
@kshitij12345 kshitij12345 reopened this Jul 28, 2021
@kshitij12345
Copy link
Collaborator Author

Reopening as #61641 was reverted.

@albanD
Copy link
Collaborator

albanD commented Oct 18, 2021

Reland happened

@albanD albanD closed this as completed Oct 18, 2021
@igm503
Copy link
Contributor

igm503 commented Aug 7, 2023

The inconsistency between torch and scipy (+ the actual value of polygamma_1 at negative integers) seems to remain as of the latest release of torch and the latest nightly.

@albanD Do you know why was this closed? Was there a decision to leave the current torch behavior in place, or is it just that no one remembered to reopen when the reland was reverted? (I'm assuming it was reverted, since I don't see any of the changes in the current codebase, and the polygamma behavior remains, at least for negative ints). Here's the commit I'm talking about: #62322

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: correctness (silent) issue that returns an incorrect result silently module: special Functions with no exact solutions, analogous to those in scipy.special triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants