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

Lower cummin op #8565

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Lower cummin op #8565

wants to merge 5 commits into from

Conversation

zyy-martin
Copy link
Contributor

Lower cummin op. Fixes #8231.

Reused most of the changes from #8491 except for using min and argmin.

@@ -289,6 +288,7 @@ def get_allowed_ops_map(
# AllowedOpInfoEntry('cosh'),
# AllowedOpInfoEntry('cov'),
# AllowedOpInfoEntry('cummax'),
# AllowedOpInfoEntry('cummin'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

@zyy-martin Thanks for your contributing.

Could you add a test for the op execution result's correctness?

Copy link
Collaborator

Choose a reason for hiding this comment

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

On this same note, could you add a test where dim is a 0-sized dimension?
Since this is using the same lowering as cummax, it could also have the same problems. ref: #8610

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has the same problem as cummax, as well as old ops such as cumprod and cumsum. I assume that was the reason those tests were excluded in the first place.

We can consider modify the op tests to have the option to exclude scalars/0-dimension values to cover other test cases. The C++ tests in this PR have verified the correctness though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now the SampleInput includes scalers by default here https://github.com/pytorch/pytorch/blob/dddf52b1b91d473e249829dad6c705c13624b35f/torch/testing/_internal/common_methods_invocations.py#L6942. I believe we can override the sample function in our test_ops.py to exclude the zero-dimension test cases. As for why the current implementation does not support scalar, i think we will need more investigation.

Copy link
Collaborator

@yaochengji yaochengji Jan 23, 2025

Choose a reason for hiding this comment

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

Although the test suite only support 0-sized dim, we can write simple tests from scratch to compare the result of torch/xla with native pytorch on cpu.

Copy link
Collaborator

@pgmoka pgmoka Jan 28, 2025

Choose a reason for hiding this comment

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

I agree with @yaochengji here to include a test for result correctness.

Otherwise, LGTM.

@@ -289,6 +288,7 @@ def get_allowed_ops_map(
# AllowedOpInfoEntry('cosh'),
# AllowedOpInfoEntry('cov'),
# AllowedOpInfoEntry('cummax'),
# AllowedOpInfoEntry('cummin'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Moving the discussion about 0-sized dimensions here, so as not to flood the other thread.
Do you think it would be hard to add support to 0-sized dimensions?

I'm asking for that, because I think this is a BC-breaking change. Before your PR, cummin would fallback to CUDA, which would work with 0-sized dimensions. Now, it crashes (#8610).

That said, since other operations (e.g. cummax) also have this problem, I think we could merge this and work out a solution to this issue afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think it would be hard to add support to 0-sized dimensions?

I am not sure, the error suggests it might have come from the XLA backend: https://github.com/openxla/xla/blob/e795171be9897e1356b1d98588e4fe784e2fc1bb/xla/service/shape_inference.cc#L202. will need more time to figure out a fix.

That said, since other operations (e.g. cummax) also have this problem, I think we could merge this and work out a solution to this issue afterwards.

Agree. It also applies to core ops like cumprod/cumsum which were lowered since the beginning of ptxla.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the XLA backend doesn't work with 0-sized dimensions, maybe we could catch this while tracing (since the shapes should be static). Then, return 2 0-sized tensors.

That said, I believe this could be left for a future PR (maybe also solving the other ops that have the same issue).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Is there anything else you'd want me to add in this PR?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also think it would be nice to have at least one test in the Python side, as @yaochengji suggested.
Other than that, LGTM.

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

Successfully merging this pull request may close these issues.

Lower cummin
5 participants