Skip to content

Commit

Permalink
full_like to full decomposition moving to decomposition.py for dynami…
Browse files Browse the repository at this point in the history
…c case
  • Loading branch information
apbose committed Nov 20, 2024
1 parent 3e8d735 commit 1965a87
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 68 deletions.
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

0 comments on commit 1965a87

Please sign in to comment.