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

full_like to full decomposition moving to decomposition.py for dynami… #3289

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions py/torch_tensorrt/dynamo/lowering/_decompositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,18 @@ def instance_norm_decomposition(
)


@register_torch_trt_decomposition(
torch.ops.aten.full_like, registry=TORCH_TRT_DECOMPOSITIONS
)
def full_like_decomposition(*args, **kwargs) -> torch.Tensor:
input = args[0]
shape = args[0].shape
fill_value = args[1]
kwargs["dtype"] = input.dtype
kwargs["device"] = to_torch_device(default_device())
return torch.full(shape, fill_value, dtype=kwargs["dtype"], device=kwargs["device"])


def get_decompositions(
enable_experimental_decompositions: bool = False,
) -> Dict[OpOverload, Callable[[Any], Any]]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from .remove_detach import remove_detach
from .remove_input_alias_fixing_clones import remove_input_alias_fixing_clones
from .repair_input_as_output import repair_input_as_output
from .replace_full_like_with_full import replace_full_like_with_full
from .replace_max_pool_with_indices import replace_max_pool_with_indices
from .view_to_reshape import view_to_reshape

Expand All @@ -27,7 +26,6 @@
lower_linear,
fuse_prims_broadcast,
replace_max_pool_with_indices,
replace_full_like_with_full,
view_to_reshape,
remove_assert_scalar,
accumulate_fp32_matmul,
Expand Down

This file was deleted.

8 changes: 5 additions & 3 deletions tests/py/dynamo/lowering/test_decompositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,13 @@ def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

def forward(self, x):
y = torch.full_like(x, 2.0)
return y
c = torch.ops.aten.add(x, x)
y = torch.ops.aten.full_like.default(c, 2)
d = y + c
return d

# Operations expected to be removed in the traced graph after decompositions
expected_ops = {torch.ops.aten.full.default}
expected_ops = {torch.ops.aten.add.Tensor}
unexpected_ops = {torch.ops.aten.full_like.default}

inputs = [torch.randn(3, 3, dtype=torch.float32).cuda()]
Expand Down
Loading