Skip to content

Commit 714f530

Browse files
committed
Fixed the comments
1 parent 65c9c03 commit 714f530

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
@@ -68,7 +68,6 @@ def cross_compile_for_windows(
6868
Set[Union[torch.dtype, dtype]], Tuple[Union[torch.dtype, dtype]]
6969
] = _defaults.ENABLED_PRECISIONS,
7070
engine_capability: EngineCapability = _defaults.ENGINE_CAPABILITY,
71-
debug: bool = False,
7271
num_avg_timing_iters: int = _defaults.NUM_AVG_TIMING_ITERS,
7372
workspace_size: int = _defaults.WORKSPACE_SIZE,
7473
dla_sram_size: int = _defaults.DLA_SRAM_SIZE,
@@ -142,7 +141,6 @@ def cross_compile_for_windows(
142141
assume_dynamic_shape_support (bool): Setting this to true enables the converters work for both dynamic and static shapes. Default: False
143142
sparse_weights (bool): Enable sparsity for convolution and fully connected layers.
144143
enabled_precision (Set(Union(torch.dtype, torch_tensorrt.dtype))): The set of datatypes that TensorRT can use when selecting kernels
145-
debug (bool): Enable debuggable engine
146144
capability (torch_tensorrt.EngineCapability): Restrict kernel selection to safe gpu kernels or safe dla kernels
147145
num_avg_timing_iters (int): Number of averaging timing iterations used to select kernels
148146
workspace_size (int): Maximum size of workspace given to TensorRT
@@ -189,9 +187,9 @@ def cross_compile_for_windows(
189187
f"Cross compile for windows is only supported on x86-64 Linux architecture, current platform: {platform.system()=}, {platform.architecture()[0]=}"
190188
)
191189

192-
if debug:
190+
if kwargs.get("debug", False):
193191
warnings.warn(
194-
"`debug` is deprecated. Please use `torch_tensorrt.dynamo.Debugger` to configure debugging options.",
192+
"`debug` is deprecated. Please use `with torch_tensorrt.dynamo.Debugger(...)` to wrap your compilation call to enable debugging functionality.",
195193
DeprecationWarning,
196194
stacklevel=2,
197195
)
@@ -406,7 +404,6 @@ def compile(
406404
Set[Union[torch.dtype, dtype]], Tuple[Union[torch.dtype, dtype]]
407405
] = _defaults.ENABLED_PRECISIONS,
408406
engine_capability: EngineCapability = _defaults.ENGINE_CAPABILITY,
409-
debug: bool = False,
410407
num_avg_timing_iters: int = _defaults.NUM_AVG_TIMING_ITERS,
411408
workspace_size: int = _defaults.WORKSPACE_SIZE,
412409
dla_sram_size: int = _defaults.DLA_SRAM_SIZE,
@@ -482,7 +479,6 @@ def compile(
482479
assume_dynamic_shape_support (bool): Setting this to true enables the converters work for both dynamic and static shapes. Default: False
483480
sparse_weights (bool): Enable sparsity for convolution and fully connected layers.
484481
enabled_precision (Set(Union(torch.dtype, torch_tensorrt.dtype))): The set of datatypes that TensorRT can use when selecting kernels
485-
debug (bool): Enable debuggable engine
486482
capability (torch_tensorrt.EngineCapability): Restrict kernel selection to safe gpu kernels or safe dla kernels
487483
num_avg_timing_iters (int): Number of averaging timing iterations used to select kernels
488484
workspace_size (int): Maximum size of workspace given to TensorRT
@@ -525,9 +521,9 @@ def compile(
525521
torch.fx.GraphModule: Compiled FX Module, when run it will execute via TensorRT
526522
"""
527523

528-
if debug:
524+
if kwargs.get("debug", False):
529525
warnings.warn(
530-
"`debug` is deprecated. Please use `torch_tensorrt.dynamo.Debugger` for debugging functionality",
526+
"`debug` is deprecated. Please use `with torch_tensorrt.dynamo.Debugger(...)` to wrap your compilation call to enable debugging functionality",
531527
DeprecationWarning,
532528
stacklevel=2,
533529
)
@@ -735,7 +731,7 @@ def compile_module(
735731
settings: CompilationSettings = CompilationSettings(),
736732
engine_cache: Optional[BaseEngineCache] = None,
737733
*,
738-
_debugger_settings: Optional[DebuggerConfig] = None,
734+
_debugger_config: Optional[DebuggerConfig] = None,
739735
) -> torch.fx.GraphModule:
740736
"""Compile a traced FX module
741737
@@ -938,29 +934,36 @@ def contains_metadata(gm: torch.fx.GraphModule) -> bool:
938934

939935
trt_modules[name] = trt_module
940936

941-
if _debugger_settings:
937+
if _debugger_config:
942938

943-
if _debugger_settings.save_engine_profile:
939+
if _debugger_config.save_engine_profile:
944940
if settings.use_python_runtime:
945-
if _debugger_settings.profile_format == "trex":
946-
logger.warning(
941+
if _debugger_config.profile_format != "cudagraph":
942+
raise ValueError(
947943
"Profiling with TREX can only be enabled when using the C++ runtime. Python runtime profiling only support cudagraph visualization."
948944
)
945+
else:
949946
trt_module.enable_profiling()
950947
else:
951-
path = os.path.join(
952-
_debugger_settings.logging_dir, "engine_visualization"
953-
)
954-
os.makedirs(path, exist_ok=True)
955-
trt_module.enable_profiling(
956-
profiling_results_dir=path,
957-
profile_format=_debugger_settings.profile_format,
958-
)
959-
960-
if _debugger_settings.save_layer_info:
948+
if _debugger_config.profile_format == "cudagraph":
949+
raise ValueError(
950+
"Profiling with Cudagraph can only be enabled when using the Python runtime. C++ runtime profiling only support TREX/Perfetto visualization."
951+
)
952+
else:
953+
path = os.path.join(
954+
_debugger_config.logging_dir,
955+
"engine_visualization_profile",
956+
)
957+
os.makedirs(path, exist_ok=True)
958+
trt_module.enable_profiling(
959+
profiling_results_dir=path,
960+
profile_format=_debugger_config.profile_format,
961+
)
962+
963+
if _debugger_config.save_layer_info:
961964
with open(
962965
os.path.join(
963-
_debugger_settings.logging_dir, "engine_layer_info.json"
966+
_debugger_config.logging_dir, "engine_layer_info.json"
964967
),
965968
"w",
966969
) as f:
@@ -993,7 +996,6 @@ def convert_exported_program_to_serialized_trt_engine(
993996
enabled_precisions: (
994997
Set[torch.dtype | dtype] | Tuple[torch.dtype | dtype]
995998
) = _defaults.ENABLED_PRECISIONS,
996-
debug: bool = False,
997999
assume_dynamic_shape_support: bool = _defaults.ASSUME_DYNAMIC_SHAPE_SUPPORT,
9981000
workspace_size: int = _defaults.WORKSPACE_SIZE,
9991001
min_block_size: int = _defaults.MIN_BLOCK_SIZE,
@@ -1055,7 +1057,6 @@ def convert_exported_program_to_serialized_trt_engine(
10551057
torch.randn((1, 3, 224, 244)) # Use an example tensor and let torch_tensorrt infer settings
10561058
]
10571059
enabled_precisions (Optional[Set[torch.dtype | _enums.dtype]]): The set of datatypes that TensorRT can use
1058-
debug (bool): Whether to print out verbose debugging information
10591060
workspace_size (int): Workspace TRT is allowed to use for the module (0 is default)
10601061
min_block_size (int): Minimum number of operators per TRT-Engine Block
10611062
torch_executed_ops (Set[str]): Set of operations to run in Torch, regardless of converter coverage
@@ -1095,9 +1096,9 @@ def convert_exported_program_to_serialized_trt_engine(
10951096
Returns:
10961097
bytes: Serialized TensorRT engine, can either be saved to a file or deserialized via TensorRT APIs
10971098
"""
1098-
if debug:
1099+
if kwargs.get("debug", False):
10991100
warnings.warn(
1100-
"`debug` is deprecated. Please use `torch_tensorrt.dynamo.Debugger` to configure debugging options.",
1101+
"`debug` is deprecated. Please use `with torch_tensorrt.dynamo.Debugger(...)` to wrap your compilation call to enable debugging functionality.",
11011102
DeprecationWarning,
11021103
stacklevel=2,
11031104
)
@@ -1184,7 +1185,6 @@ def convert_exported_program_to_serialized_trt_engine(
11841185
compilation_options = {
11851186
"assume_dynamic_shape_support": assume_dynamic_shape_support,
11861187
"enabled_precisions": enabled_precisions,
1187-
"debug": debug,
11881188
"workspace_size": workspace_size,
11891189
"min_block_size": min_block_size,
11901190
"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
@@ -56,6 +56,7 @@
5656
L2_LIMIT_FOR_TILING = -1
5757
USE_DISTRIBUTED_MODE_TRACE = False
5858
OFFLOAD_MODULE_TO_CPU = False
59+
DEBUG_LOGGING_DIR = os.path.join(tempfile.gettempdir(), "torch_tensorrt/debug_logs")
5960

6061

6162
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)