Skip to content

Commit 570209a

Browse files
committed
chore(//py): Adding documentation to the new context managers
Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
1 parent 11dc516 commit 570209a

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

py/torch_tensorrt/logging.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ def log(level: Level, msg: str):
108108
Graph = LogLevel.GRAPH
109109

110110
class internal_errors:
111+
"""Context-manager to limit displayed log messages to just internal errors
112+
113+
Example::
114+
115+
with torch_tensorrt.logging.internal_errors():
116+
outputs = model_torchtrt(inputs)
117+
"""
111118
def __enter__(self):
112119
self.external_lvl = get_reportable_log_level()
113120
set_reportable_log_level(Level.InternalError)
@@ -116,6 +123,13 @@ def __exit__(self, exc_type, exc_value, exc_tb):
116123
set_reportable_log_level(self.external_lvl)
117124

118125
class errors:
126+
"""Context-manager to limit displayed log messages to just errors and above
127+
128+
Example::
129+
130+
with torch_tensorrt.logging.errors():
131+
outputs = model_torchtrt(inputs)
132+
"""
119133
def __enter__(self):
120134
self.external_lvl = get_reportable_log_level()
121135
set_reportable_log_level(Level.Error)
@@ -124,6 +138,14 @@ def __exit__(self, exc_type, exc_value, exc_tb):
124138
set_reportable_log_level(self.external_lvl)
125139

126140
class warnings:
141+
"""Context-manager to limit displayed log messages to just warnings and above
142+
143+
Example::
144+
145+
with torch_tensorrt.logging.warnings():
146+
model_trt = torch_tensorrt.compile(model, **spec)
147+
"""
148+
127149
def __enter__(self):
128150
self.external_lvl = get_reportable_log_level()
129151
set_reportable_log_level(Level.Warning)
@@ -132,6 +154,13 @@ def __exit__(self, exc_type, exc_value, exc_tb):
132154
set_reportable_log_level(self.external_lvl)
133155

134156
class info:
157+
"""Context-manager to display all info and greater severity messages
158+
159+
Example::
160+
161+
with torch_tensorrt.logging.info():
162+
model_trt = torch_tensorrt.compile(model, **spec)
163+
"""
135164
def __enter__(self):
136165
self.external_lvl = get_reportable_log_level()
137166
set_reportable_log_level(Level.Info)
@@ -140,6 +169,13 @@ def __exit__(self, exc_type, exc_value, exc_tb):
140169
set_reportable_log_level(self.external_lvl)
141170

142171
class debug:
172+
"""Context-manager to display full debug information through the logger
173+
174+
Example::
175+
176+
with torch_tensorrt.logging.debug():
177+
model_trt = torch_tensorrt.compile(model, **spec)
178+
"""
143179
def __enter__(self):
144180
self.external_lvl = get_reportable_log_level()
145181
set_reportable_log_level(Level.Debug)
@@ -148,6 +184,14 @@ def __exit__(self, exc_type, exc_value, exc_tb):
148184
set_reportable_log_level(self.external_lvl)
149185

150186
class graphs:
187+
"""Context-manager to display the results of intermediate lowering passes
188+
as well as full debug information through the logger
189+
190+
Example::
191+
192+
with torch_tensorrt.logging.graphs():
193+
model_trt = torch_tensorrt.compile(model, **spec)
194+
"""
151195
def __enter__(self):
152196
self.external_lvl = get_reportable_log_level()
153197
set_reportable_log_level(Level.Graph)

0 commit comments

Comments
 (0)