Skip to content

add strong typing fix #3749

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
8 changes: 0 additions & 8 deletions py/torch_tensorrt/dynamo/conversion/impl/activation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from torch_tensorrt.dynamo._SourceIR import SourceIR
from torch_tensorrt.dynamo.conversion._ConversionContext import ConversionContext
from torch_tensorrt.fx.converters.converter_utils import (
mark_as_int8_layer,
set_layer_name,
)
from torch_tensorrt.fx.types import TRTTensor
Expand Down Expand Up @@ -37,11 +36,4 @@ def convert_activation(
layer.beta = beta
set_layer_name(layer, target, name, source_ir)

if (
not ctx.net.get_flag(trt.NetworkDefinitionCreationFlag.STRONGLY_TYPED)
and input_val.dynamic_range is not None
and dyn_range_fn is not None
):
dyn_range = dyn_range_fn(input_val.dynamic_range)
mark_as_int8_layer(layer, dyn_range)
return layer.get_output(0)
9 changes: 0 additions & 9 deletions py/torch_tensorrt/dynamo/conversion/impl/conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
to_torch,
to_trt_weights,
)
from torch_tensorrt.fx.converters.converter_utils import (
get_dyn_range,
mark_as_int8_layer,
)
from torch_tensorrt.fx.types import TRTTensor


Expand Down Expand Up @@ -172,11 +168,6 @@ def convNd(
if groups is not None:
conv_layer.num_groups = groups

# Handle quantization cases
if scale is not None and zero_point is not None:
# Assume the dtype of activation is torch.quint8
mark_as_int8_layer(conv_layer, get_dyn_range(scale, zero_point, torch.quint8))

result = conv_layer.get_output(0)

if is_conv1d:
Expand Down
7 changes: 0 additions & 7 deletions py/torch_tensorrt/dynamo/conversion/impl/deconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
to_trt_weights,
)
from torch_tensorrt.fx.converters.converter_utils import (
get_dyn_range,
mark_as_int8_layer,
set_layer_name,
)
from torch_tensorrt.fx.types import TRTTensor
Expand Down Expand Up @@ -174,11 +172,6 @@ def deconvNd(
deconv_layer.pre_padding = tuple(pre_padding_values)
deconv_layer.post_padding = tuple(post_padding_values)

# Handle quantization cases
if scale is not None and zero_point is not None:
# Assume the dtype of activation is torch.quint8
mark_as_int8_layer(deconv_layer, get_dyn_range(scale, zero_point, torch.quint8))

result = deconv_layer.get_output(0)

if is_deconv1d:
Expand Down
17 changes: 13 additions & 4 deletions py/torch_tensorrt/dynamo/conversion/impl/elementwise/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,19 @@ def pow(

lhs_dtype = None
rhs_dtype = None
if isinstance(lhs_val, int):
lhs_dtype = torch.int32
if isinstance(rhs_val, int):
rhs_dtype = torch.int32
if isinstance(lhs_val, (int, float)) and isinstance(rhs_val, (int, float)):
raise ValueError(
"Both lhs_val and rhs_val are int or float, at least one of them should be a tensor"
)
elif isinstance(lhs_val, (int, float)):
# At this point, rhs_val must be a Tensor since we checked both aren't scalars
assert isinstance(rhs_val, (TRTTensor, torch.Tensor))
lhs_dtype = rhs_val.dtype
elif isinstance(rhs_val, (int, float)):
# At this point, lhs_val must be a Tensor since we checked both aren't scalars
assert isinstance(lhs_val, (TRTTensor, torch.Tensor))
rhs_dtype = lhs_val.dtype

# POW operation supports only float32 and int8 inputs
lhs_val = get_trt_tensor(ctx, lhs_val, name + "_lhs_val", lhs_dtype)
rhs_val = get_trt_tensor(ctx, rhs_val, name + "_rhs_val", rhs_dtype)
Expand Down
Loading