提交 b3305fde 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!28 update pynative example code

Merge pull request !28 from wangqiuliang/update-pynative-example-code
......@@ -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).
......@@ -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的方式对网络进行调试。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册