Skip to content

Index select empty tensor scalar tensor #2513

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

Merged
merged 16 commits into from
Mar 10, 2023

Conversation

jjsjann123
Copy link
Collaborator

Fixes index_select on empty/scalar indices. Issues found in python API.

  1. Our stack should support empty tensor (numel()==0), removed the check on that.
  2. Scalar tensor should be used in place of real Scalar with variable_name[0]. Add a quick patch for that.

void handle(const TensorView* tv) final {
// This allows us to access scalar tensor as if they are just scalar
TORCH_INTERNAL_ASSERT(tv->isZeroDim(), "TensorView can only be handled as scalar tensor");
code_ << ir_utils::varName(tv) << "[0]";
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This I think should be fine for scalar tensor. Seeking advises @naoyam @zasdfgbnm

Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of handling scalar tensor here, should we handle it during index lowering? In

std::unordered_map<IterDomain*, Val*> getIndexOverridingMap() const {
return {{getSelectAxis(), input(1)}};
}

We can check if input(1) is a tensor, if yes, create a kir::TensorIndex with index zero value.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It should be fine, but it doesn't seem quite right to me. I think all we need to do is to lower the index input in lower_index.cpp.

I'll work on cleaning it up. Can you add a test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure. Let me add a test on the python API~~ 🙇
Thanks for following up on this one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Pushed a commit. The Python test seems fine. Running the other tests.

Base automatically changed from index_select_cache_patch to devel February 24, 2023 06:00
@jjsjann123 jjsjann123 force-pushed the index_select_empty_tensor_scalar_tensor branch from 9f22351 to 6d17917 Compare February 24, 2023 07:24
@@ -743,6 +743,28 @@ def fusion_func(fd: FusionDefinition):
test_fn(0)
test_fn(1)

def test_index_select_scalar_indices(self):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@naoyam tests added and verified the failing after reverting changes in codegen.cpp. It's all yours now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, BTW, current branch I'm on is broken. You might want to revert the fouling commit for scatter 9340f80

@jjsjann123
Copy link
Collaborator Author

sorry, this one totally falls off my radar.
Do we have it patched in a separate PR? or is the problem still there?!?! @naoyam

Copy link
Collaborator

@naoyam naoyam left a comment

Choose a reason for hiding this comment

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

LGTM

@jjsjann123
Copy link
Collaborator Author

CI passed. merging this one

@jjsjann123 jjsjann123 merged commit 81adad8 into devel Mar 10, 2023
@jjsjann123 jjsjann123 deleted the index_select_empty_tensor_scalar_tensor branch March 10, 2023 22:55
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

Successfully merging this pull request may close these issues.

3 participants