Skip to content

Commit 2c92ec0

Browse files
committed
Fixed the comments
1 parent 27ddf38 commit 2c92ec0

File tree

6 files changed

+18
-14
lines changed

6 files changed

+18
-14
lines changed

py/torch_tensorrt/dynamo/_compiler.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def cross_compile_for_windows(
6565
Set[Union[torch.dtype, dtype]], Tuple[Union[torch.dtype, dtype]]
6666
] = _defaults.ENABLED_PRECISIONS,
6767
engine_capability: EngineCapability = _defaults.ENGINE_CAPABILITY,
68-
debug: bool = False,
6968
num_avg_timing_iters: int = _defaults.NUM_AVG_TIMING_ITERS,
7069
workspace_size: int = _defaults.WORKSPACE_SIZE,
7170
dla_sram_size: int = _defaults.DLA_SRAM_SIZE,
@@ -185,7 +184,7 @@ def cross_compile_for_windows(
185184
f"Cross compile for windows is only supported on x86-64 Linux architecture, current platform: {platform.system()=}, {platform.architecture()[0]=}"
186185
)
187186

188-
if debug:
187+
if kwargs.get("debug", False):
189188
warnings.warn(
190189
"`debug` is deprecated. Please use `torch_tensorrt.dynamo.Debugger` to configure debugging options.",
191190
DeprecationWarning,
@@ -391,7 +390,6 @@ def compile(
391390
Set[Union[torch.dtype, dtype]], Tuple[Union[torch.dtype, dtype]]
392391
] = _defaults.ENABLED_PRECISIONS,
393392
engine_capability: EngineCapability = _defaults.ENGINE_CAPABILITY,
394-
debug: bool = False,
395393
num_avg_timing_iters: int = _defaults.NUM_AVG_TIMING_ITERS,
396394
workspace_size: int = _defaults.WORKSPACE_SIZE,
397395
dla_sram_size: int = _defaults.DLA_SRAM_SIZE,
@@ -508,7 +506,7 @@ def compile(
508506
torch.fx.GraphModule: Compiled FX Module, when run it will execute via TensorRT
509507
"""
510508

511-
if debug:
509+
if kwargs.get("debug", False):
512510
warnings.warn(
513511
"`debug` is deprecated. Please use `torch_tensorrt.dynamo.Debugger` for debugging functionality",
514512
DeprecationWarning,
@@ -925,7 +923,8 @@ def contains_metadata(gm: torch.fx.GraphModule) -> bool:
925923
trt_module.enable_profiling()
926924
else:
927925
path = os.path.join(
928-
_debugger_settings.logging_dir, "engine_visualization"
926+
_debugger_settings.logging_dir,
927+
"engine_visualization_profile",
929928
)
930929
os.makedirs(path, exist_ok=True)
931930
trt_module.enable_profiling(
@@ -969,7 +968,6 @@ def convert_exported_program_to_serialized_trt_engine(
969968
enabled_precisions: (
970969
Set[torch.dtype | dtype] | Tuple[torch.dtype | dtype]
971970
) = _defaults.ENABLED_PRECISIONS,
972-
debug: bool = False,
973971
assume_dynamic_shape_support: bool = _defaults.ASSUME_DYNAMIC_SHAPE_SUPPORT,
974972
workspace_size: int = _defaults.WORKSPACE_SIZE,
975973
min_block_size: int = _defaults.MIN_BLOCK_SIZE,
@@ -1070,7 +1068,7 @@ def convert_exported_program_to_serialized_trt_engine(
10701068
Returns:
10711069
bytes: Serialized TensorRT engine, can either be saved to a file or deserialized via TensorRT APIs
10721070
"""
1073-
if debug:
1071+
if kwargs.get("debug", False):
10741072
warnings.warn(
10751073
"`debug` is deprecated. Please use `torch_tensorrt.dynamo.Debugger` to configure debugging options.",
10761074
DeprecationWarning,
@@ -1159,7 +1157,6 @@ def convert_exported_program_to_serialized_trt_engine(
11591157
compilation_options = {
11601158
"assume_dynamic_shape_support": assume_dynamic_shape_support,
11611159
"enabled_precisions": enabled_precisions,
1162-
"debug": debug,
11631160
"workspace_size": workspace_size,
11641161
"min_block_size": min_block_size,
11651162
"torch_executed_ops": torch_executed_ops,

py/torch_tensorrt/dynamo/_defaults.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
TILING_OPTIMIZATION_LEVEL = "none"
4949
L2_LIMIT_FOR_TILING = -1
5050
USE_DISTRIBUTED_MODE_TRACE = False
51+
DEBUG_LOGGING_DIR = os.path.join(tempfile.gettempdir(), "torch_tensorrt/debug_logs")
5152

5253

5354
def default_device() -> Device:

py/torch_tensorrt/dynamo/debug/_Debugger.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from unittest import mock
99

1010
import torch
11+
from torch_tensorrt.dynamo._defaults import DEBUG_LOGGING_DIR
1112
from torch_tensorrt.dynamo.debug._DebuggerConfig import DebuggerConfig
1213
from torch_tensorrt.dynamo.debug._supports_debugger import (
1314
_DEBUG_ENABLED_CLS,
@@ -32,7 +33,7 @@ def __init__(
3233
save_engine_profile: bool = False,
3334
profile_format: str = "perfetto",
3435
engine_builder_monitor: bool = True,
35-
logging_dir: str = tempfile.gettempdir(),
36+
logging_dir: str = DEBUG_LOGGING_DIR,
3637
save_layer_info: bool = False,
3738
):
3839
"""Initialize a debugger for TensorRT conversion.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import tempfile
21
from dataclasses import dataclass
32

3+
from torch_tensorrt.dynamo._defaults import DEBUG_LOGGING_DIR
4+
45

56
@dataclass
67
class DebuggerConfig:
78
log_level: str = "debug"
89
save_engine_profile: bool = False
910
engine_builder_monitor: bool = True
10-
logging_dir: str = tempfile.gettempdir()
11+
logging_dir: str = DEBUG_LOGGING_DIR
1112
profile_format: str = "perfetto"
1213
save_layer_info: bool = False

tools/debug/engine_visualization/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ pip install git+https://github.com/NVIDIA/TensorRT.git#subdirectory=tools/experi
77
sudo apt --yes install graphviz
88
```
99

10+
## Usage
11+
The example usage can be found in `draw_engine_graph_example.py`. We use `torch_tensorrt.dynamo.debugger` to first output the engine profile info that required by TREX. Note that only when the compilation settings `use_python_runtime=False` can it produce TREX profiling. When it is saved to a folder, we call `draw_engine` on the same directory where the profile files are saved, which is in the subdirectory `engine_visualization_profile`.

tools/debug/engine_visualization/draw_engine_graph_example.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import torch
66
import torch_tensorrt as torch_tensorrt
77
import torchvision.models as models
8+
from torch_tensorrt.dynamo._defaults import DEBUG_LOGGING_DIR
89

910
inputs = [torch.rand((1, 3, 224, 224)).to("cuda")]
1011
model = models.resnet18(pretrained=False).eval().to("cuda")
@@ -14,12 +15,13 @@
1415
# min_block_size = 0
1516
use_python_runtime = False
1617
torch_executed_ops = {}
17-
logging_dir = "/home/profile"
18+
1819
with torch_tensorrt.dynamo.Debugger(
1920
"graphs",
20-
logging_dir=logging_dir,
21+
logging_dir=DEBUG_LOGGING_DIR,
2122
capture_fx_graph_after=["constant_fold"],
2223
save_engine_profile=True,
24+
profile_format="trex",
2325
):
2426
trt_gm = torch_tensorrt.dynamo.compile(
2527
exp_program,
@@ -32,5 +34,5 @@
3234

3335
from draw_engine_graph import draw_engine
3436

35-
draw_engine(os.path.join(logging_dir, "engine_visualization"))
37+
draw_engine(os.path.join(DEBUG_LOGGING_DIR, "engine_visualization_profile"))
3638
print()

0 commit comments

Comments
 (0)