Skip to content

Conversation

@aayn
Copy link
Contributor

@aayn aayn commented Jun 27, 2020

Resolves #40018.

@dr-ci
Copy link

dr-ci bot commented Jun 27, 2020

💊 CI failures summary and remediations

As of commit c8b9af0 (more details on the Dr. CI page):


None of the CI failures appear to be your fault 💚



❄️ 1 failure tentatively classified as flaky

but reruns have not yet been triggered to confirm:

See CircleCI build pytorch_python_doc_push (1/1)

Step: "Doc Build and Push" (full log | diagnosis details | 🔁 rerun) ❄️

Jul 14 19:34:57 fatal: The remote end hung up unexpectedly
Jul 14 19:34:49 python_doc_push_script.sh: Invoked with docs/master master site dry_run 
Jul 14 19:34:49 ++ '[' -z site ']' 
Jul 14 19:34:49 ++ dry_run=false 
Jul 14 19:34:49 ++ '[' dry_run '!=' '' ']' 
Jul 14 19:34:49 ++ dry_run=true 
Jul 14 19:34:49 ++ echo 'install_path: docs/master  version: master  dry_run: true' 
Jul 14 19:34:49 ++ git clone https://github.com/pytorch/pytorch.github.io -b site 
Jul 14 19:34:49 install_path: docs/master  version: master  dry_run: true 
Jul 14 19:34:49 Cloning into 'pytorch.github.io'... 
Jul 14 19:34:57 error: RPC failed; curl 56 GnuTLS recv error (-54): Error in the pull function. 
Jul 14 19:34:57 fatal: The remote end hung up unexpectedly 
Jul 14 19:34:57 fatal: early EOF 
Jul 14 19:34:57 fatal: index-pack failed 

This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 54 times.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do I change this so that gcd gets invoked only with integral arguments?

@mruberry

Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need to add gcd or lcm to common methods invocations, since it's mostly intended for testing gradients, which you're not dealing with.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. In that case, I'm ready for a review.

@mruberry mruberry self-requested a review July 9, 2020 18:17
@aayn aayn changed the title [WIP] Implement gcd, lcm Implement gcd, lcm Jul 9, 2020
Copy link
Collaborator

Choose a reason for hiding this comment

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

Newline

Copy link
Collaborator

@mruberry mruberry Jul 9, 2020

Choose a reason for hiding this comment

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

What does this return if a is zero? If b is zero? If both are zero?

Copy link
Collaborator

Choose a reason for hiding this comment

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

