M
在while_op中使用`=`赋值,期望每轮更新结果,但实际只运行一次;期望能够更详细说明while_op的正确用法
memeda 发布于2020-02-12 11:27 浏览:303 回复:2
0
收藏
  • 标题:
    在while_op中使用=赋值,期望每轮更新结果,但实际只运行一次;
    期望能够更详细说明while_op的正确用法
  • 版本、环境信息:
       1)PaddlePaddle版本:1.6.1
       2)CPU/GPU:CUDA 10.1, cuDNN 7.0
       3)系统环境:CentOS 7.7
       4)Python版本号: 3.7.4
       5)显存信息: 32G
  • 复现信息:
import paddle.fluid as fluid


target_spos = fluid.layers.fill_constant(shape=[1], value=100, dtype="int32")
step_idx = fluid.layers.fill_constant(shape=[1], value=0, dtype="int64")
max_len = fluid.layers.fill_constant(shape=[1], value=3, dtype="int64")
cond = fluid.layers.less_than(x=step_idx, y=max_len)

while_op = fluid.layers.While(cond)

with while_op.block():
    decode_position = target_spos + step_idx

    fluid.layers.Print(step_idx)
    fluid.layers.Print(decode_position)

    fluid.layers.increment(x=step_idx, value=1, in_place=True)
    fluid.layers.less_than(x=step_idx, y=max_len, cond=cond)

exe = fluid.Executor(fluid.CUDAPlace(0))
exe.run(fluid.default_startup_program())
exe.run(fluid.default_main_program())
  • 问题描述:
  1. decode_position一直为100, 而step_idx正常累加
  2. 能否给while_op更多的说明,防止踩坑(譬如,是否只能用layers.assign, increment这些来赋值)
收藏
点赞
0
个赞
共2条回复 最后由_我只是打杂的回复于2020-04-27 11:08
#3_我只是打杂的回复于2020-04-27 11:08:41

我用1.7版本的,也遇到这个问题,完全搞不懂

0
C
#2chenwhql回复于2020-02-12 11:54:35

您好:

  1. 我在develop分支的paddle版本上尝试了您的代码,执行没有问题,所以这应该是1.6.1版本的一个bug,应该目前已经修复了,你也可以用新的版本尝试验证一下,我的结果如下:
grep: warning: GREP_OPTIONS is deprecated; please use an alias or script
/usr/local/lib/python3.5/dist-packages/paddle/fluid/executor.py:804: UserWarning: There are no operators in the program to be executed. If you pass Program manually, please use fluid.program_guard to ensure the current Program is being used.
  warnings.warn(error_info)
W0212 03:51:06.340605  2433 device_context.cc:237] Please NOTE: device: 0, CUDA Capability: 61, Driver API Version: 10.1, Runtime API Version: 10.0
W0212 03:51:06.348084  2433 device_context.cc:245] device: 0, cuDNN Version: 7.5.
1581479468		The place is:CUDAPlace(0)
Tensor[fill_constant_1.tmp_0]
	shape: [1,]
	dtype: l
	data: 0,
1581479468		The place is:CUDAPlace(0)
Tensor[tmp_1]
	shape: [1,]
	dtype: i
	data: 100,
1581479468		The place is:CUDAPlace(0)
Tensor[fill_constant_1.tmp_0]
	shape: [1,]
	dtype: l
	data: 1,
1581479468		The place is:CUDAPlace(0)
Tensor[tmp_1]
	shape: [1,]
	dtype: i
	data: 101,
1581479468		The place is:CUDAPlace(0)
Tensor[fill_constant_1.tmp_0]
	shape: [1,]
	dtype: l
	data: 2,
1581479468		The place is:CUDAPlace(0)
Tensor[tmp_1]
	shape: [1,]
	dtype: i
	data: 102,
  1. 文档方面,我会反馈给相关同学补充更多的示例,感谢反馈意见!
0
TOP
切换版块