Skip to content

[fx2trt] Engineholder feature improvement, test fixes #1143

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

Merged
merged 2 commits into from
Jun 23, 2022
Merged
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
command: |
pip3 install nvidia-pyindex
pip3 install nvidia-tensorrt==8.2.4.2
pip3 install --pre torch==1.13.0.dev20220618 torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cu113
pip3 install --pre torch==1.13.0.dev20220621 torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cu113
pip3 install pytest parameterized expecttest
# install torch_tensorrt
mv WORKSPACE.ci WORKSPACE
Expand Down
10 changes: 6 additions & 4 deletions py/torch_tensorrt/fx/converters/acc_ops_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ def acc_ops_conv1d(
kernel=weight,
bias=bias,
)
padding = kwargs["padding"]
padding = padding + (0,)
stride = extend_attr_to_tuple(kwargs["stride"], 1)
dilation = extend_attr_to_tuple(kwargs["dilation"], 1)
# expand params to 2d for computation
padding = list(kwargs["padding"])
padding.append(0)
stride = extend_attr_to_tuple(kwargs["stride"], 2)
dilation = extend_attr_to_tuple(kwargs["dilation"], 2)

set_layer_name(layer, target, name)
layer.stride_nd = stride
layer.padding_nd = padding
Expand Down
6 changes: 3 additions & 3 deletions py/torch_tensorrt/fx/converters/convolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def common_conv(network, mod, dimension, input_val, layer_name, is_quantized):
unsqueeze_layer.name = f"{layer_name}_unsqueeze"
input_val = unsqueeze_layer.get_output(0)

padding = padding + (0,)
kernel = np.expand_dims(kernel, -1)
kernel_size = kernel.shape[2:]
if bias is not None:
bias = bias[None]
# bias = np.expand_dims(bias, -1)

