PaddleTS的DeepAR模型 在用paddle inference推理的时候,PreconditionNotMetError: Tensor holds no memory. Call Tensor::mutable_data firstly.

dy2hfwbg  于 4个月前  发布在  其他
关注(0)|答案(2)|浏览(38)

bug描述 Describe the Bug

#保存模型的代码
DeepAR.save("./DeepAR",network_model=True,dygraph_to_static=True)

#使用paddle inference 推理
from paddlets.models.model_loader import load
from paddlets.datasets.repository import dataset_list, get_dataset

dataset = get_dataset('UNI_WTH')

import paddle.inference as paddle_infer

config = paddle_infer.Config("./DeepAR.pdmodel", "./DeepAR.pdiparams")
predictor = paddle_infer.create_predictor(config)
input_names = predictor.get_input_names()
print(f"input_name: f{input_names}")

import json
with open("./DeepAR_model_meta") as f:
json_data = json.load(f)
print(json_data)

from paddlets.utils.utils import build_ts_infer_input

input_data = build_ts_infer_input(dataset, "./DeepAR_model_meta")

for key, value in json_data['input_data'].items():
input_handle1 = predictor.get_input_handle(key)
#set batch_size=1
value[0] = 1
input_handle1.reshape(value)
input_handle1.copy_from_cpu(input_data[key])

predictor.run()
output_names = predictor.get_output_names()
output_handle = predictor.get_output_handle(output_names[0])
output_data = output_handle.copy_to_cpu()
print(output_data)

Traceback (most recent call last):
  File "/Users/kevin/Desktop/com/40-docs-main/TS-10/DeepAR/predict.py", line 31, in <module>
    predictor.run()
RuntimeError: In user code:

    File "/Users/kevin/Desktop/中车/40-docs-main/TS-10/DeepAR/DeepAR.py", line 57, in <module>
      DeepAR.save("./DeepAR",network_model=True,dygraph_to_static=True)
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddlets/models/forecasting/dl/paddle_base.py", line 169, in save
      paddle.jit.save(layer, os.path.join(abs_root_path, internal_filename_map["network_model"]))
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/decorator.py", line 232, in fun
      return caller(func, *(extras + args), **kw)
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddle/base/wrapped_decorator.py", line 26, in __impl__
      return wrapped_func(*args, **kwargs)
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddle/jit/api.py", line 809, in wrapper
      func(layer, path, input_spec, **configs)
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/decorator.py", line 232, in fun
      return caller(func, *(extras + args), **kw)
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddle/base/wrapped_decorator.py", line 26, in __impl__
      return wrapped_func(*args, **kwargs)
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddle/base/dygraph/base.py", line 68, in __impl__
      return func(*args, **kwargs)
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddle/jit/api.py", line 1104, in save
      static_func.concrete_program_specify_input_spec(
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 986, in concrete_program_specify_input_spec
      concrete_program, _ = self.get_concrete_program(
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 875, in get_concrete_program
      concrete_program, partial_program_layer = self._program_cache[
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 1648, in __getitem__
      self._caches[item_id] = self._build_once(item)
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 1575, in _build_once
      concrete_program = ConcreteProgram.from_func_spec(
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/decorator.py", line 232, in fun
      return caller(func, *(extras + args), **kw)
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddle/base/wrapped_decorator.py", line 26, in __impl__
      return wrapped_func(*args, **kwargs)
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddle/base/dygraph/base.py", line 68, in __impl__
      return func(*args, **kwargs)
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 1339, in from_func_spec
      outputs = static_func(*inputs)
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddlets/models/forecasting/dl/deepar.py", line 339, in forward
      output = self._decoder(x, hidden_state)
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddlets/models/forecasting/dl/deepar.py", line 297, in _decoder
      input_tensor = self._build_input(future_target, future_known_cov, first_target_replace) 
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddlets/models/forecasting/dl/deepar.py", line 96, in _build_input
      target_roll = paddle.roll(target, shifts=1, axis=1)  # [batch_size, seq_len, target_dim]
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddle/tensor/manipulation.py", line 1899, in roll
      helper.append_op(
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddle/base/layer_helper.py", line 44, in append_op
      return self.main_program.current_block().append_op(*args, **kwargs)
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddle/base/framework.py", line 4467, in append_op
      op = Operator(
    File "/Users/kevin/opt/anaconda3/envs/paddlets/lib/python3.8/site-packages/paddle/base/framework.py", line 3016, in __init__
      for frame in traceback.extract_stack():

    PreconditionNotMetError: Tensor holds no memory. Call Tensor::mutable_data firstly.
      [Hint: holder_ should not be null.] (at /Users/paddle/xly/workspace/9a389d1e-5f81-4294-a204-ca0214ddf827/Paddle/paddle/phi/core/dense_tensor_impl.cc:44)
      [operator < roll > error]

其他补充信息 Additional Supplementary Information

No response

kkbh8khc

kkbh8khc1#

您好,请给一下详细的复现方式~

dohp0rv5

dohp0rv52#

我也遇到同样的问题了

相关问题