Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

executor.run的fetch_list如果直接给Variable。运行会hang住。

Open Meiyim opened this issue 7 years ago • 4 comments

executor.run的fetch_list如果没有指定python list,而是Variable。运行会hang住。用户体验很奇怪。建议给这个函数(包括其他paddle的API)加上更完善的参数类型检查。

另外加一个 feature_request: 希望fetch_list时候能支持 dict, list, tuple, namedtuple, list of dict等复杂结构。参考tf.Session.run的fetches参数。

  • 问题描述:请详细描述您的问题,同步贴出报错信息、日志、可复现的代码片段
import numpy as np

import multiprocessing as mp
import paddle
import paddle.fluid  as F
import paddle.fluid.layers  as L
from time import sleep


train_program = F.Program()
startup_prog = F.Program()
with F.program_guard(train_program, startup_prog):
    with F.unique_name.guard():
        inputs = L.data(name='in', shape=[-1, 10], dtype='int64')
        loss = inputs + 1

place = F.CUDAPlace(0)
start_exe = F.Executor(place)
train_exe = F.Executor(place)
start_exe.run(startup_prog)

print(paddle.__version__)
for _ in range(10):
    print(train_exe.run(train_program, fetch_list=loss, feed={inputs.name: np.ones([3,10], dtype=np.int64)}))

output:

W0507 15:32:50.906225 226435 device_context.cc:261] Please NOTE: device: 0, CUDA Capability: 61, Driver API Version: 10.0, Runtime API Version: 9.0
W0507 15:32:50.910995 226435 device_context.cc:269] device: 0, cuDNN Version: 7.0.
1.4.1

Meiyim avatar May 07 '19 07:05 Meiyim

感谢指出,我们会首先对fetch_list进行格式检查。

luotao1 avatar May 07 '19 07:05 luotao1

补充一个,exe.run如果缺少program参数,也会死循环,hang住。

CAOYUHUI avatar May 07 '19 09:05 CAOYUHUI

在evaluate的时候使用exe.run,如果缺少program参数,会死循环,加入program后正常运行。 evaluate部分的代码

def evaluate(exe, test_program, test_pyreader, fetch_list, steps):
    test_pyreader.start()
    total_cost, total_acc, total_num_seqs = [], [], []
    time_begin = time.time()
    while True:
        try:
            np_loss, np_acc, np_num_seqs = exe.run(fetch_list=fetch_list, program=test_program)
            total_cost.extend(np_loss * np_num_seqs)
            total_acc.extend(np_acc * np_num_seqs)
            total_num_seqs.extend(np_num_seqs)
        except fluid.core.EOFException:
            test_pyreader.reset()
            break
    time_end = time.time()
    print("[evaluation] steps: %d, ave loss: %f, ave_acc: %f, ave_pnr: %f,lapsed time: %f s" %
          (steps, np.sum(total_cost) / np.sum(total_num_seqs),
           np.sum(total_acc) / np.sum(total_num_seqs),
           np.sum(total_acc) / (np.sum(total_num_seqs) - np.sum(total_acc)),
           time_end - time_begin))

CAOYUHUI avatar May 07 '19 09:05 CAOYUHUI

感谢您的反馈。

补充一个,exe.run如果缺少program参数,也会死循环,hang住。

如果不传入program,程序将会使用fluid.default_main_program()。所以对于您的模型,如果不传入program是会有问题的。

chengduoZH avatar Aug 01 '19 06:08 chengduoZH