Skip to content

Commit 8e29a3d

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 8e29a3d

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

py/torch_tensorrt/logging.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,55 +99,109 @@ def log(level: Level, msg: str):
9999
"""
100100
_log(Level._to_internal_level(level), msg)
101101

102-
103102
InternalError = LogLevel.INTERNAL_ERROR
104103
Error = LogLevel.ERROR
105104
Warning = LogLevel.WARNING
106105
Info = LogLevel.INFO
107106
Debug = LogLevel.DEBUG
108107
Graph = LogLevel.GRAPH
109108

109+
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+
"""
118+
111119
def __enter__(self):
112120
self.external_lvl = get_reportable_log_level()
113121
set_reportable_log_level(Level.InternalError)
114122

115123
def __exit__(self, exc_type, exc_value, exc_tb):
116124
set_reportable_log_level(self.external_lvl)
117125

126+
118127
class errors:
128+
"""Context-manager to limit displayed log messages to just errors and above
129+
130+
Example::
131+
132+
with torch_tensorrt.logging.errors():
133+
outputs = model_torchtrt(inputs)
134+
"""
135+
119136
def __enter__(self):
120137
self.external_lvl = get_reportable_log_level()
121138
set_reportable_log_level(Level.Error)
122139

123140
def __exit__(self, exc_type, exc_value, exc_tb):
124141
set_reportable_log_level(self.external_lvl)
125142

143+
126144
class warnings:
145+
"""Context-manager to limit displayed log messages to just warnings and above
146+
147+
Example::
148+
149+
with torch_tensorrt.logging.warnings():
150+
model_trt = torch_tensorrt.compile(model, **spec)
151+
"""
152+
127153
def __enter__(self):
128154
self.external_lvl = get_reportable_log_level()
129155
set_reportable_log_level(Level.Warning)
130156

131157
def __exit__(self, exc_type, exc_value, exc_tb):
132158
set_reportable_log_level(self.external_lvl)
133159

160+
134161
class info:
162+
"""Context-manager to display all info and greater severity messages
163+
164+
Example::
165+
166+
with torch_tensorrt.logging.info():
167+
model_trt = torch_tensorrt.compile(model, **spec)
168+
"""
169+
135170
def __enter__(self):
136171
self.external_lvl = get_reportable_log_level()
137172
set_reportable_log_level(Level.Info)
138173

139174
def __exit__(self, exc_type, exc_value, exc_tb):
140175
set_reportable_log_level(self.external_lvl)
141176

177+
142178
class debug:
179+
"""Context-manager to display full debug information through the logger
180+
181+
Example::
182+
183+
with torch_tensorrt.logging.debug():
184+
model_trt = torch_tensorrt.compile(model, **spec)
185+
"""
186+
143187
def __enter__(self):
144188
self.external_lvl = get_reportable_log_level()
145189
set_reportable_log_level(Level.Debug)
146190

147191
def __exit__(self, exc_type, exc_value, exc_tb):
148192
set_reportable_log_level(self.external_lvl)
149193

194+
150195
class graphs:
196+
"""Context-manager to display the results of intermediate lowering passes
197+
as well as full debug information through the logger
198+
199+
Example::
200+
201+
with torch_tensorrt.logging.graphs():
202+
model_trt = torch_tensorrt.compile(model, **spec)
203+
"""
204+
151205
def __enter__(self):
152206
self.external_lvl = get_reportable_log_level()
153207
set_reportable_log_level(Level.Graph)

0 commit comments

Comments
 (0)