From 2fff09202cb62fa76450f6e5458dd2f01220df9f Mon Sep 17 00:00:00 2001 From: OccupyMars2025 <31559413+OccupyMars2025@users.noreply.github.com> Date: Fri, 26 Aug 2022 11:00:44 +0800 Subject: [PATCH] modify something (#5188) * Update basic_usage_cn.md * Update basic_usage_cn.md * Update principle_cn.md delete duplicate use of to_static * Update principle_cn.md --- docs/guides/jit/basic_usage_cn.md | 5 +++-- docs/guides/jit/principle_cn.md | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/guides/jit/basic_usage_cn.md b/docs/guides/jit/basic_usage_cn.md index 8e317ed414b..7d0518c1a9a 100644 --- a/docs/guides/jit/basic_usage_cn.md +++ b/docs/guides/jit/basic_usage_cn.md @@ -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() # 设置优化器 diff --git a/docs/guides/jit/principle_cn.md b/docs/guides/jit/principle_cn.md index d0c7c94df9c..f0f21194613 100644 --- a/docs/guides/jit/principle_cn.md +++ b/docs/guides/jit/principle_cn.md @@ -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 @@ -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)。