stride = (stride[0], 1)
padding = (padding[0], 0)
dilation = (dilation[0], 1)
layer = network.add_convolution_nd(
input=input_val,
num_output_maps=mod.out_channels,
Expand Down
7 changes: 5 additions & 2 deletions py/torch_tensorrt/fx/input_tensor_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def from_tensors(cls, tensors: Sequence[torch.Tensor]) -> List["InputTensorSpec"

@classmethod
def from_tensors_with_dynamic_batch_size(
cls, tensors: Sequence[torch.Tensor], batch_size_range: Tuple[int, int, int]
cls,
tensors: Sequence[torch.Tensor],
batch_size_range: Tuple[int, int, int],
opt_profile_replica: int = 1,
) -> List["InputTensorSpec"]:
"""
Produce a list of InputTenosrSpec named tuples which would contain
Expand All @@ -93,7 +96,7 @@ def from_tensors_with_dynamic_batch_size(
), f"The {i}th tensor (shape: {tensor.shape}) doesn't have the correct batch size: {batch_size}."
shape = list(tensor.shape)
shape[0] = -1
shape_ranges: List[ShapeRange] = [tuple(tuple([bs] + shape[1:]) for bs in batch_size_range)] # type: ignore[list-item]
shape_ranges: List[ShapeRange] = [tuple(tuple([bs] + shape[1:]) for bs in batch_size_range)] * opt_profile_replica # type: ignore[list-item]
input_specs.append(
cls(tuple(shape), tensor.dtype, tensor.device, shape_ranges)
)
Expand Down
1 change: 1 addition & 0 deletions py/torch_tensorrt/fx/lower.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def __call__(self, mod, input, split_name) -> TRTInterpreterResult:
self.lower_setting.max_batch_size,
self.lower_setting.max_batch_size,
),
self.lower_setting.opt_profile_replica,
)
if self.lower_setting.explicit_batch_dimension
else InputTensorSpec.from_tensors(input)
Expand Down
3 changes: 3 additions & 0 deletions py/torch_tensorrt/fx/lower_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class LowerSetting(LowerSettingBasic):
how presets are applied. Refer to
`caffe2.torch.fb.model_transform.fx2trt.presets.ESUHMLowererPreset` on how
to add a preset.
opt_profile_replica (int): the number of opt profile set for TensorRT engine, this field is
only used by explicit batch dim with dynamic shape mode.
"""

input_specs: List[InputTensorSpec] = dc.field(default_factory=list)
Expand All @@ -86,3 +88,4 @@ class LowerSetting(LowerSettingBasic):
save_timing_cache: bool = False
cuda_graph_batch_size: int = -1
preset_lowerer: str = ""
opt_profile_replica: int = 1
4 changes: 1 addition & 3 deletions py/torch_tensorrt/fx/passes/lower_basic_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ def skip_folding_quant_dequant(node: torch.fx.Node):
return True
return False

const_split_mod = split_const_subgraphs(
traced_mod, skip_folding_quant_dequant, device_for_folded_attrs="cuda"
)
const_split_mod = split_const_subgraphs(traced_mod, skip_folding_quant_dequant)
const_split_mod.run_folding()
return const_split_mod

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import torch
import torch_tensorrt.fx.tracer.acc_tracer.acc_ops as acc_ops
from parameterized import parameterized
from torch.testing._internal.common_fx2trt import AccTestCase, InputTensorSpec
from torch.testing._internal.common_utils import run_tests
from torch_tensorrt.fx.tools.common_fx2trt import AccTestCase, InputTensorSpec


class TestAdaptiveAvgPoolConverter(AccTestCase):
Expand Down
2 changes: 1 addition & 1 deletion py/torch_tensorrt/fx/test/converters/acc_op/test_any.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import torch.nn as nn
import torch_tensorrt.fx.tracer.acc_tracer.acc_ops as acc_ops
from parameterized import parameterized
from torch.testing._internal.common_fx2trt import AccTestCase
from torch.testing._internal.common_utils import run_tests
from torch_tensorrt.fx.tools.common_fx2trt import AccTestCase


class TestAnyConverters(AccTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import torch.nn as nn
import torch_tensorrt.fx.tracer.acc_tracer.acc_ops as acc_ops
from parameterized import parameterized
from torch.testing._internal.common_fx2trt import AccTestCase
from torch.testing._internal.common_utils import run_tests
from torch_tensorrt.fx.tools.common_fx2trt import AccTestCase


class TestConverter(AccTestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import torch
import torch_tensorrt.fx.tracer.acc_tracer.acc_ops as acc_ops
from parameterized import param, parameterized
from torch.testing._internal.common_fx2trt import AccTestCase
from torch.testing._internal.common_utils import run_tests
from torch_tensorrt.fx.tools.common_fx2trt import AccTestCase


class TestAvgPoolConverter(AccTestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch
import torch_tensorrt.fx.tracer.acc_tracer.acc_ops as acc_ops
from torch.testing._internal.common_fx2trt import AccTestCase, InputTensorSpec
from torch.testing._internal.common_utils import run_tests
from torch_tensorrt.fx.tools.common_fx2trt import AccTestCase, InputTensorSpec


class TestBatchNormConverter(AccTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import torch_tensorrt.fx.tracer.acc_tracer.acc_ops as acc_ops
from parameterized import parameterized
from torch.testing._internal.common_fx2trt import AccTestCase, InputTensorSpec
from torch.testing._internal.common_utils import run_tests
from torch_tensorrt.fx.tools.common_fx2trt import AccTestCase, InputTensorSpec

NEED_TEST_BOTH_CONSTANTS_CASE = True

Expand Down
2 changes: 1 addition & 1 deletion py/torch_tensorrt/fx/test/converters/acc_op/test_cat.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import torch
import torch.nn as nn
import torch_tensorrt.fx.tracer.acc_tracer.acc_ops as acc_ops
from torch.testing._internal.common_fx2trt import AccTestCase, InputTensorSpec
from torch.testing._internal.common_utils import run_tests
from torch_tensorrt.fx.tools.common_fx2trt import AccTestCase, InputTensorSpec


class TestCatConverter(AccTestCase):
Expand Down
2 changes: 1 addition & 1 deletion py/torch_tensorrt/fx/test/converters/acc_op/test_chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import torch.nn as nn
import torch_tensorrt.fx.tracer.acc_tracer.acc_ops as acc_ops
from parameterized import parameterized
from torch.testing._internal.common_fx2trt import AccTestCase, InputTensorSpec
from torch.testing._internal.common_utils import run_tests
from torch_tensorrt.fx.tools.common_fx2trt import AccTestCase, InputTensorSpec


class TestChunkConverter(AccTestCase):
Expand Down
2 changes: 1 addition & 1 deletion py/torch_tensorrt/fx/test/converters/acc_op/test_clamp.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import torch
import torch_tensorrt.fx.tracer.acc_tracer.acc_ops as acc_ops
from parameterized import param, parameterized
from torch.testing._internal.common_fx2trt import AccTestCase
from torch.testing._internal.common_utils import run_tests
from torch_tensorrt.fx.tools.common_fx2trt import AccTestCase


class TestClampConverter(AccTestCase):
Expand Down
Loading