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

Decompose arange.default to arange.start_step #99739

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions torch/_decomp/decompositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3356,6 +3356,36 @@ def nansum(self, dim=None, keepdim=False, *, dtype=None):
return aten.sum(torch.where(torch.isnan(self), 0, self), dim, keepdim, dtype=dtype)


@register_decomposition([aten.arange.default, aten.arange.out])
angelayi marked this conversation as resolved.
Show resolved Hide resolved
@out_wrapper()
def arange_default(
end: NumberType,
*,
dtype: Optional[torch.dtype] = None,
layout: torch.layout = torch.strided,
device: Optional[torch.device] = None,
pin_memory: bool = False,
):
return aten.arange.start_step(
0, end, 1, dtype=dtype, layout=layout, device=device, pin_memory=pin_memory
)


@register_decomposition([aten.arange.start])
angelayi marked this conversation as resolved.
Show resolved Hide resolved
def arange_start(
start: NumberType,
end: NumberType,
*,
dtype: Optional[torch.dtype] = None,
layout: torch.layout = torch.strided,
device: Optional[torch.device] = None,
pin_memory: bool = False,
):
return aten.arange.start_step(
start, end, 1, dtype=dtype, layout=layout, device=device, pin_memory=pin_memory
)


def register_inplace(aten_op, outplace_op):
@register_decomposition(aten_op)
def inplace_op(*args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion torch/_refs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4338,7 +4338,7 @@ def empty_like(
)


@register_decomposition(aten.arange)
@register_decomposition([aten.arange.start_step, aten.arange.start_out])
angelayi marked this conversation as resolved.
Show resolved Hide resolved
@out_wrapper()
def arange(
start: NumberType = 0,
Expand Down