Skip to content

Conversation

tringwald
Copy link
Collaborator

This PR improves the implementation of torch.log1p for complex inputs as mentioned in issue #107022. The new implementation is based on the insights provided in numpy/numpy#22611 (comment).

cc @lezcano

@pytorch-bot
Copy link

pytorch-bot bot commented Aug 13, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/107100

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit ec662a9 with merge base 10ce16b (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 13, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@lezcano lezcano added the release notes: complex release notes category label Aug 13, 2023
Copy link
Collaborator

@lezcano lezcano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function is also in c10_complex_math, you don't need to specify the namespace, but fair enough.

Thank you for the quick fix! Feel free to merge the PR yourself via @pytorchbot

@lezcano lezcano added the ciflow/trunk Trigger trunk jobs on your pull request label Aug 13, 2023
@tringwald
Copy link
Collaborator Author

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 4 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@lezcano
Copy link
Collaborator

lezcano commented Aug 14, 2023

So, as discussed in numpy/numpy#22611 (comment), the implementation in mac seems to be failing. The relative error is small (6e-6) but higher than the tolerance of 1e-6.
Given that this operation is meant to be used as a more precise version of log, I think we should fix it. I propose you resort to the previous implementation (which was passing the tests) for mac via compile flags.

@lezcano
Copy link
Collaborator

lezcano commented Aug 14, 2023

And could you also leave a comment as to why we're doing that.

@tringwald
Copy link
Collaborator Author

I added a fallback to the old version in case __APPLE__ or __MACOSX is defined. I also removed the namespace specifier for c10_complex_math::log.

@lezcano
Copy link
Collaborator

lezcano commented Aug 14, 2023

Great, thank you for the contribution!

@lezcano
Copy link
Collaborator

lezcano commented Aug 14, 2023

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 2 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@lezcano
Copy link
Collaborator

lezcano commented Aug 14, 2023

The failures seem real (although CI is not particularly helpful). Could you look into those?

@tringwald
Copy link
Collaborator Author

There seems to be a problem with building LogcumsumexpKernel.cu. I'll have a look.

@tringwald
Copy link
Collaborator Author

So far, I've not been able to reproduce the build errors on my local setup. I've checked the failing linux-jammy and linux-bionic builds with both gcc and clang inside of Docker.
Given the Killed output in all of the failing builds, is the build server maybe running out of memory?

@lezcano
Copy link
Collaborator

lezcano commented Aug 15, 2023

It could be. I remember that thrust::log is a particularly heavy operation.
cc @peterbell10 @malfet perhaps they know what could be going on here?

} else if (u - T(1) == z) {
return log(u);
} else {
return log(u) * (z / (u - T(1)));
Copy link
Collaborator

@peterbell10 peterbell10 Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly these complex functions are far more costly than the real counterparts and it looks like the build is running out of memory when compiling them. A shot in the dark, there might be a compile time improvement by only calling log(u) once:

auto log_u = log(u);
if (u - T(1) != z) {
    return log_u * (z / (u - T(1)));
}
return log_u;

@lezcano
Copy link
Collaborator

lezcano commented Aug 15, 2023

All those failures seem unrelated. Can you rebase off viable/strict (it's a branch that should have CI green... albeit sometimes it doesn't, but yeah) to clean all these failures?

@peterbell10
Copy link
Collaborator

@pytorchbot rebase

@pytorchmergebot
Copy link
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot
Copy link
Collaborator

Successfully rebased improved-complex-log1p onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout improved-complex-log1p && git pull --rebase)

@lezcano
Copy link
Collaborator

lezcano commented Aug 16, 2023

Há! That did it! nvcc is sometimes a bit thick...

@lezcano
Copy link
Collaborator

lezcano commented Aug 16, 2023

@pytorchbot merge -i

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: trunk / win-vs2019-cpu-py3 / test (default, 3, 3, windows.4xlarge.nonephemeral)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

summerdo pushed a commit to summerdo/pytorch that referenced this pull request Aug 17, 2023
This PR improves the implementation of `torch.log1p` for complex inputs as mentioned in issue pytorch#107022. The new implementation is based on the insights provided in numpy/numpy#22611 (comment).

Pull Request resolved: pytorch#107100
Approved by: https://github.com/lezcano
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged open source release notes: complex release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants