Skip to content

Commit

Permalink
modify something (PaddlePaddle#5188)
Browse files Browse the repository at this point in the history
* Update basic_usage_cn.md

* Update basic_usage_cn.md

* Update principle_cn.md

delete duplicate use of to_static

* Update principle_cn.md
  • Loading branch information
OccupyMars2025 authored Aug 26, 2022
1 parent c69c327 commit 2fff092
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions docs/guides/jit/basic_usage_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -964,17 +964,18 @@ paddle.jit.save(net, path='./simple_net')
print("Epoch {} batch {}: loss = {}".format(
epoch_id, batch_id, np.mean(loss.numpy())))

def set_build_strategy():
def get_build_strategy():
build_strategy = paddle.static.BuildStrategy()
# addto 策略常搭配 FLAGS_max_inplace_grad_add 变量使用
build_strategy.enable_addto = True
os.environ['FLAGS_max_inplace_grad_add'] = "8"
build_strategy.fuse_elewise_add_act_ops = True
return build_strategy

# 构建神经网络
model = resnet50()
# 动转静,并设置计算图优化策略
model = paddle.jit.to_static(model, build_strategy=set_build_strategy())
model = paddle.jit.to_static(model, build_strategy=get_build_strategy())
# 设置损失函数
loss_fn = nn.CrossEntropyLoss()
# 设置优化器
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/jit/principle_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ out = paddle.add(out, y)
```python
import paddle
from paddle.jit import to_static
from paddle.static import InputSpec

class SimpleNet(paddle.nn.Layer):
def __init__(self):
super(SimpleNet, self).__init__()
self.linear = paddle.nn.Linear(10, 3)

@to_static
def forward(self, x, y):
out = self.linear(x)
out = out + y
Expand All @@ -88,7 +88,7 @@ net = paddle.jit.to_static(net, input_spec=[x_spec, y_spec]) # 动静转换


+ 可以指定某些维度为 ``None`` , 如 ``batch_size````seq_len`` 维度
+ 可以指定 Placeholder 的 ``name``方面预测时根据 ``name`` 输入数据
+ 可以指定 Placeholder 的 ``name``方便预测时根据 ``name`` 输入数据

> 注:``InputSpec`` 接口的详细用法,请参见 [InputSpec 的用法介绍](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/jit/basic_usage_cn.html#inputspec)
Expand Down

0 comments on commit 2fff092

Please sign in to comment.