-
Notifications
You must be signed in to change notification settings - Fork 7
Convert aten.slice.Tensor
to ttnn.slice
#179
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
base: main
Are you sure you want to change the base?
Conversation
I'm getting this error message. I test slicing like
|
I think if the tensor is tilized, you can't slice to non-tile aligned chunks |
Yeah try ROW major. You're slicing the outer collapsed dim of 1416=64 to 8, which is not tile-aligned. Try row major for this. |
@@ -118,7 +118,8 @@ def is_function_call(node) -> bool: | |||
ttnn.permute, | |||
# ttnn.repeat, in target_wrapper | |||
ttnn.concat, | |||
# ttnn.split, # ttnn has no split, remote the comment in the future when it has | |||
# ttnn.split, # ttnn has no split, remove the comment in the future when it has |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made #184 because the patch is useful on its own. After that, ttnn.split
becomes a valid conversion target.
if step != 1 or dim >= len(input_size): | ||
return None | ||
|
||
# NOTE(jdh8): is there a way to skip a no-op? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevinwuTT is there a way to skip an op if its a no-op?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning tensor
seems fine here. The following code will automatically replace the uses of the aten.split
op to point to the arg[0]
tensor, which effectively removes this op.
pytorch2.0_ttnn/torch_ttnn/passes/lowering/to_tt_pass.py
Lines 592 to 596 in a5ce2a6
if new_nodes: | |
node.replace_all_uses_with( | |
new_nodes[-1], | |
delete_user_cb=lambda node: node != new_nodes[-1], | |
) |
|
||
slice_start[dim] = start | ||
slice_end[dim] = min(end, input_size[dim]) | ||
slice_end -= 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats because torch is exclusive and ttnn is inclusive, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! This is exactly my intention, to convert exclusive ends to inclusive ends.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you use python style splices (eg) tensor[..., begin:end:step]) then it's exclusive. If you use ttnn.slice() it's inclusive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to refactor ttnn.slice to be exclusive
…ent pass This patch originates from #179 but is good on its own
…ent pass (#184) This patch originates from #179 but is good on its own Co-authored-by: Artem Yerofieiev <[email protected]>
return None | ||
|
||
if start == 0 and end >= input_size[dim]: | ||
return tensor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the difference in returning None vs tensor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None
marks failed conversion and leaves the graph as is. Returning a tenor lets the tenor replace the original op.
Running manually here Tests failed |
@jdh8 negative values are now supported with this PR So you can improve when this gets merged |
@jdh8 that PR is now merged. |
|
||
# NOTE(jdh8): is there a way to skip a no-op? | ||
# if start == 0 and end >= input_size[dim]: | ||
# return tensor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevinwuTT, I'd like to eliminate no-op slices, but this doesn't seem to be the right way.
From:
aten.slice.Tensor(tensor, dim, 0, INT64_MAX)
To:
tensor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can just return the tensor
as the new node after merging #180. RAUW of the return value is collectively handled.
pytorch2.0_ttnn/torch_ttnn/passes/lowering/to_tt_pass.py
Lines 595 to 601 in 9f80cdb
with g.inserting_before(node): | |
new_node = rewrite_node(node) | |
if new_node is not None: | |
node.replace_all_uses_with( | |
new_node, | |
delete_user_cb=lambda node: node != new_node, | |
) |
|
||
slice_start[dim] = start | ||
slice_end[dim] = min(end, input_size[dim]) | ||
slice_end -= 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! This is exactly my intention, to convert exclusive ends to inclusive ends.
@@ -118,7 +118,8 @@ def is_function_call(node) -> bool: | |||
ttnn.permute, | |||
# ttnn.repeat, in target_wrapper | |||
ttnn.concat, | |||
# ttnn.split, # ttnn has no split, remote the comment in the future when it has | |||
# ttnn.split, # ttnn has no split, remove the comment in the future when it has |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made #184 because the patch is useful on its own. After that, ttnn.split
becomes a valid conversion target.
return None | ||
|
||
if start == 0 and end >= input_size[dim]: | ||
return tensor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None
marks failed conversion and leaves the graph as is. Returning a tenor lets the tenor replace the original op.
Ticket
None
Problem description
input[:, :, start:end]
to 3aten.slice.Tensor
ops for each dimensions. I'd like to eliminate the outer two no-op slicing ops, but I need help from @kevinwuTT.ttnn.slice
are inclusiveWhat's changed
Convert
aten.slice.Tensor
tottnn.slice
in supported cases