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

Add a code comment about torch._check_is_size in tensor_split #125292

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions torch/_decomp/decompositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,15 @@ def tensor_split_tensor_indices_or_sections_py_impl(
return self.tensor_split(sections, dim)
else:
indices = [i.item() for i in tensor_indices_or_sections]
# WARNING: Tempted to torch._check_is_size on the indices here? You
# can't: tensor_split works with negative values in indices:
#
# >>> torch.tensor_split(torch.randn(10), torch.tensor([-5, 5]))
# (tensor([ 0.3540, 2.1074, -0.8507, 1.1639, 0.3055]), tensor([]),
# tensor([-0.4285, 1.0692, -0.1776, 0.9362, 1.6143]))
#
# Sorry, I don't make the rules. Explicitly do the item call in user
Copy link
Contributor

Choose a reason for hiding this comment

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

😆 😢

# code if you KNOW that they are non-negative.
return self.tensor_split(indices, dim)


Expand Down
Loading