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

fix: remove legacy conv converter #3343

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions py/torch_tensorrt/dynamo/conversion/aten_ops_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2454,6 +2454,8 @@ def aten_ops_le(
def conv_param_validator(
conv_node: Node, settings: Optional[CompilationSettings] = None
) -> bool:

# return True
chohk88 marked this conversation as resolved.
Show resolved Hide resolved
return conv_node.args[7] in ([0], [0, 0], [0, 0, 0])


Expand Down Expand Up @@ -2505,6 +2507,7 @@ def aten_ops_convolution(
stride=args[3],
padding=args[4],
dilation=args[5],
# output_padding=args[7],
groups=args[8],
)

Expand Down
108 changes: 54 additions & 54 deletions py/torch_tensorrt/fx/converters/aten_ops_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,60 +103,60 @@ def aten_ops_batch_norm(
)


@tensorrt_converter(torch.ops.aten.convolution.default)
def aten_ops_convolution(
network: TRTNetwork,
target: Target,
args: Tuple[Argument, ...],
kwargs: Dict[str, Argument],
name: str,
) -> Union[TRTTensor, Sequence[TRTTensor]]:
kwargs_new = {
"input": args[0],
"weight": args[1],
"bias": args[2],
"stride": args[3],
"padding": args[4],
"dilation": args[5],
"groups": args[8],
}
# we do not handle transposed.
if args[6] is True:
raise RuntimeError(f"Target {target} does not support `transposed=True` ")
# we do not handle output_padding.
if args[7] not in ([0], [0, 0], [0, 0, 0]):
raise RuntimeError(f"Target {target} has non-0 output_padding")

if len(kwargs_new["stride"]) == 1:
return convolution.convNd(
network,
target,
source_ir=SourceIR.ATEN,
name=name,
is_conv1d=True,
input_val=kwargs_new["input"],
weight=kwargs_new["weight"],
bias=kwargs_new["bias"],
stride=kwargs_new["stride"],
padding=kwargs_new["padding"],
dilation=kwargs_new["dilation"],
groups=kwargs_new["groups"],
)
else:
return convolution.convNd(
network,
target,
source_ir=SourceIR.ATEN,
name=name,
is_conv1d=False,
input_val=kwargs_new["input"],
weight=kwargs_new["weight"],
bias=kwargs_new["bias"],
stride=kwargs_new["stride"],
padding=kwargs_new["padding"],
dilation=kwargs_new["dilation"],
groups=kwargs_new["groups"],
)
# @tensorrt_converter(torch.ops.aten.convolution.default)
# def aten_ops_convolution(
# network: TRTNetwork,
# target: Target,
# args: Tuple[Argument, ...],
# kwargs: Dict[str, Argument],
# name: str,
chohk88 marked this conversation as resolved.
Show resolved Hide resolved
# ) -> Union[TRTTensor, Sequence[TRTTensor]]:
# kwargs_new = {
# "input": args[0],
# "weight": args[1],
# "bias": args[2],
# "stride": args[3],
# "padding": args[4],
# "dilation": args[5],
# "groups": args[8],
# }
# # we do not handle transposed.
# if args[6] is True:
# raise RuntimeError(f"Target {target} does not support `transposed=True` ")
# # we do not handle output_padding.
# if args[7] not in ([0], [0, 0], [0, 0, 0]):
# raise RuntimeError(f"Target {target} has non-0 output_padding")

# if len(kwargs_new["stride"]) == 1:
# return convolution.convNd(
# network,
# target,
# source_ir=SourceIR.ATEN,
# name=name,
# is_conv1d=True,
# input_val=kwargs_new["input"],
# weight=kwargs_new["weight"],
# bias=kwargs_new["bias"],
# stride=kwargs_new["stride"],
# padding=kwargs_new["padding"],
# dilation=kwargs_new["dilation"],
# groups=kwargs_new["groups"],
# )
# else:
# return convolution.convNd(
# network,
# target,
# source_ir=SourceIR.ATEN,
# name=name,
# is_conv1d=False,
# input_val=kwargs_new["input"],
# weight=kwargs_new["weight"],
# bias=kwargs_new["bias"],
# stride=kwargs_new["stride"],
# padding=kwargs_new["padding"],
# dilation=kwargs_new["dilation"],
# groups=kwargs_new["groups"],
# )


@tensorrt_converter(torch.ops.aten.div.default)
Expand Down
43 changes: 43 additions & 0 deletions run_aot_moria_2dunet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from monai.networks.nets import UNet
import torch
import torch_tensorrt

device = "cuda:0"

# Define the 2D U-Net model
model = UNet(
spatial_dims=2,
in_channels=3,
out_channels=2,
channels=(16, 32, 64, 128),
strides=(2, 2, 2),
num_res_units=2,
act="relu",
norm="batch",
dropout=0.1,
).to(device).half().eval()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you plan to add this script, examples/dynamo would be a better fit. Please refer to the existing examples if you want to add this model as a part of model zoo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this script only to test deconv with output_padding. I’ve created a separate issue with the reproduction steps and code, so I’ll remove this code from this PR.


# (batch size, channels, height, width)
input_tensor = torch.randn(1, 3, 256, 256, device=device).half()

backend = "torch_tensorrt"

# Compile the model with Torch-TensorRT backend
model = torch.compile(
model,
backend=backend,
options={
"use_python_runtime": False,
"enabled_precisions": {torch.float16},
"truncate_double": True,
"debug": True,
"min_block_size": 1,
},
dynamic=False,
)

# Perform inference with the compiled model
with torch.no_grad():
output = model(input_tensor)

print(output)
Loading