(We should just add a comment explaining the behavior, since we can't return NaN for gcd(0, 0) here)

I suppose we could return an optional, but that seems like a lot.

Copy link
Collaborator

@mruberry mruberry Jul 9, 2020

Choose a reason for hiding this comment

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

Also you can use the same type traits trick as calc_erfinv (with is_integral instead of is_floating_point):

https://github.com/pytorch/pytorch/blob/40228ef2e59dced45b1b39819e57ea150e14b4ce/aten/src/ATen/native/Math.h#L66

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If a is 0, we return b (this is the case even when b is also 0). If b is 0 and a is nonzero then the while loop is executed once, b takes the value of a and is returned. In short, this will never return NaN, with gcd(a, 0) = a; gcd(0, b) = b; gcd(0, 0) = 0.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good. I just want to be clear about the (0, 0) behavior.

@mruberry mruberry self-requested a review July 9, 2020 21:52
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use:

#define C10_HOST_DEVICE __host__ __device__

Copy link
Contributor Author

@aayn aayn Jul 10, 2020

Choose a reason for hiding this comment

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

All other functions in that header (Math.cuh) file also don't use that macro. Should I change them too?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No. Old code that's working is best left undisturbed. Thank you for asking, though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the accumulate type ever different for the integer types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought accscalar_t stood for "accelerated scalar type" (as in accelerated with CUDA), my bad. I'll change that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's remove this for now. Named tensor support is on the back burner and these functions don't directly support named tensors since they're implementing a new kernel.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For the tolerances here, can they not all be 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you're right.

Copy link
Collaborator

Choose a reason for hiding this comment

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

"value"->"other" to be consistent with the documentation below?

Copy link
Collaborator

Choose a reason for hiding this comment

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

"-> Tensor", not "LongTensor"

Copy link
Collaborator

Choose a reason for hiding this comment

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

"LongTensor" -> "Tensor"

Copy link
Collaborator

Choose a reason for hiding this comment

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

"... of input and other."

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's be pedantic and be clear the function defines gcd(0, 0)=0.

Copy link
Collaborator

Choose a reason for hiding this comment

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

"Both input and other must have integer dtypes."

Copy link
Collaborator

Choose a reason for hiding this comment

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

See above notes.

Copy link
Collaborator

@mruberry mruberry Jul 9, 2020

Choose a reason for hiding this comment

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

In particular, what is lcm(a, 0)?

Should there be a test in test_torch.py explicitly for the gcd and lcm edge cases where one of the two inputs is zero and when both of the inputs are zero?

Copy link
Contributor Author

@aayn aayn Jul 10, 2020

Choose a reason for hiding this comment

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

Yeah, I think having explicit tests is a good idea (I tested these edge cases against the numpy implementation manually). And, lcm(a, 0) = 0 (which is also the case in the numpy implementation).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thought, doesn't this line already account for this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You would think so because our test suite is so confusing, but I think that function is for the Math tests and your tests are in the method test section. I'm actually about to overhaul all of this so it's not super important where you test the extremal values. You can probably just add lcm to the math test portion, but some people have struggled to fit their functions in there. You would do that by adding to torch_op_tests on line 19546.

Copy link
Collaborator

@mruberry mruberry left a comment

Choose a reason for hiding this comment

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

This is an excellent and well-written PR implementing two interesting functions. I've requested a few small changes for clarity.

@aayn
Copy link
Contributor Author

aayn commented Jul 10, 2020

Thanks! Do you know why the XLA tests are failing?

@JackCaoG
Copy link
Collaborator

Looking at the log Cannot access data pointer of Tensor that doesn't have storage It seems like test is trying to access the storage while xla does not have one. I will submit a pr to disable those tests.

@mruberry
Copy link
Collaborator

Looking at the log Cannot access data pointer of Tensor that doesn't have storage It seems like test is trying to access the storage while xla does not have one. I will submit a pr to disable those tests.

You can't disable them because they're not even in master yet ;)

It's not super surprising these new tests are failing on XLA. You can disable the test just on XLA by adding the @onlyOnCPUAndCUDA decorator to your tests. For the method tests you can see how decorators are applied to them in the test for qr, for example, where the skipCUDAIfNoMagma decorator is applied.

@ailzhang ailzhang requested a review from JackCaoG July 10, 2020 16:23
@aayn aayn requested a review from mruberry July 10, 2020 22:56
@aayn
Copy link
Contributor Author

aayn commented Jul 10, 2020

I've updated the PR: adding edge-case tests for gcd and lcm, and reflected other suggestions.

@aayn
Copy link
Contributor Author

aayn commented Jul 12, 2020

Checks have passed! @mruberry

@ailzhang ailzhang added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jul 13, 2020
Copy link
Collaborator

@mruberry mruberry left a comment

Choose a reason for hiding this comment

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

Awesome! Nice work, @aayn. Let me know if you need another project ;)

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@mruberry
Copy link
Collaborator

Sorry @aayn, looks like we got a small merge conflict at the last moment. Would you please resolve it and I'll restart the land process?

@aayn
Copy link
Contributor Author

aayn commented Jul 14, 2020

@mruberry Done. And yeah, I'd love to work on another project.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@mruberry
Copy link
Collaborator

@mruberry Done. And yeah, I'd love to work on another project.

Great! This should land soon.

If you'd like to implement a similar function with a twist there's divmod, something a little different is vdot, and something completely different is broadcast_to. Would any of those be interesting?

@facebook-github-bot
Copy link
Contributor

@mruberry merged this pull request in 200c343.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged open source triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implementing gcd, lcm

6 participants