Skip to content

Commit

Permalink
Optimize English doc of dynamic-to-static debugging and error_handling
Browse files Browse the repository at this point in the history
  • Loading branch information
liym27 committed Sep 27, 2020
1 parent 01ded5d commit 5cfd5b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
17 changes: 10 additions & 7 deletions doc/paddle/guides/dygraph_to_static/debugging_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ This section will introduce several debugging methods recommended by Dynamic Gra
```python
import paddle
import numpy as np
paddle.disable_static()

# Disable Dynamic-to-Static
paddle.jit.ProgramTranslator().enable(False)
Expand Down Expand Up @@ -99,7 +98,7 @@ There are two ways to print the transformed static graph code:
3, true_fn_0, false_fn_0, (x,), (x,), (x,))
return x
```
2. Call `set_code_level(level)` or set environment variable `TRANSLATOR_CODE_LEVEL=level`
2. Call [`set_code_level(level=100, also_to_stdout=False)`](../../../paddle/api/paddle/fluid/dygraph/jit/set_code_level_en.html) or set environment variable `TRANSLATOR_CODE_LEVEL=level`
You can view the transformed code in the log by calling `set_code_level` or set environment variable `TRANSLATOR_CODE_LEVEL`.
Expand All @@ -116,7 +115,7 @@ There are two ways to print the transformed static graph code:
```
```bash
2020-XX-XX 00:00:00,980-INFO: After the level 100 ast transformer: 'All Transformers', the transformed code:
2020-XX-XX 00:00:00,980 Dynamic-to-Static INFO: After the level 100 ast transformer: 'All Transformers', the transformed code:
def func(x):
x = fluid.layers.assign(x)

Expand All @@ -130,7 +129,8 @@ There are two ways to print the transformed static graph code:
3, true_fn_0, false_fn_0, (x,), (x,), (x,))
return x
```
`set_code_level` can set different levels to view the code transformed by different ast transformers. For details, please refer to [set_code_level](../../../paddle/api/paddle/fluid/dygraph/jit/set_code_level_en.html)。
In addition, if you want to output the transformed code to ``sys.stdout``, you can set the argument ``also_to_stdout`` to True, otherwise the transformed code is only output to ``sys.stderr``.
`set_code_level` can set different levels to view the code transformed by different ast transformers. For details, please refer to [set_code_level](../../../paddle/api/paddle/fluid/dygraph/jit/set_code_level_en.html).
## `print`
You can call `print` to view variables. `print` will be transformed when using Dynamic-to-Static. When only Paddle Tensor is printed, `print` will be transformed and call Paddle operator [Print](../../api/layers/Print.html) in runtime. Otherwise, call python `print`.
Expand Down Expand Up @@ -168,7 +168,7 @@ Here call print function.
## Log Printing
ProgramTranslator can log additional debugging information to help you know whether the function was successfully transformed or not.
You can call [`paddle.jit.set_verbosity(level)`](../../../paddle/api/paddle/fluid/dygraph/jit/set_verbosity_en.html) or set environment variable `TRANSLATOR_VERBOSITY=level` to enable logging and view logs of different levels. The argument `level` varies from 0 to 3:
You can call [`paddle.jit.set_verbosity(level=0, also_to_stdout=False)`](../../../paddle/api/paddle/fluid/dygraph/jit/set_verbosity_en.html) or set environment variable `TRANSLATOR_VERBOSITY=level` to enable logging and view logs of different levels. The argument `level` varies from 0 to 3:
- 0: no logging
- 1: includes the information in Dynamic-to-Static tranformation process, such as the source code not transformed, the callable object to transform and so on
- 2: includes above and more detailed function transformation logs
Expand All @@ -189,7 +189,7 @@ os.environ["TRANSLATOR_VERBOSITY"] = '3'
```
```bash
2020-XX-XX 00:00:00,123-Level 1: Source code:
2020-XX-XX 00:00:00,123 Dynamic-to-Static INFO: (Level 1) Source code:
@paddle.jit.to_static
def func(x):
x = paddle.to_tensor(x)
Expand All @@ -199,4 +199,7 @@ def func(x):
x = paddle.ones(shape=[1])
return x
2020-XX-XX 00:00:00,152-Level 1: Convert callable object: convert <built-in function len>.
2020-XX-XX 00:00:00,152 Dynamic-to-Static INFO: (Level 1) Convert callable object: convert <built-in function len>.
```
In addition, if you want to output the logs to ``sys.stdout``, you can set the argument ``also_to_stdout`` to True, otherwise the logs are only output to ``sys.stderr``. For details, please refer to [set_verbosity](../../../paddle/api/paddle/fluid/dygraph/jit/set_verbosity_en.html)
14 changes: 11 additions & 3 deletions doc/paddle/guides/dygraph_to_static/error_handling_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ In the following code, the function `inner_func` is transformed before calling.
import paddle
import numpy as np

paddle.disable_static()

@paddle.jit.to_static
def func():
def inner_func(x):
Expand All @@ -28,7 +26,7 @@ func()

The warning message is as follows:
```bash
WARNING: <function inner_func at 0x7fa9bcaacf50> doesn't have to be transformed to static function because it has been transformed before, it will be run as-is.
2020-01-01 00:00:00,104-WARNING: <function inner_func at 0x125b3a550> doesn't have to be transformed to static function because it has been transformed before, it will be run as-is.
```
## Exceptions in Running Transformed Code
Expand Down Expand Up @@ -97,6 +95,10 @@ The above error information can be divided into three points:
AssertionError: Only one dimension value of 'shape' in reshape can be -1. But received shape[1] is also -1.
```
> **NOTE:**
>
> If you want to view Paddle native error stack, that is, the error stack that has not been processed by Dynamic-to-Static, you can set the environment variable ``TRANSLATOR_DISABLE_NEW_ERROR=1`` to disable the Dynamic-to-Static error handling module. The default value of this environment variable is 0, which means to enable Dynamic-to-Static error handling module.
If execute the following code, an exception is raised when the static graph is executed at runtime:
```Python
Expand Down Expand Up @@ -158,3 +160,9 @@ InvalidArgumentError: The 'shape' in ReshapeOp is invalid. The input tensor X'si
```

In the above exception, in addition to hiding part of the error stack and locating the error to the un-transformed dynamic graph code, the error information includes the c++ error stack `C++ Traceback` and `Error Message Summary`, which are the exception from C++ and are displayed in Python exception after processing.

> **NOTE:**
>
> If you want to view the hidden part of the error stack, you can set the environment variable ``TRANSLATOR_SIMPLIFY_NEW_ERROR=0``. The default value of this environment variable is 1, which means to hide redundant error stack.
.

0 comments on commit 5cfd5b6

Please sign in to comment.