Skip to content

Commit 27b5a6c

Browse files
Krovatkinfacebook-github-bot
authored andcommitted
Add documentation to logging
Summary: Pull Request resolved: #26175 Differential Revision: D17371085 Pulled By: Krovatkin fbshipit-source-id: ea06f4e16fc320940a299e8e1d4f4d7c76f5950a
1 parent 20124c4 commit 27b5a6c

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

torch/csrc/jit/docs/OVERVIEW.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,32 @@ with prim::DifferentiableGraph_0 = graph(%13 : Float(*, *),
10261026
return (%hy, %cy)
10271027
```
10281028

1029+
## JIT Logging ##
1030+
1031+
Logging is a very useful debugging technique, especially in the context of compilers. Compilers perform a series of passes and analyses and logging can help to trace issues such as wrong results or segmentation faults
1032+
all the way back to the original erroneous transformation.
1033+
1034+
`TorchScript` offers a simple logging facility that can enabled by setting an environment variable `PYTORCH_JIT_LOG_LEVEL`.
1035+
1036+
Logging is enabled on a per file basis. To enable logging in `dead_code_elimination.cpp`, `PYTORCH_JIT_LOG_LEVEL` should be
1037+
set to `dead_code_elimination.cpp` or, simply, to `dead_code_elimination` (i.e. `PYTORCH_JIT_LOG_LEVEL=dead_code_elimination`).
1038+
1039+
Multiple files can be logged by separating each file name with a colon `:` as in the following example, `PYTORCH_JIT_LOG_LEVEL=dead_code_elimination:guard_elimination`
1040+
1041+
There are 3 logging levels available for your use ordered by the detail level from lowest to highest.
1042+
1043+
* `GRAPH_DUMP` should be used for printing entire graphs after optimization passes
1044+
* `GRAPH_UPDATE` should be used for reporting graph transformations (i.e. node deletion, constant folding, etc)
1045+
* `GRAPH_DEBUG` should be used for providing information useful for debugging
1046+
the internals of a particular optimization pass or analysis
1047+
1048+
The current logging level is `GRAPH_UPDATE` meaning that both `GRAPH_DUMP` and `GRAPH_UPDATE` will be enabled when
1049+
one specifies a file(s) in `PYTORCH_JIT_LOG_LEVEL`.
1050+
1051+
`GRAPH_DEBUG` can be enabled by prefixing a file name with an `>` as in `>alias_analysis`.
1052+
`>>` and `>>>` are also valid and **currently** are equivalent to `GRAPH_DEBUG` as there is no logging level that is
1053+
higher than `GRAPH_DEBUG`.
1054+
10291055
## DifferentiableGraphOp ##
10301056

10311057
[graph_executor.cpp](../graph_executor.cpp)

torch/csrc/jit/jit_log.h

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,38 @@
33
#include <string>
44
#include <torch/csrc/WindowsTorchApiMacro.h>
55

6-
// To enable logging please set(export) PYTORCH_JIT_LOG_LEVEL to
7-
// the ordinal value of one of the following logging levels: 1 for GRAPH_DUMP,
8-
// 2 for GRAPH_UPDATE, 3 for GRAPH_DEBUG.
9-
// * Use GRAPH_DUMP for dumping graphs after optimization passes
10-
// * Use GRAPH_UPDATE for reporting graph transformations (i.e. node deletion,
11-
// constant folding, CSE)
12-
// * Use GRAPH_DEBUG to provide information useful for debugging
6+
// `TorchScript` offers a simple logging facility that can enabled by setting an
7+
// environment variable `PYTORCH_JIT_LOG_LEVEL`.
8+
9+
// Logging is enabled on a per file basis. To enable logging in
10+
// `dead_code_elimination.cpp`, `PYTORCH_JIT_LOG_LEVEL` should be
11+
// set to `dead_code_elimination.cpp` or, simply, to `dead_code_elimination`
12+
// (i.e. `PYTORCH_JIT_LOG_LEVEL=dead_code_elimination`).
13+
14+
// Multiple files can be logged by separating each file name with a colon `:` as
15+
// in the following example,
16+
// `PYTORCH_JIT_LOG_LEVEL=dead_code_elimination:guard_elimination`
17+
18+
// There are 3 logging levels available for your use ordered by the detail level
19+
// from lowest to highest.
20+
21+
// * `GRAPH_DUMP` should be used for printing entire graphs after optimization
22+
// passes
23+
// * `GRAPH_UPDATE` should be used for reporting graph transformations (i.e.
24+
// node deletion, constant folding, etc)
25+
// * `GRAPH_DEBUG` should be used for providing information useful for debugging
1326
// the internals of a particular optimization pass or analysis
1427

28+
// The current logging level is `GRAPH_UPDATE` meaning that both `GRAPH_DUMP`
29+
// and `GRAPH_UPDATE` will be enabled when
30+
// one specifies a file(s) in `PYTORCH_JIT_LOG_LEVEL`.
31+
32+
// `GRAPH_DEBUG` can be enabled by prefixing a file name with an `>` as in
33+
// `>alias_analysis`.
34+
// `>>` and `>>>` are also valid and **currently** are equivalent to
35+
// `GRAPH_DEBUG` as there is no logging level that is
36+
// higher than `GRAPH_DEBUG`.
37+
1538
namespace torch {
1639
namespace jit {
1740

0 commit comments

Comments
 (0)