diff --git a/doc/fluid/advanced_guide/dygraph_to_static/debugging_cn.md b/doc/fluid/advanced_guide/dygraph_to_static/debugging_cn.md index 7fa3e7e462648f5aef51da11294c51661d18fd09..40bc3e002eadc30f03383cf4d262931179001322 100644 --- a/doc/fluid/advanced_guide/dygraph_to_static/debugging_cn.md +++ b/doc/fluid/advanced_guide/dygraph_to_static/debugging_cn.md @@ -4,7 +4,7 @@ > **注解:** > -> 请确保转换前的动态图代码能够成功运行,建议使用[paddle.jit.ProgramTranslator().enable(False)](../../api_cn/dygraph_cn/ProgramTranslator_cn.html#enable)关闭动转静功能,直接运行动态图,如下: +> 请确保转换前的动态图代码能够成功运行,建议使用 [paddle.jit.ProgramTranslator().enable(False)](../../api_cn/dygraph_cn/ProgramTranslator_cn.html#enable)关闭动转静功能,直接运行动态图,如下: ```python import paddle @@ -25,7 +25,7 @@ func(np.ones([3, 2])) ## 断点调试 使用动转静功能时,您可以使用断点调试代码。 -例如,在代码中,调用`pdb.set_trace()`: +例如,在代码中,调用 `pdb.set_trace()`: ```Python import pdb @@ -52,7 +52,7 @@ func(np.ones([3, 2])) ... ``` -如果您想在原始的动态图代码中使用调试器,请先调用[`paddle.jit.ProgramTranslator().enable(False)`](../../api_cn/dygraph_cn/ProgramTranslator_cn.html#enable),如下: +如果您想在原始的动态图代码中使用调试器,请先调用 [`paddle.jit.ProgramTranslator().enable(False)`](../../api_cn/dygraph_cn/ProgramTranslator_cn.html#enable),如下: ```python paddle.jit.ProgramTranslator().enable(False) func(np.ones([3, 2])) @@ -68,7 +68,8 @@ func(np.ones([3, 2])) ## 打印转换后的代码 您可以打印转换后的静态图代码,有2种方法: -1. 使用被装饰函数的`code` 属性 +1. 使用被装饰后的函数的 `code` 属性 + 如下代码中,装饰器 `paddle.jit.to_static` 会将函数 `func` 转化为一个类对象 `StaticLayer`,可以使用 StaticLayer 的 `code` 属性来获得转化后的代码。 ```Python @paddle.jit.to_static def func(x): @@ -97,9 +98,9 @@ func(np.ones([3, 2])) return x ``` -2. 使用`set_code_level(level)`或环境变量`TRANSLATOR_CODE_LEVEL=level` +2. 使用 `set_code_level(level)` 或环境变量 `TRANSLATOR_CODE_LEVEL=level` - 通过调用`set_code_level`或设置环境变量`TRANSLATOR_CODE_LEVEL`,可以在log中查看转换后的代码: + 通过调用 `set_code_level` 或设置环境变量 `TRANSLATOR_CODE_LEVEL`,可以在日志中查看转换后的代码: ```python @paddle.jit.to_static @@ -129,10 +130,10 @@ func(np.ones([3, 2])) 3, true_fn_0, false_fn_0, (x,), (x,), (x,)) return x ``` - `set_code_level` 函数可以设置查看不同的AST Transformer转化后的代码,详情请见[set_code_level]()。 + `set_code_level` 函数可以设置查看不同的AST Transformer转化后的代码,详情请见 [set_code_level](../../../paddle/api/paddle/fluid/dygraph/jit/set_code_level_cn.html)。 ## 使用 `print` -`print` 函数可以用来查看变量,该函数在动转静中会被转化。当仅打印Paddle Tensor时,实际运行时会被转换为Paddle算子[Print](../../api_cn/layers_cn/Print_cn.html),否则仍然运行`print`。 +`print` 函数可以用来查看变量,该函数在动转静中会被转化。当仅打印 Paddle Tensor 时,实际运行时会被转换为 Paddle 算子 [Print](../../api_cn/layers_cn/Print_cn.html),否则仍然运行 `print`。 ```python @paddle.jit.to_static def func(x): @@ -167,7 +168,7 @@ Here call print function. ## 日志打印 ProgramTranslator在日志中记录了额外的调试信息,以帮助您了解动转静过程中函数是否被成功转换。 -您可以调用`paddle.jit.set_verbosity(level)` 或设置环境变量`TRANSLATOR_VERBOSITY=level`来设置日志详细等级,并查看不同等级的日志信息。目前,`level`可以取值0-3: +您可以调用 [`paddle.jit.set_verbosity(level)`]((../../../paddle/api/paddle/fluid/dygraph/jit/set_verbosity_cn.html)) 或设置环境变量 `TRANSLATOR_VERBOSITY=level` 来设置日志详细等级,并查看不同等级的日志信息。目前,`level` 可以取值0-3: - 0: 无日志 - 1: 包括了动转静转化流程的信息,如转换前的源码、转换的可调用对象 - 2: 包括以上信息,还包括更详细函数转化日志 @@ -177,11 +178,11 @@ ProgramTranslator在日志中记录了额外的调试信息,以帮助您了解 > > 日志中包括了源代码等信息,请在共享日志前确保它不包含敏感信息。 -可以在代码运行前调用`paddle.jit.set_verbosity`控制日志详细程度: +可以在代码运行前调用 `paddle.jit.set_verbosity` 控制日志详细程度: ```python paddle.jit.set_verbosity(3) ``` -或者设置环境变量`TRANSLATOR_VERBOSITY`: +或者设置环境变量 `TRANSLATOR_VERBOSITY`: ```python import os os.environ["TRANSLATOR_VERBOSITY"] = '3' diff --git a/doc/fluid/advanced_guide/dygraph_to_static/debugging_en.md b/doc/fluid/advanced_guide/dygraph_to_static/debugging_en.md index 08d0a8bb869a444cc5231c0d875de4aabea2e592..2ca87c976b0a9fc30dc588d1b4a8f814463f42de 100644 --- a/doc/fluid/advanced_guide/dygraph_to_static/debugging_en.md +++ b/doc/fluid/advanced_guide/dygraph_to_static/debugging_en.md @@ -71,7 +71,9 @@ func(np.ones([3, 2])) There are two ways to print the transformed static graph code: -1. Use the attribute `code` of the decorated function: +1. Use the attribute `code` of the decorated function + + In the following code, the decorator `paddle.jit.to_static` transforms `func` into a class object `StaticLayer`. You can use the `code` attribute of `StaticLayer` to get the transformed code. ```Python @paddle.jit.to_static def func(x): @@ -128,7 +130,7 @@ 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]()。 + `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`. @@ -166,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)` 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)`](../../../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 diff --git a/doc/fluid/advanced_guide/dygraph_to_static/error_handling_cn.md b/doc/fluid/advanced_guide/dygraph_to_static/error_handling_cn.md index cb322356c89795bf5851ae84b19aadb4816a6d87..bb92cb80aa7a2485e2203177be2b3a4813602d91 100644 --- a/doc/fluid/advanced_guide/dygraph_to_static/error_handling_cn.md +++ b/doc/fluid/advanced_guide/dygraph_to_static/error_handling_cn.md @@ -4,7 +4,7 @@ ## 动转静过程中的异常 在动态图代码转换成静态图代码的过程中,如果ProgramTranslator无法转换一个函数时,将会显示警告信息,并尝试直接运行该函数。 -如下代码中,函数`inner_func` 在调用前被转换成静态图代码,当`x=inner_func(data)`调用该函数时,不能重复转换,会给出警告信息: +如下代码中,函数 `inner_func` 在调用前被转换成静态图代码,当 `x = inner_func(data)` 调用该函数时,不能重复转换,会给出警告信息: ```python import paddle @@ -31,7 +31,7 @@ WARNING: doesn't have to be transformed ## 运行转换后的代码报错 -如果在动转静后的静态图代码中发生异常,ProgramTranslator会捕获该异常,增强异常报错信息,将静态图代码报错行映射到转换前的动态图代码,并重新抛出该异常。 +如果在动转静后的静态图代码中发生异常,ProgramTranslator 会捕获该异常,增强异常报错信息,将静态图代码报错行映射到转换前的动态图代码,并重新抛出该异常。 重新抛出的异常具有以下特点: - 隐藏了部分对用户无用的动转静过程调用栈; @@ -157,4 +157,4 @@ InvalidArgumentError: The 'shape' in ReshapeOp is invalid. The input tensor X'si [operator < reshape2 > error] [operator < run_program > error] ``` -上述异常中,除了隐藏部分报错栈、报错定位到转换前的动态图代码外,报错信息中包含了C++报错栈`C++ Traceback`和`Error Message Summary`,这是Paddle的C++端异常信息,经处理后在Python的异常信息中显示。 +上述异常中,除了隐藏部分报错栈、报错定位到转换前的动态图代码外,报错信息中包含了C++报错栈 `C++ Traceback` 和 `Error Message Summary`,这是 Paddle 的 C++ 端异常信息,经处理后在 Python 的异常信息中显示。 diff --git a/doc/fluid/advanced_guide/dygraph_to_static/error_handling_en.md b/doc/fluid/advanced_guide/dygraph_to_static/error_handling_en.md index bb474551215f75705c22acd3853985d45450ab6d..22c9eb8b37a93c68c0e20a83844be14a560bd6a7 100644 --- a/doc/fluid/advanced_guide/dygraph_to_static/error_handling_en.md +++ b/doc/fluid/advanced_guide/dygraph_to_static/error_handling_en.md @@ -1,13 +1,13 @@ # Error Handling This section will introduce the error information when an exception occurs, so as to help you better understand the Dynamic-to-Static error information. -When running the transformed static graph code, the internal can be divided into two steps: the dynamic graph code is transformed into the static graph code, and the static graph code is run. We will introduce the error reporting in these two steps. +When running the transformed static graph code, the internal procedure can be divided into two steps: the dynamic graph code is transformed into the static graph code, and the static graph code is run. We will introduce the error reporting in these two steps. ## Exceptions in Dynamic-to-Static Transformation If ProgramTranslator cannot transform a function, it will display a warning message and try to run the function as-is. -In the following code, the function `inner_func` is transformed before calling. When calling `inner_func` in `x=inner_func(data)`, it is not allowed to transform repeatedly, and a warning message will be given: +In the following code, the function `inner_func` is transformed before calling. When calling `inner_func` in `x = inner_func(data)`, it is not allowed to transform repeatedly, and a warning message will be given: ```python import paddle @@ -32,12 +32,12 @@ WARNING: doesn't have to be transformed ``` ## Exceptions in Running Transformed Code -When an exception occurs in the transformed code by ProgramTranslator, the exception is be catched and the error message is augmented. It maps the error line of the static graph code to the dynamic graph code un-transformed, and then re-raise the exception. +When an exception occurs in the transformed code by ProgramTranslator, the exception is caught and the error message is augmented. It maps the error line of the static graph code to the un-transformed dynamic graph code, and then re-raises the exception. Among the features of the re-raised exception: - Some useless call stacks of Dynamic-to-Static are hidden; -- A prompt will be given before the code un-transformed: "In User Code:"; +- A prompt will be given before the un-transformed code: "In User Code:"; - The error message includes references to the original dynamic graph code before transformation; For example, if executing the following code, an exception is raised when the static graph is built, that is, at compile time: @@ -90,14 +90,14 @@ The above error information can be divided into three points: File "paddle/fluid/layers/nn.py", line 6169, in get_attr_shape "be -1. But received shape[%d] is also -1." % dim_idx) ``` - `File "", line 7, in func` is the location information of un-transformed code, `x = fluid.layers.reshape(x, shape=[-1, -1])` is the code un-transformed. + `File "", line 7, in func` is the location information of un-transformed code, `x = fluid.layers.reshape(x, shape=[-1, -1])` is the un-transformed code. 3. The new exception contains the message that the exception originally reported, as follows: ```bash AssertionError: Only one dimension value of 'shape' in reshape can be -1. But received shape[1] is also -1. ``` -If executing the following code, an exception is raised when the static graph is executed, that is, at runtime: +If execute the following code, an exception is raised when the static graph is executed at runtime: ```Python @paddle.jit.to_static @@ -157,4 +157,4 @@ InvalidArgumentError: The 'shape' in ReshapeOp is invalid. The input tensor X'si [operator < reshape2 > error] [operator < run_program > error] ``` -In the above exception, in addition to hiding part of the error stack and locating the error to the dynamic graph code un-transformed, 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. +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. diff --git a/doc/paddle/guides/dygraph_to_static/debugging_cn.md b/doc/paddle/guides/dygraph_to_static/debugging_cn.md index 7fa3e7e462648f5aef51da11294c51661d18fd09..40bc3e002eadc30f03383cf4d262931179001322 100644 --- a/doc/paddle/guides/dygraph_to_static/debugging_cn.md +++ b/doc/paddle/guides/dygraph_to_static/debugging_cn.md @@ -4,7 +4,7 @@ > **注解:** > -> 请确保转换前的动态图代码能够成功运行,建议使用[paddle.jit.ProgramTranslator().enable(False)](../../api_cn/dygraph_cn/ProgramTranslator_cn.html#enable)关闭动转静功能,直接运行动态图,如下: +> 请确保转换前的动态图代码能够成功运行,建议使用 [paddle.jit.ProgramTranslator().enable(False)](../../api_cn/dygraph_cn/ProgramTranslator_cn.html#enable)关闭动转静功能,直接运行动态图,如下: ```python import paddle @@ -25,7 +25,7 @@ func(np.ones([3, 2])) ## 断点调试 使用动转静功能时,您可以使用断点调试代码。 -例如,在代码中,调用`pdb.set_trace()`: +例如,在代码中,调用 `pdb.set_trace()`: ```Python import pdb @@ -52,7 +52,7 @@ func(np.ones([3, 2])) ... ``` -如果您想在原始的动态图代码中使用调试器,请先调用[`paddle.jit.ProgramTranslator().enable(False)`](../../api_cn/dygraph_cn/ProgramTranslator_cn.html#enable),如下: +如果您想在原始的动态图代码中使用调试器,请先调用 [`paddle.jit.ProgramTranslator().enable(False)`](../../api_cn/dygraph_cn/ProgramTranslator_cn.html#enable),如下: ```python paddle.jit.ProgramTranslator().enable(False) func(np.ones([3, 2])) @@ -68,7 +68,8 @@ func(np.ones([3, 2])) ## 打印转换后的代码 您可以打印转换后的静态图代码,有2种方法: -1. 使用被装饰函数的`code` 属性 +1. 使用被装饰后的函数的 `code` 属性 + 如下代码中,装饰器 `paddle.jit.to_static` 会将函数 `func` 转化为一个类对象 `StaticLayer`,可以使用 StaticLayer 的 `code` 属性来获得转化后的代码。 ```Python @paddle.jit.to_static def func(x): @@ -97,9 +98,9 @@ func(np.ones([3, 2])) return x ``` -2. 使用`set_code_level(level)`或环境变量`TRANSLATOR_CODE_LEVEL=level` +2. 使用 `set_code_level(level)` 或环境变量 `TRANSLATOR_CODE_LEVEL=level` - 通过调用`set_code_level`或设置环境变量`TRANSLATOR_CODE_LEVEL`,可以在log中查看转换后的代码: + 通过调用 `set_code_level` 或设置环境变量 `TRANSLATOR_CODE_LEVEL`,可以在日志中查看转换后的代码: ```python @paddle.jit.to_static @@ -129,10 +130,10 @@ func(np.ones([3, 2])) 3, true_fn_0, false_fn_0, (x,), (x,), (x,)) return x ``` - `set_code_level` 函数可以设置查看不同的AST Transformer转化后的代码,详情请见[set_code_level]()。 + `set_code_level` 函数可以设置查看不同的AST Transformer转化后的代码,详情请见 [set_code_level](../../../paddle/api/paddle/fluid/dygraph/jit/set_code_level_cn.html)。 ## 使用 `print` -`print` 函数可以用来查看变量,该函数在动转静中会被转化。当仅打印Paddle Tensor时,实际运行时会被转换为Paddle算子[Print](../../api_cn/layers_cn/Print_cn.html),否则仍然运行`print`。 +`print` 函数可以用来查看变量,该函数在动转静中会被转化。当仅打印 Paddle Tensor 时,实际运行时会被转换为 Paddle 算子 [Print](../../api_cn/layers_cn/Print_cn.html),否则仍然运行 `print`。 ```python @paddle.jit.to_static def func(x): @@ -167,7 +168,7 @@ Here call print function. ## 日志打印 ProgramTranslator在日志中记录了额外的调试信息,以帮助您了解动转静过程中函数是否被成功转换。 -您可以调用`paddle.jit.set_verbosity(level)` 或设置环境变量`TRANSLATOR_VERBOSITY=level`来设置日志详细等级,并查看不同等级的日志信息。目前,`level`可以取值0-3: +您可以调用 [`paddle.jit.set_verbosity(level)`]((../../../paddle/api/paddle/fluid/dygraph/jit/set_verbosity_cn.html)) 或设置环境变量 `TRANSLATOR_VERBOSITY=level` 来设置日志详细等级,并查看不同等级的日志信息。目前,`level` 可以取值0-3: - 0: 无日志 - 1: 包括了动转静转化流程的信息,如转换前的源码、转换的可调用对象 - 2: 包括以上信息,还包括更详细函数转化日志 @@ -177,11 +178,11 @@ ProgramTranslator在日志中记录了额外的调试信息,以帮助您了解 > > 日志中包括了源代码等信息,请在共享日志前确保它不包含敏感信息。 -可以在代码运行前调用`paddle.jit.set_verbosity`控制日志详细程度: +可以在代码运行前调用 `paddle.jit.set_verbosity` 控制日志详细程度: ```python paddle.jit.set_verbosity(3) ``` -或者设置环境变量`TRANSLATOR_VERBOSITY`: +或者设置环境变量 `TRANSLATOR_VERBOSITY`: ```python import os os.environ["TRANSLATOR_VERBOSITY"] = '3' diff --git a/doc/paddle/guides/dygraph_to_static/debugging_en.md b/doc/paddle/guides/dygraph_to_static/debugging_en.md index 08d0a8bb869a444cc5231c0d875de4aabea2e592..2ca87c976b0a9fc30dc588d1b4a8f814463f42de 100644 --- a/doc/paddle/guides/dygraph_to_static/debugging_en.md +++ b/doc/paddle/guides/dygraph_to_static/debugging_en.md @@ -71,7 +71,9 @@ func(np.ones([3, 2])) There are two ways to print the transformed static graph code: -1. Use the attribute `code` of the decorated function: +1. Use the attribute `code` of the decorated function + + In the following code, the decorator `paddle.jit.to_static` transforms `func` into a class object `StaticLayer`. You can use the `code` attribute of `StaticLayer` to get the transformed code. ```Python @paddle.jit.to_static def func(x): @@ -128,7 +130,7 @@ 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]()。 + `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`. @@ -166,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)` 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)`](../../../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 diff --git a/doc/paddle/guides/dygraph_to_static/error_handling_cn.md b/doc/paddle/guides/dygraph_to_static/error_handling_cn.md index cb322356c89795bf5851ae84b19aadb4816a6d87..bb92cb80aa7a2485e2203177be2b3a4813602d91 100644 --- a/doc/paddle/guides/dygraph_to_static/error_handling_cn.md +++ b/doc/paddle/guides/dygraph_to_static/error_handling_cn.md @@ -4,7 +4,7 @@ ## 动转静过程中的异常 在动态图代码转换成静态图代码的过程中,如果ProgramTranslator无法转换一个函数时,将会显示警告信息,并尝试直接运行该函数。 -如下代码中,函数`inner_func` 在调用前被转换成静态图代码,当`x=inner_func(data)`调用该函数时,不能重复转换,会给出警告信息: +如下代码中,函数 `inner_func` 在调用前被转换成静态图代码,当 `x = inner_func(data)` 调用该函数时,不能重复转换,会给出警告信息: ```python import paddle @@ -31,7 +31,7 @@ WARNING: doesn't have to be transformed ## 运行转换后的代码报错 -如果在动转静后的静态图代码中发生异常,ProgramTranslator会捕获该异常,增强异常报错信息,将静态图代码报错行映射到转换前的动态图代码,并重新抛出该异常。 +如果在动转静后的静态图代码中发生异常,ProgramTranslator 会捕获该异常,增强异常报错信息,将静态图代码报错行映射到转换前的动态图代码,并重新抛出该异常。 重新抛出的异常具有以下特点: - 隐藏了部分对用户无用的动转静过程调用栈; @@ -157,4 +157,4 @@ InvalidArgumentError: The 'shape' in ReshapeOp is invalid. The input tensor X'si [operator < reshape2 > error] [operator < run_program > error] ``` -上述异常中,除了隐藏部分报错栈、报错定位到转换前的动态图代码外,报错信息中包含了C++报错栈`C++ Traceback`和`Error Message Summary`,这是Paddle的C++端异常信息,经处理后在Python的异常信息中显示。 +上述异常中,除了隐藏部分报错栈、报错定位到转换前的动态图代码外,报错信息中包含了C++报错栈 `C++ Traceback` 和 `Error Message Summary`,这是 Paddle 的 C++ 端异常信息,经处理后在 Python 的异常信息中显示。 diff --git a/doc/paddle/guides/dygraph_to_static/error_handling_en.md b/doc/paddle/guides/dygraph_to_static/error_handling_en.md index bb474551215f75705c22acd3853985d45450ab6d..22c9eb8b37a93c68c0e20a83844be14a560bd6a7 100644 --- a/doc/paddle/guides/dygraph_to_static/error_handling_en.md +++ b/doc/paddle/guides/dygraph_to_static/error_handling_en.md @@ -1,13 +1,13 @@ # Error Handling This section will introduce the error information when an exception occurs, so as to help you better understand the Dynamic-to-Static error information. -When running the transformed static graph code, the internal can be divided into two steps: the dynamic graph code is transformed into the static graph code, and the static graph code is run. We will introduce the error reporting in these two steps. +When running the transformed static graph code, the internal procedure can be divided into two steps: the dynamic graph code is transformed into the static graph code, and the static graph code is run. We will introduce the error reporting in these two steps. ## Exceptions in Dynamic-to-Static Transformation If ProgramTranslator cannot transform a function, it will display a warning message and try to run the function as-is. -In the following code, the function `inner_func` is transformed before calling. When calling `inner_func` in `x=inner_func(data)`, it is not allowed to transform repeatedly, and a warning message will be given: +In the following code, the function `inner_func` is transformed before calling. When calling `inner_func` in `x = inner_func(data)`, it is not allowed to transform repeatedly, and a warning message will be given: ```python import paddle @@ -32,12 +32,12 @@ WARNING: doesn't have to be transformed ``` ## Exceptions in Running Transformed Code -When an exception occurs in the transformed code by ProgramTranslator, the exception is be catched and the error message is augmented. It maps the error line of the static graph code to the dynamic graph code un-transformed, and then re-raise the exception. +When an exception occurs in the transformed code by ProgramTranslator, the exception is caught and the error message is augmented. It maps the error line of the static graph code to the un-transformed dynamic graph code, and then re-raises the exception. Among the features of the re-raised exception: - Some useless call stacks of Dynamic-to-Static are hidden; -- A prompt will be given before the code un-transformed: "In User Code:"; +- A prompt will be given before the un-transformed code: "In User Code:"; - The error message includes references to the original dynamic graph code before transformation; For example, if executing the following code, an exception is raised when the static graph is built, that is, at compile time: @@ -90,14 +90,14 @@ The above error information can be divided into three points: File "paddle/fluid/layers/nn.py", line 6169, in get_attr_shape "be -1. But received shape[%d] is also -1." % dim_idx) ``` - `File "", line 7, in func` is the location information of un-transformed code, `x = fluid.layers.reshape(x, shape=[-1, -1])` is the code un-transformed. + `File "", line 7, in func` is the location information of un-transformed code, `x = fluid.layers.reshape(x, shape=[-1, -1])` is the un-transformed code. 3. The new exception contains the message that the exception originally reported, as follows: ```bash AssertionError: Only one dimension value of 'shape' in reshape can be -1. But received shape[1] is also -1. ``` -If executing the following code, an exception is raised when the static graph is executed, that is, at runtime: +If execute the following code, an exception is raised when the static graph is executed at runtime: ```Python @paddle.jit.to_static @@ -157,4 +157,4 @@ InvalidArgumentError: The 'shape' in ReshapeOp is invalid. The input tensor X'si [operator < reshape2 > error] [operator < run_program > error] ``` -In the above exception, in addition to hiding part of the error stack and locating the error to the dynamic graph code un-transformed, 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. +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. diff --git a/doc/paddle/guides/dygraph_to_static/index_cn.rst b/doc/paddle/guides/dygraph_to_static/index_cn.rst index a28d37767b4f3c3e894b303fb6f796dca360bc4e..9700ce66dfb2c15b46ae0a235ad3a89a4d0a1da4 100644 --- a/doc/paddle/guides/dygraph_to_static/index_cn.rst +++ b/doc/paddle/guides/dygraph_to_static/index_cn.rst @@ -8,7 +8,7 @@ - `InputSpec功能介绍 `_ :介绍了动态图转静态图指定输入InputSpec的功能和用法 -- `报错信息处理 `_ :介绍了动态图转静态图支持的报错信息处理方法 +- `报错信息处理 `_ :介绍了动态图转静态图的报错信息处理方法 - `调试方法 `_ :介绍了动态图转静态图支持的调试方法 diff --git a/doc/paddle/guides/dygraph_to_static/index_en.rst b/doc/paddle/guides/dygraph_to_static/index_en.rst index ede13c0ea05e5cb6248bfc6c28a88eb33e864b1c..209af0f4fc45f02eca70a1efa86b19ded3e74908 100644 --- a/doc/paddle/guides/dygraph_to_static/index_en.rst +++ b/doc/paddle/guides/dygraph_to_static/index_en.rst @@ -12,6 +12,10 @@ Dygraph to Static Graph - `Debugging Methods `_ :Introduce the debugging methods when using ProgramTranslator. +- `Error Handling `_ :Introduce the error handling by ProgramTranslator. + +- `Debugging Methods `_ :Introduce the debugging methods when using ProgramTranslator. + .. toctree:: :hidden: @@ -20,4 +24,3 @@ Dygraph to Static Graph input_spec_en.rst error_handling_en.md debugging_en.md -