Skip to content

Drop contiguity info for size 1 dimensions for Python's define_tensor(sizes=..., strides=...)#2551

Closed
IvanYashchuk wants to merge 4 commits intocsarofeen:develfrom
IvanYashchuk:fix-2549
Closed

Drop contiguity info for size 1 dimensions for Python's define_tensor(sizes=..., strides=...)#2551
IvanYashchuk wants to merge 4 commits intocsarofeen:develfrom
IvanYashchuk:fix-2549

Conversation

@IvanYashchuk
Copy link
Copy Markdown
Collaborator

Fixes #2549.

@IvanYashchuk IvanYashchuk requested a review from zasdfgbnm March 7, 2023 18:23
" is not supported in nvFuser. Expected size > 0.");
if (sizes[i] == 1) {
maybe_symbolic_sizes.push_back(1);
contiguity.erase(contiguity.begin() + i);
Copy link
Copy Markdown
Collaborator

@zasdfgbnm zasdfgbnm Mar 7, 2023

Choose a reason for hiding this comment

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

Strange. Isn't this already handled by computeContiguity?

auto not_broadcast = [&](auto i) { return strides[i] != 0 && sizes[i] != 1; };

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Here, in maybe_symbolic_sizes, there's a specialization on size 1 dimensions independent of strides, while computeContiguity checks stride==0 for the dimension to be considered as the broadcast dimension.

Maybe that line should be changed to auto not_broadcast = [&](auto i) { return sizes[i] != 1; }; ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ahh, I see. I am OK with changing not_broadcast for now to unblock. But I think a better solution is to a some refactor on the python frontend to handle size N stride 0 dimension as expanded broadcast.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

#2561 handles size N stride 0. Should we move along with that instead of this PR?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, let's move with #2561!

Copy link
Copy Markdown
Collaborator

@zasdfgbnm zasdfgbnm left a comment

Choose a reason for hiding this comment

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

Thanks for fixing!

"compute_contiguity: Sizes and strides must have the same number of dimensions");
auto not_broadcast = [&](auto i) { return strides[i] != 0 && sizes[i] != 1; };
auto not_broadcast = [&](auto i) {
return (sizes[i] != 1) || (strides[i] != 0 && sizes[i] != 1);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Probably this should be sizes[i] != 1? test_compute_contiguity might fail if we do so, but we can skip that test for now.

@jjsjann123
Copy link
Copy Markdown
Collaborator

Not trying to block this PR.

think about a tensor torch.randn(5, 5).expand(-1).expand((5, 5, 5))

We still have issue with explicitly broadcast dimensions that I don't think is handled by this PR yet. With the API on TensorOpRecord, we can't properly pass correct contiguity information for an expanded dimension.
I'm trying to keep the contiguity information more comprehensible on the python side (not skipping contiguity for broadcast dims).

Wondering if you want to patch that in this PR as well? otherwise I'll start one once this merges.
cc'ing @IvanYashchuk

@IvanYashchuk
Copy link
Copy Markdown
Collaborator Author

Closing in favor of #2561

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.

broadcast_in_dim: The size of contiguity must equal to the number of non-broadcasting IterDomains

3 participants