Skip to content

Commit 479e4e3

Browse files
gs-oliveperi044
authored andcommitted
chore/fix: Restructure Dynamo directory
- Add `common` directory which stores code common to both the compile and export path, to reduce code duplication and better organize the repository - Update necessary imports, promote the `_defaults` module to `torch_tensorrt.dynamo._defaults`
1 parent 324766f commit 479e4e3

20 files changed

+42
-26
lines changed

py/torch_tensorrt/dynamo/backend/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from torch_tensorrt.dynamo.backend.utils import prepare_inputs, prepare_device
1212
from torch_tensorrt.dynamo.backend.backends import torch_tensorrt_backend
13-
from torch_tensorrt.dynamo.backend._defaults import (
13+
from torch_tensorrt.dynamo._defaults import (
1414
PRECISION,
1515
DEBUG,
1616
WORKSPACE_SIZE,

py/torch_tensorrt/dynamo/backend/backends.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from functools import partial
55
import torch._dynamo as td
66

7-
from torch_tensorrt.dynamo.backend._settings import CompilationSettings
7+
from torch_tensorrt.dynamo.common import CompilationSettings
88
from torch_tensorrt.dynamo.backend.lowering._decompositions import (
99
get_decompositions,
1010
)

py/torch_tensorrt/dynamo/backend/conversion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import torch
33
import io
44
from torch_tensorrt.fx.trt_module import TRTModule
5-
from torch_tensorrt.dynamo.backend._settings import CompilationSettings
6-
from torch_tensorrt.dynamo.fx_ts_compat.fx2trt import (
5+
from torch_tensorrt.dynamo.common import (
6+
CompilationSettings,
77
InputTensorSpec,
88
TRTInterpreter,
99
)

py/torch_tensorrt/dynamo/backend/lowering/_partition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import torch
55

6-
from torch_tensorrt.dynamo.backend._defaults import MIN_BLOCK_SIZE
76
from torch_tensorrt.dynamo.backend.lowering import SUBSTITUTION_REGISTRY
7+
from torch_tensorrt.dynamo._defaults import MIN_BLOCK_SIZE
88
from torch.fx.passes.infra.partitioner import CapabilityBasedPartitioner, Partition
99
from torch.fx.graph_module import GraphModule
1010
from torch.fx.node import _get_qualified_name

py/torch_tensorrt/dynamo/backend/test/test_backend_compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from copy import deepcopy
55
from torch_tensorrt.dynamo import compile
66
from utils import lower_graph_testing
7-
from torch_tensorrt.dynamo.common_utils.test_utils import DECIMALS_OF_AGREEMENT
7+
from torch_tensorrt.dynamo.common.test_utils import DECIMALS_OF_AGREEMENT
88

99

1010
class TestTRTModuleNextCompilation(TestCase):

py/torch_tensorrt/dynamo/backend/test/test_decompositions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from torch.testing._internal.common_utils import run_tests, TestCase
44
import torch
55
from torch_tensorrt.dynamo import compile
6-
from torch_tensorrt.dynamo.common_utils.test_utils import DECIMALS_OF_AGREEMENT
6+
from torch_tensorrt.dynamo.common.test_utils import DECIMALS_OF_AGREEMENT
77

88

99
class TestLowering(TestCase):

py/torch_tensorrt/dynamo/backend/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
import logging
33
from dataclasses import replace, fields
44

5-
from torch_tensorrt.dynamo.backend._settings import CompilationSettings
5+
from torch_tensorrt.dynamo.common import CompilationSettings, use_python_runtime_parser
66
from typing import Any, Union, Sequence, Dict
77
from torch_tensorrt import _Input, Device
8-
from ..common_utils import use_python_runtime_parser
98

109

1110
logger = logging.getLogger(__name__)

py/torch_tensorrt/dynamo/common_utils/__init__.py renamed to py/torch_tensorrt/dynamo/common/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import logging
22
from typing import Optional
33

4+
from ._settings import CompilationSettings
5+
from .input_tensor_spec import InputTensorSpec
6+
from .fx2trt import TRTInterpreter, TRTInterpreterResult
7+
48

59
logger = logging.getLogger(__name__)
610

py/torch_tensorrt/dynamo/backend/_settings.py renamed to py/torch_tensorrt/dynamo/common/_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Optional, Sequence
33

44
from torch_tensorrt.fx.utils import LowerPrecision
5-
from torch_tensorrt.dynamo.backend._defaults import (
5+
from torch_tensorrt.dynamo._defaults import (
66
PRECISION,
77
DEBUG,
88
WORKSPACE_SIZE,

py/torch_tensorrt/dynamo/fx_ts_compat/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
NO_IMPLICIT_BATCH_DIM_SUPPORT,
77
tensorrt_converter,
88
)
9-
from .fx2trt import TRTInterpreter, TRTInterpreterResult # noqa
10-
from .input_tensor_spec import InputTensorSpec # noqa
119
from .lower_setting import LowerSetting # noqa
1210
from .lower import compile # usort: skip #noqa
1311

py/torch_tensorrt/dynamo/fx_ts_compat/lower.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,32 @@
1010
import torch_tensorrt.fx.tracer.dispatch_tracer.aten_tracer as aten_tracer
1111
from torch.fx.passes.splitter_base import SplitResult
1212

13-
from .fx2trt import TRTInterpreter, TRTInterpreterResult
13+
from torch_tensorrt.dynamo.common import (
14+
TRTInterpreter,
15+
TRTInterpreterResult,
16+
use_python_runtime_parser,
17+
)
1418
from .lower_setting import LowerSetting
1519
from .passes.lower_pass_manager_builder import LowerPassManagerBuilder
1620
from .passes.pass_utils import PassFunc, validate_inference
17-
from ..common_utils import use_python_runtime_parser
1821
from torch_tensorrt.fx.tools.timing_cache_utils import TimingCacheManager
1922
from torch_tensorrt.fx.tools.trt_splitter import TRTSplitter, TRTSplitterSetting
2023

2124
from torch_tensorrt.fx.tracer.acc_tracer import acc_tracer
2225
from torch_tensorrt.fx.trt_module import TRTModule
2326
from torch_tensorrt.fx.utils import LowerPrecision
2427
from torch_tensorrt._Device import Device
28+
from torch_tensorrt.dynamo._defaults import (
29+
PRECISION,
30+
DEBUG,
31+
WORKSPACE_SIZE,
32+
MIN_BLOCK_SIZE,
33+
PASS_THROUGH_BUILD_FAILURES,
34+
MAX_AUX_STREAMS,
35+
VERSION_COMPATIBLE,
36+
OPTIMIZATION_LEVEL,
37+
USE_PYTHON_RUNTIME,
38+
)
2539

2640
logger = logging.getLogger(__name__)
2741

@@ -35,24 +49,25 @@ def compile(
3549
disable_tf32=False,
3650
sparse_weights=False,
3751
enabled_precisions=set(),
38-
min_block_size: int = 3,
39-
workspace_size=0,
52+
min_block_size: int = MIN_BLOCK_SIZE,
53+
workspace_size=WORKSPACE_SIZE,
4054
dla_sram_size=1048576,
4155
dla_local_dram_size=1073741824,
4256
dla_global_dram_size=536870912,
4357
calibrator=None,
4458
truncate_long_and_double=False,
4559
require_full_compilation=False,
46-
debug=False,
60+
explicit_batch_dimension=False,
61+
debug=DEBUG,
4762
refit=False,
4863
timing_cache_prefix="",
4964
save_timing_cache=False,
5065
cuda_graph_batch_size=-1,
5166
is_aten=False,
52-
use_python_runtime=None,
53-
max_aux_streams=None,
54-
version_compatible=False,
55-
optimization_level=None,
67+
use_python_runtime=USE_PYTHON_RUNTIME,
68+
max_aux_streams=MAX_AUX_STREAMS,
69+
version_compatible=VERSION_COMPATIBLE,
70+
optimization_level=OPTIMIZATION_LEVEL,
5671
num_avg_timing_iters=1,
5772
torch_executed_ops=[],
5873
torch_executed_modules=[],

py/torch_tensorrt/dynamo/fx_ts_compat/lower_setting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from torch import nn
55
from torch.fx.passes.pass_manager import PassManager
66

7-
from .input_tensor_spec import InputTensorSpec
7+
from torch_tensorrt.dynamo.common import InputTensorSpec
88
from torch_tensorrt.fx.passes.lower_basic_pass import (
99
fuse_permute_linear,
1010
fuse_permute_matmul,

py/torch_tensorrt/dynamo/fx_ts_compat/passes/lower_pass_manager_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from torch.fx.passes.splitter_base import generate_inputs_for_submodules, SplitResult
1111
from torch_tensorrt.fx.utils import LowerPrecision
1212
from torch_tensorrt import _Input
13-
from ..input_tensor_spec import InputTensorSpec
13+
from torch_tensorrt.dynamo.common import InputTensorSpec
1414

1515
from ..lower_setting import LowerSetting
1616
from torch_tensorrt.fx.observer import Observer

py/torch_tensorrt/dynamo/fx_ts_compat/test/core/test_input_tensor_spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import torch
66
import torch_tensorrt
77
from torch.testing._internal.common_utils import run_tests, TestCase
8-
from torch_tensorrt.dynamo.fx_ts_compat import InputTensorSpec, LowerSetting
8+
from torch_tensorrt.dynamo.common import InputTensorSpec
99

1010

1111
class TestTRTModule(TestCase):

py/torch_tensorrt/dynamo/fx_ts_compat/tools/common_fx2trt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from torch.fx.passes import shape_prop
1414
from torch.fx.passes.infra.pass_base import PassResult
1515
from torch.testing._internal.common_utils import TestCase
16-
from torch_tensorrt.dynamo.fx_ts_compat import InputTensorSpec, TRTInterpreter
16+
from torch_tensorrt.dynamo.common import InputTensorSpec, TRTInterpreter
1717
from torch_tensorrt.fx.passes.lower_basic_pass_aten import (
1818
compose_bmm,
1919
compose_chunk,

py/torch_tensorrt/dynamo/test/test_dynamo_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from transformers import BertModel
1010

11-
from torch_tensorrt.dynamo.common_utils.test_utils import (
11+
from torch_tensorrt.dynamo.common.test_utils import (
1212
COSINE_THRESHOLD,
1313
cosine_similarity,
1414
)

0 commit comments

Comments
 (0)