Skip to content

  • 体验新版
    • 正在加载...
  • 登录
  • PaddlePaddle
  • Paddle
  • Issue
  • #21772

P
Paddle
  • 项目概览

PaddlePaddle / Paddle
大约 2 年 前同步成功

通知 2325
Star 20933
Fork 5424
  • 代码
    • 文件
    • 提交
    • 分支
    • Tags
    • 贡献者
    • 分支图
    • Diff
  • Issue 1423
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 543
  • Wiki 0
    • Wiki
  • 分析
    • 仓库
    • DevOps
  • 项目成员
  • Pages
P
Paddle
  • 项目概览
    • 项目概览
    • 详情
    • 发布
  • 仓库
    • 仓库
    • 文件
    • 提交
    • 分支
    • 标签
    • 贡献者
    • 分支图
    • 比较
  • Issue 1,423
    • Issue 1,423
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 543
    • 合并请求 543
  • Pages
  • 分析
    • 分析
    • 仓库分析
    • DevOps
  • Wiki 0
    • Wiki
  • 成员
    • 成员
  • 收起侧边栏
  • 动态
  • 分支图
  • 创建新Issue
  • 提交
  • Issue看板
已关闭
开放中
Opened 12月 16, 2019 by saxon_zh@saxon_zhGuest

tensor array 赋值错误

Created by: Angus07

我用fluid.layers.create_array(dtype='float32')建立了一个array 在 with while_op.block() 循环中赋值: layers.array_write(weights, i=step_idx, array=weights_array) 并且这时候确保是有数据的(打印出来看过了) 但是在循环结束后,我尝试读取或操作这个array,比如 step_idx = layers.fill_constant( shape=[1], dtype=tgt_ids.dtype, value=0, force_cpu=True) weight_debug = layers.array_read(weights_array, i=step_idx) layers.Print(weight_debug, message="weights_debug", summarize=100) 就报错了,报错信息如下,极大概率是整个array 都是空的:

Error Message Summary:

PaddleCheckError: holder_ should not be null Tensor holds no memory. Call Tensor::mutable_data first. at [/paddle/paddle/fluid/framework/tensor.cc:23] [operator < read_from_array > error]


详情代码如下: weights_array = fluid.layers.create_array(dtype='float32') global_src_id = src_ids with while_op.block(): pre_ids = layers.array_read(array=ids, i=step_idx) pre_ids = layers.reshape(pre_ids, (-1, 1, 1), inplace=True) pre_scores = layers.array_read(array=scores, i=step_idx)

    tmp_tgt_input_mask = layers.array_read(tgt_masks, i=step_idx)
    tmp_tgt_input_mask_encoder = layers.array_read(tgt_masks_encoder, i=step_idx)
    append_mask = layers.fill_constant_batch_size_like(
            input=tmp_tgt_input_mask,
            value=1.0,
            shape=[-1, 1, 1],
            dtype=tmp_tgt_input_mask.dtype)
    append_mask_encoder = layers.fill_constant_batch_size_like(
            input=tmp_tgt_input_mask,
            value=0.0,
            shape=[-1, 1, 1],
            dtype=tmp_tgt_input_mask.dtype)
    tmp_tgt_input_mask = layers.concat([tmp_tgt_input_mask, append_mask], axis=2)
    tmp_tgt_input_mask_encoder = layers.concat([tmp_tgt_input_mask_encoder, append_mask_encoder], axis=2)
    pre_mask = layers.gather(input=tmp_tgt_input_mask, index=parent_idx)
    pre_mask_encoder = layers.gather(input=tmp_tgt_input_mask_encoder, index=parent_idx)
    pre_pos = layers.elementwise_mul(
        x=layers.fill_constant_batch_size_like(
            input=pre_mask,
            value=1,
            shape=[-1, 1, 1],
            dtype=pre_ids.dtype), y=step_idx, axis=0)
    type_ids = layers.fill_constant_batch_size_like(
        input=pre_mask,
        value=args.tgt_type_id,
        shape=[-1, 1, 1],
        dtype=pre_ids.dtype)
    dec_out, weights, gens = ernie.encode(pre_ids, pre_pos, type_ids, pre_mask, pre_mask_encoder, parent_idx)
    tmp_id = layers.gather(input=global_src_id, index=parent_idx)
    tmp_id =  layers.concat([tmp_id, pre_ids], axis=1)
    layers.assign(tmp_id, global_src_id)
    fc_out = cal_logit(tmp_id, dec_out, None, args, ernie_config, weights, gens)
    topk_scores, topk_indices = layers.topk(
        input=fc_out, k=args.beam_size)
    accu_scores = layers.elementwise_add(
        x=layers.log(topk_scores), y=pre_scores, axis=0)
    topk_indices = layers.lod_reset(topk_indices, pre_ids)
    accu_scores = layers.lod_reset(accu_scores, pre_ids)
    selected_ids, selected_scores, gather_idx = layers.beam_search(
        pre_ids=pre_ids,
        pre_scores=pre_scores,
        ids=topk_indices,
        scores=accu_scores,
        beam_size=args.beam_size,
        end_id=args.eos_idx,
        return_parent_idx=True)

    layers.increment(x=step_idx, value=1.0, in_place=True)
    layers.array_write(selected_ids, i=step_idx, array=ids)
    layers.array_write(selected_scores, i=step_idx, array=scores)
    layers.Print(weights, message="weights_here", summarize=100)
    layers.array_write(weights, i=step_idx, array=weights_array)
    weight_debug = layers.array_read(weights_array, i=step_idx)
    layers.Print(weight_debug, message="weights_debug", summarize=100)
    layers.array_write(pre_mask, i=step_idx, array=tgt_masks)
    layers.array_write(pre_mask_encoder, i=step_idx, array=tgt_masks_encoder)
    layers.assign(gather_idx, parent_idx)
    length_cond = layers.less_than(x=step_idx, y=max_len)
    finish_cond = layers.logical_not(layers.is_empty(x=selected_ids))
    layers.logical_and(x=length_cond, y=finish_cond, out=cond)

finished_ids, finished_scores = layers.beam_search_decode(
    ids, scores, beam_size=args.beam_size, end_id=args.eos_idx)
step_idx = layers.fill_constant(
        shape=[1], dtype=tgt_ids.dtype, value=0, force_cpu=True)
weight_debug =   layers.array_read(weights_array, i=step_idx)
layers.Print(weight_debug, message="weights_debug", summarize=100)
weights_output, _ = fluid.layers.tensor_array_to_tensor(input=weights_array, axis=0 , use_stack=True)
指派人
分配到
无
里程碑
无
分配里程碑
工时统计
无
截止日期
无
标识: paddlepaddle/Paddle#21772
渝ICP备2023009037号

京公网安备11010502055752号

网络110报警服务 Powered by GitLab CE v13.7
开源知识
Git 入门 Pro Git 电子书 在线学 Git
Markdown 基础入门 IT 技术知识开源图谱
帮助
使用手册 反馈建议 博客
《GitCode 隐私声明》 《GitCode 服务条款》 关于GitCode
Powered by GitLab CE v13.7