Skip to content

Updated slices validations in the compiler #877

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 4 commits into from
May 22, 2025
Merged
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
16 changes: 13 additions & 3 deletions torch_ttnn/passes/lowering/to_tt_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import math
from torch._guards import detect_fake_mode
from torch._subclasses.fake_tensor import unset_fake_temporarily

from torch_ttnn.utils import (
GraphCleanup,
TtnnBfloat16,
Expand Down Expand Up @@ -709,11 +710,11 @@ def cast_bf16(target, other):
[step] = step or [1]
rank = len(input_size)

if step != 1 or dim >= rank:
if dim >= rank:
return None

# Check if no-op, just return the input tensor
if start == 0 and end >= input_size[dim]:
if start == 0 and end >= input_size[dim] and step == 1:
return tensor

slice_start = np.zeros(rank, dtype=int)
Expand All @@ -728,7 +729,15 @@ def cast_bf16(target, other):
slice_start[dim] = start
slice_end[dim] = end

return g.call_function(ttnn.slice, (tensor, [*slice_start], [*slice_end]))
if step != 1:
array_step = [1] * len(input_size)
array_step[dim] = step

kwargs = {
"slice_step": array_step if step != 1 else None,
}

return g.call_function(ttnn.slice, (tensor, [*slice_start], [*slice_end]), kwargs)

if node.target == torch.ops.aten.repeat.default:
tensor, sizes = args
Expand Down Expand Up @@ -1244,6 +1253,7 @@ def cast_bf16(target, other):
# slice_scatter could be concat([pre_slice_tensor, src_tensor, post_slice_tensor])
rank = len(tensor_shape)
[step] = step or [1]

if step != 1:
return None

Expand Down
Loading