Skip to content

Commit b46599e

Browse files
committed
Fixed the comments
1 parent 5683644 commit b46599e

File tree

13 files changed

+83
-111
lines changed

13 files changed

+83
-111
lines changed

core/runtime/TRTEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void TRTEngine::set_profiling_paths() {
325325
output_profile_path = std::filesystem::path{profile_path_prefix + "/" + name + "_output_profile.trace"}.string();
326326
enqueue_profile_path = std::filesystem::path{profile_path_prefix + "/" + name + "_enqueue_profile.trace"}.string();
327327
trt_engine_profile_path =
328-
std::filesystem::path{profile_path_prefix + "/" + name + "_engine_exectuion_profile.trace"}.string();
328+
std::filesystem::path{profile_path_prefix + "/" + name + "_engine_execution_profile.trace"}.string();
329329
cuda_graph_debug_path = std::filesystem::path{profile_path_prefix + "/" + name + "_cudagraph.dot"}.string();
330330
}
331331

core/runtime/TRTEngineProfiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void dump_trace(const std::string& path, const TRTEngineProfiler& value) {
6262
} else { // kTREX
6363
out << " \"timeMs\": " << elem.time << "," << std::endl;
6464
out << " \"averageMs\": " << elem.time / elem.count << "," << std::endl;
65-
out << " \"percentage\": " << (elem.time * 100.0 / ts) << "," << std::endl;
65+
out << " \"percentage\": " << (elem.time * 100.0 / ts) << std::endl;
6666
}
6767
out << " }," << std::endl;
6868
running_time += elem.time;

