From 82ae85e9f2583dd708638c4313a7d626cb15b715 Mon Sep 17 00:00:00 2001 From: kingfo Date: Tue, 14 Apr 2020 11:51:14 +0800 Subject: [PATCH] update pynative example code --- .../source_en/use/debugging_in_pynative_mode.md | 13 +++++-------- .../source_zh_cn/use/debugging_in_pynative_mode.md | 12 +++++------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/tutorials/source_en/use/debugging_in_pynative_mode.md b/tutorials/source_en/use/debugging_in_pynative_mode.md index 66a7d9f0a1..d573a11c2a 100644 --- a/tutorials/source_en/use/debugging_in_pynative_mode.md +++ b/tutorials/source_en/use/debugging_in_pynative_mode.md @@ -99,7 +99,7 @@ print(output.asnumpy()) [3. 3. 3.]] ``` - +> Parallel execution and summary is not supported in PyNative mode, so parallel and summary related operators can not be used. ### Improving PyNative Performance @@ -273,14 +273,11 @@ During network training, obtain the gradient, call the optimizer to optimize par import numpy as np import mindspore.nn as nn import mindspore.ops.operations as P -from mindspore.nn import Dense -from mindspore import context, Tensor, ParameterTuple -from mindspore.common.initializer import TruncatedNormal from mindspore.ops import composite as C from mindspore.common import dtype as mstype -from mindspore.nn.wrap.cell_wrapper import WithLossCell -from mindspore.nn.loss import SoftmaxCrossEntropyWithLogits -from mindspore.nn.optim import Momentum +from mindspore import context, Tensor, ParameterTuple +from mindspore.common.initializer import TruncatedNormal +from mindspore.nn import Dense, WithLossCell, SoftmaxCrossEntropyWithLogits, Momentum context.set_context(mode=context.PYNATIVE_MODE, device_target="GPU") @@ -377,4 +374,4 @@ print(loss) 2.3050091 ``` -In the preceding execution, an intermediate result of network execution can be obtained at any required place in construct function, and the network can be debugged by using the Python Debugger (pdb). \ No newline at end of file +In the preceding execution, an intermediate result of network execution can be obtained at any required place in construct function, and the network can be debugged by using the Python Debugger (pdb). diff --git a/tutorials/source_zh_cn/use/debugging_in_pynative_mode.md b/tutorials/source_zh_cn/use/debugging_in_pynative_mode.md index 3967bb5407..0357e8fb3e 100644 --- a/tutorials/source_zh_cn/use/debugging_in_pynative_mode.md +++ b/tutorials/source_zh_cn/use/debugging_in_pynative_mode.md @@ -99,6 +99,7 @@ print(output.asnumpy()) [3. 3. 3.]] ``` +> PyNative不支持并行执行和summary功能,图模式的并行和summary相关算子不能使用。 ### 提升PyNative性能 @@ -272,14 +273,11 @@ print(mainf(1,2)) import numpy as np import mindspore.nn as nn import mindspore.ops.operations as P -from mindspore.nn import Dense -from mindspore import context, Tensor, ParameterTuple -from mindspore.common.initializer import TruncatedNormal from mindspore.ops import composite as C from mindspore.common import dtype as mstype -from mindspore.nn.wrap.cell_wrapper import WithLossCell -from mindspore.nn.loss import SoftmaxCrossEntropyWithLogits -from mindspore.nn.optim import Momentum +from mindspore import context, Tensor, ParameterTuple +from mindspore.common.initializer import TruncatedNormal +from mindspore.nn import Dense, WithLossCell, SoftmaxCrossEntropyWithLogits, Momentum context.set_context(mode=context.PYNATIVE_MODE, device_target="GPU") @@ -376,4 +374,4 @@ print(loss) 2.3050091 ``` -上述执行方式中,可以在construct函数任意需要的地方设置断点,获取网络执行的中间结果,通过pdb的方式对网络进行调试。 \ No newline at end of file +上述执行方式中,可以在`construct`函数任意需要的地方设置断点,获取网络执行的中间结果,通过pdb的方式对网络进行调试。 -- Gitee