core/runtime/TRTEngineProfiler.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ namespace runtime {
1212

1313
enum TraceFormat { kPERFETTO, kTREX };
1414

15-
// Forward declare the function
16-
1715
struct TRTEngineProfiler : public nvinfer1::IProfiler {
1816
struct Record {
1917
float time{0};

py/torch_tensorrt/dynamo/_compiler.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def cross_compile_for_windows(
6666
Set[Union[torch.dtype, dtype]], Tuple[Union[torch.dtype, dtype]]
6767
] = _defaults.ENABLED_PRECISIONS,
6868
engine_capability: EngineCapability = _defaults.ENGINE_CAPABILITY,
69-
debug: bool = False,
7069
num_avg_timing_iters: int = _defaults.NUM_AVG_TIMING_ITERS,
7170
workspace_size: int = _defaults.WORKSPACE_SIZE,
7271
dla_sram_size: int = _defaults.DLA_SRAM_SIZE,
@@ -140,7 +139,6 @@ def cross_compile_for_windows(
140139
assume_dynamic_shape_support (bool): Setting this to true enables the converters work for both dynamic and static shapes. Default: False
141140
sparse_weights (bool): Enable sparsity for convolution and fully connected layers.
142141
enabled_precision (Set(Union(torch.dtype, torch_tensorrt.dtype))): The set of datatypes that TensorRT can use when selecting kernels
143-
debug (bool): Enable debuggable engine
144142
capability (torch_tensorrt.EngineCapability): Restrict kernel selection to safe gpu kernels or safe dla kernels
145143
num_avg_timing_iters (int): Number of averaging timing iterations used to select kernels
146144
workspace_size (int): Maximum size of workspace given to TensorRT
@@ -187,9 +185,9 @@ def cross_compile_for_windows(
187185
f"Cross compile for windows is only supported on x86-64 Linux architecture, current platform: {platform.system()=}, {platform.architecture()[0]=}"
188186
)
189187

190-
if debug:
188+
if kwargs.get("debug", False):
191189
warnings.warn(
192-
"`debug` is deprecated. Please use `torch_tensorrt.dynamo.Debugger` to configure debugging options.",
190+
"`debug` is deprecated. Please use `with torch_tensorrt.dynamo.Debugger(...)` to wrap your compilation call to enable debugging functionality.",
193191
DeprecationWarning,
194192
stacklevel=2,
195193
)
@@ -404,7 +402,6 @@ def compile(
404402
Set[Union[torch.dtype, dtype]], Tuple[Union[torch.dtype, dtype]]
405403
] = _defaults.ENABLED_PRECISIONS,
406404
engine_capability: EngineCapability = _defaults.ENGINE_CAPABILITY,
407-
debug: bool = False,
408405
num_avg_timing_iters: int = _defaults.NUM_AVG_TIMING_ITERS,
409406
workspace_size: int = _defaults.WORKSPACE_SIZE,
410407
dla_sram_size: int = _defaults.DLA_SRAM_SIZE,
@@ -480,7 +477,6 @@ def compile(
480477
assume_dynamic_shape_support (bool): Setting this to true enables the converters work for both dynamic and static shapes. Default: False
481478
sparse_weights (bool): Enable sparsity for convolution and fully connected layers.
482479
enabled_precision (Set(Union(torch.dtype, torch_tensorrt.dtype))): The set of datatypes that TensorRT can use when selecting kernels
483-
debug (bool): Enable debuggable engine
484480
capability (torch_tensorrt.EngineCapability): Restrict kernel selection to safe gpu kernels or safe dla kernels
485481
num_avg_timing_iters (int): Number of averaging timing iterations used to select kernels
486482
workspace_size (int): Maximum size of workspace given to TensorRT
@@ -523,9 +519,9 @@ def compile(
523519
torch.fx.GraphModule: Compiled FX Module, when run it will execute via TensorRT
524520
"""
525521

526-
if debug:
522+
if kwargs.get("debug", False):
527523
warnings.warn(
528-
"`debug` is deprecated. Please use `torch_tensorrt.dynamo.Debugger` for debugging functionality",
524+
"`debug` is deprecated. Please use `with torch_tensorrt.dynamo.Debugger(...)` to wrap your compilation call to enable debugging functionality",
529525
DeprecationWarning,
530526
stacklevel=2,
531527
)
@@ -732,7 +728,7 @@ def compile_module(
732728
settings: CompilationSettings = CompilationSettings(),
733729
engine_cache: Optional[BaseEngineCache] = None,
734730
*,
735-
_debugger_settings: Optional[DebuggerConfig] = None,
731+
_debugger_config: Optional[DebuggerConfig] = None,
736732
) -> torch.fx.GraphModule:
737733
"""Compile a traced FX module
738734
@@ -935,29 +931,36 @@ def contains_metadata(gm: torch.fx.GraphModule) -> bool:
935931

936932
trt_modules[name] = trt_module
937933

938-
if _debugger_settings:
934+
if _debugger_config:
939935

940-
if _debugger_settings.save_engine_profile:
936+
if _debugger_config.save_engine_profile:
941937
if settings.use_python_runtime:
942-
if _debugger_settings.profile_format == "trex":
943-
logger.warning(
938+
if _debugger_config.profile_format != "cudagraph":
939+
raise ValueError(
944940
"Profiling with TREX can only be enabled when using the C++ runtime. Python runtime profiling only support cudagraph visualization."
945941
)
942+
else:
946943
trt_module.enable_profiling()
947944
else:
948-
path = os.path.join(
949-
_debugger_settings.logging_dir, "engine_visualization"
950-
)
951-
os.makedirs(path, exist_ok=True)
952-
trt_module.enable_profiling(
953-
profiling_results_dir=path,
954-
profile_format=_debugger_settings.profile_format,
955-
)
956-
957-
if _debugger_settings.save_layer_info:
945+
if _debugger_config.profile_format == "cudagraph":
946+
raise ValueError(
947+
"Profiling with Cudagraph can only be enabled when using the Python runtime. C++ runtime profiling only support TREX/Perfetto visualization."
948+
)
949+
else:
950+
path = os.path.join(
951+
_debugger_config.logging_dir,
952+
"engine_visualization_profile",
953+
)
954+
os.makedirs(path, exist_ok=True)
955+
trt_module.enable_profiling(
956+
profiling_results_dir=path,
957+
profile_format=_debugger_config.profile_format,
958+
)
959+
960+
if _debugger_config.save_layer_info:
958961
with open(
959962
os.path.join(
960-
_debugger_settings.logging_dir, "engine_layer_info.json"
963+
_debugger_config.logging_dir, "engine_layer_info.json"
961964
),
962965
"w",
963966
) as f:
@@ -990,7 +993,6 @@ def convert_exported_program_to_serialized_trt_engine(
990993
enabled_precisions: (
991994
Set[torch.dtype | dtype] | Tuple[torch.dtype | dtype]
992995
) = _defaults.ENABLED_PRECISIONS,
993-
debug: bool = False,
994996
assume_dynamic_shape_support: bool = _defaults.ASSUME_DYNAMIC_SHAPE_SUPPORT,
995997
workspace_size: int = _defaults.WORKSPACE_SIZE,
996998
min_block_size: int = _defaults.MIN_BLOCK_SIZE,
@@ -1052,7 +1054,6 @@ def convert_exported_program_to_serialized_trt_engine(
10521054
torch.randn((1, 3, 224, 244)) # Use an example tensor and let torch_tensorrt infer settings
10531055
]
10541056
enabled_precisions (Optional[Set[torch.dtype | _enums.dtype]]): The set of datatypes that TensorRT can use
1055-
debug (bool): Whether to print out verbose debugging information
10561057
workspace_size (int): Workspace TRT is allowed to use for the module (0 is default)
10571058
min_block_size (int): Minimum number of operators per TRT-Engine Block
10581059
torch_executed_ops (Set[str]): Set of operations to run in Torch, regardless of converter coverage
@@ -1092,9 +1093,9 @@ def convert_exported_program_to_serialized_trt_engine(
10921093
Returns:
10931094
bytes: Serialized TensorRT engine, can either be saved to a file or deserialized via TensorRT APIs
10941095
"""
1095-
if debug:
1096+
if kwargs.get("debug", False):
10961097
warnings.warn(
1097-
"`debug` is deprecated. Please use `torch_tensorrt.dynamo.Debugger` to configure debugging options.",
1098+
"`debug` is deprecated. Please use `with torch_tensorrt.dynamo.Debugger(...)` to wrap your compilation call to enable debugging functionality.",
10981099
DeprecationWarning,
10991100
stacklevel=2,
11001101
)
@@ -1181,7 +1182,6 @@ def convert_exported_program_to_serialized_trt_engine(
11811182
compilation_options = {
11821183
"assume_dynamic_shape_support": assume_dynamic_shape_support,
11831184
"enabled_precisions": enabled_precisions,
1184-
"debug": debug,
11851185
"workspace_size": workspace_size,
11861186
"min_block_size": min_block_size,
11871187
"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
@@ -49,6 +49,7 @@
4949
L2_LIMIT_FOR_TILING = -1
5050
USE_DISTRIBUTED_MODE_TRACE = False
5151
OFFLOAD_MODULE_TO_CPU = False
52+
DEBUG_LOGGING_DIR = os.path.join(tempfile.gettempdir(), "torch_tensorrt/debug_logs")
5253

5354

5455
def default_device() -> Device:

py/torch_tensorrt/dynamo/conversion/_TRTInterpreter.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
get_trt_tensor,
4646
to_torch,
4747
)
48-
from torch_tensorrt.dynamo.utils import DYNAMIC_DIM, deallocate_module, to_torch_device
4948
from torch_tensorrt.dynamo.debug._DebuggerConfig import DebuggerConfig
5049
from torch_tensorrt.dynamo.debug._supports_debugger import cls_supports_debugger
50+
from torch_tensorrt.dynamo.utils import DYNAMIC_DIM, deallocate_module, to_torch_device
5151
from torch_tensorrt.fx.observer import Observer
5252
from torch_tensorrt.logging import TRT_LOGGER
5353

@@ -82,13 +82,13 @@ def __init__(
8282
compilation_settings: CompilationSettings = CompilationSettings(),
8383
engine_cache: Optional[BaseEngineCache] = None,
8484
*,
85-
_debugger_settings: Optional[DebuggerConfig] = None,
85+
_debugger_config: Optional[DebuggerConfig] = None,
8686
):
8787
super().__init__(module)
8888

8989
self.logger = TRT_LOGGER
9090
self.builder = trt.Builder(self.logger)
91-
self._debugger_settings = _debugger_settings
91+
self._debugger_config = _debugger_config
9292
flag = 0
9393
if compilation_settings.use_explicit_typing:
9494
STRONGLY_TYPED = 1 << (int)(
@@ -209,7 +209,7 @@ def _populate_trt_builder_config(
209209
) -> trt.IBuilderConfig:
210210
builder_config = self.builder.create_builder_config()
211211

212-
if self._debugger_settings and self._debugger_settings.engine_builder_monitor:
212+
if self._debugger_config and self._debugger_config.engine_builder_monitor:
213213
builder_config.progress_monitor = TRTBulderMonitor()
214214

215215
if self.compilation_settings.workspace_size != 0:
@@ -220,8 +220,7 @@ def _populate_trt_builder_config(
220220
if version.parse(trt.__version__) >= version.parse("8.2"):
221221
builder_config.profiling_verbosity = (
222222
trt.ProfilingVerbosity.DETAILED
223-
if self._debugger_settings
224-
and self._debugger_settings.save_engine_profile
223+
if self._debugger_config and self._debugger_config.save_engine_profile
225224
else trt.ProfilingVerbosity.LAYER_NAMES_ONLY
226225
)
227226

py/torch_tensorrt/dynamo/debug/_Debugger.py

Lines changed: 24 additions & 51 deletions
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,
@@ -18,7 +19,7 @@
1819
ATEN_PRE_LOWERING_PASSES,
1920
)
2021

21-
_LOGGER = logging.getLogger("torch_tensorrt [TensorRT Conversion Context]")
22+
_LOGGER = logging.getLogger(__name__)
2223
GRAPH_LEVEL = 5
2324
logging.addLevelName(GRAPH_LEVEL, "GRAPHS")
2425

@@ -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.
@@ -47,8 +48,9 @@ def __init__(
4748
after execution of a lowering pass. Defaults to None.
4849
save_engine_profile (bool): Whether to save TensorRT engine profiling information.
4950
Defaults to False.
50-
profile_format (str): Format for profiling data. Can be either 'perfetto' or 'trex'.
51-
If you need to generate engine graph using the profiling files, set it to 'trex' .
51+
profile_format (str): Format for profiling data. Choose from 'perfetto', 'trex', 'cudagraph'.
52+
If you need to generate engine graph using the profiling files, set it to 'trex' and use the C++ runtime.
53+
If you need to generate cudagraph visualization, set it to 'cudagraph'.
5254
Defaults to 'perfetto'.
5355
engine_builder_monitor (bool): Whether to monitor TensorRT engine building process.
5456
Defaults to True.
@@ -92,7 +94,7 @@ def __init__(
9294
def __enter__(self) -> None:
9395
self.original_lvl = _LOGGER.getEffectiveLevel()
9496
self.rt_level = torch.ops.tensorrt.get_logging_level()
95-
dictConfig(self.get_customized_logging_config())
97+
dictConfig(self.get_logging_config(self.log_level))
9698

9799
if self.capture_fx_graph_before or self.capture_fx_graph_after:
98100
self.old_pre_passes, self.old_post_passes = (
@@ -126,22 +128,22 @@ def __enter__(self) -> None:
126128
self._context_stack = contextlib.ExitStack()
127129

128130
for f in _DEBUG_ENABLED_FUNCS:
129-
f.__kwdefaults__["_debugger_settings"] = self.cfg
131+
f.__kwdefaults__["_debugger_config"] = self.cfg
130132

131133
[
132134
self._context_stack.enter_context(
133135
mock.patch.object(
134136
c,
135137
"__init__",
136-
functools.partialmethod(c.__init__, _debugger_settings=self.cfg),
138+
functools.partialmethod(c.__init__, _debugger_config=self.cfg),
137139
)
138140
)
139141
for c in _DEBUG_ENABLED_CLS
140142
]
141143

142144
def __exit__(self, exc_type: Any, exc_value: Any, exc_tb: Any) -> None:
143145

144-
dictConfig(self.get_default_logging_config())
146+
dictConfig(self.get_logging_config(None))
145147
torch.ops.tensorrt.set_logging_level(self.rt_level)
146148
if self.capture_fx_graph_before or self.capture_fx_graph_after:
147149
ATEN_PRE_LOWERING_PASSES.passes, ATEN_POST_LOWERING_PASSES.passes = (
@@ -151,50 +153,13 @@ def __exit__(self, exc_type: Any, exc_value: Any, exc_tb: Any) -> None:
151153
self.debug_file_dir = tempfile.TemporaryDirectory().name
152154

153155
for f in _DEBUG_ENABLED_FUNCS:
154-
f.__kwdefaults__["_debugger_settings"] = None
156+
f.__kwdefaults__["_debugger_config"] = None
155157

156158
self._context_stack.close()
157159

158-
def get_customized_logging_config(self) -> dict[str, Any]:
159-
config = {
160-
"version": 1,
161-
"disable_existing_loggers": False,
162-
"formatters": {
163-
"brief": {
164-
"format": "%(asctime)s - %(levelname)s - %(message)s",
165-
"datefmt": "%H:%M:%S",
166-
},
167-
"standard": {
168-
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
169-
"datefmt": "%Y-%m-%d %H:%M:%S",
170-
},
171-
},
172-
"handlers": {
173-
"file": {
174-
"level": self.log_level,
175-
"class": "logging.FileHandler",
176-
"filename": f"{self.cfg.logging_dir}/torch_tensorrt_logging.log",
177-
"formatter": "standard",
178-
},
179-
"console": {
180-
"level": self.log_level,
181-
"class": "logging.StreamHandler",
182-
"formatter": "brief",
183-
},
184-
},
185-
"loggers": {
186-
"": { # root logger
187-
"handlers": ["file", "console"],
188-
"level": self.log_level,
189-
"propagate": True,
190-
},
191-
},
192-
"force": True,
193-
}
194-
return config
195-
196-
def get_default_logging_config(self) -> dict[str, Any]:
197-
config = {
160+
def get_logging_config(self, log_level: Optional[int] = None) -> dict[str, Any]:
161+
level = log_level if log_level is not None else self.original_lvl
162+
config: dict[str, Any] = {
198163
"version": 1,
199164
"disable_existing_loggers": False,
200165
"formatters": {
@@ -209,18 +174,26 @@ def get_default_logging_config(self) -> dict[str, Any]:
209174
},
210175
"handlers": {
211176
"console": {
212-
"level": self.original_lvl,
177+
"level": level,
213178
"class": "logging.StreamHandler",
214179
"formatter": "brief",
215180
},
216181
},
217182
"loggers": {
218183
"": { # root logger
219184
"handlers": ["console"],
220-
"level": self.original_lvl,
185+
"level": level,
221186
"propagate": True,
222187
},
223188
},
224189
"force": True,
225190
}
191+
if log_level is not None:
192+
config["handlers"]["file"] = {
193+
"level": level,
194+
"class": "logging.FileHandler",
195+
"filename": f"{self.cfg.logging_dir}/torch_tensorrt_logging.log",
196+
"formatter": "standard",
197+
}
198+
config["loggers"][""]["handlers"].append("file")
226199
return config

0 commit comments

Comments
 (0)