PaddlePaddle / Serving

A flexible, high-performance carrier for machine learning models(『飞桨』服务化部署框架)
Apache License 2.0
898 stars 250 forks source link

保存ERNIE可服务模型,client调用问题 #913

Closed lerry-lee closed 8 months ago

lerry-lee commented 3 years ago

client端代码

    from paddle_serving_client import Client

    client = Client()
    client.load_client_config("serving_client/serving_client_conf.prototxt")
    client.connect(["127.0.0.1:9292"])
    data_generator = data_preprocess()
    for sample in data_generator():
        src_ids = sample[0]
        sent_ids = sample[1]
        pos_ids = sample[2]
        input_mask = sample[4]

        data = {"eval_placeholder_0": src_ids,
                "eval_placeholder_1": sent_ids,
                "eval_placeholder_2": pos_ids,
                "eval_placeholder_3": input_mask}

        fetch_map = client.predict(feed=data, fetch=["save_infer_model/scale_0.tmp_0"])

        print(fetch_map)

其中数据预处理data_preprocess是从源码中抽离出来的

def data_preprocess():
    from ernie.reader.task_reader import ClassifyReader
    reader = ClassifyReader(
        vocab_path="{}/vocab.txt".format(ERNIE_PATH),  # ernie配置文件-vocab
        label_map_config=None,
        max_seq_len=128,
        do_lower_case=True,
        in_tokens=False,
        is_inference=True)

    predict_data_generator = reader.data_generator(
        input_file="task_data/test.txt",
        batch_size=1,
        epoch=1,
        shuffle=False)

    return predict_data_generator

测试数据text.txt为

text_a  text_b  label
你好  你好  1

客户端配置如下

feed_var {
  name: "eval_placeholder_0"
  alias_name: "eval_placeholder_0"
  is_lod_tensor: false
  feed_type: 0
  shape: 128
  shape: 1
}
feed_var {
  name: "eval_placeholder_1"
  alias_name: "eval_placeholder_1"
  is_lod_tensor: false
  feed_type: 0
  shape: 128
  shape: 1
}
feed_var {
  name: "eval_placeholder_2"
  alias_name: "eval_placeholder_2"
  is_lod_tensor: false
  feed_type: 0
  shape: 128
  shape: 1
}
feed_var {
  name: "eval_placeholder_3"
  alias_name: "eval_placeholder_3"
  is_lod_tensor: false
  feed_type: 1
  shape: 128
  shape: 1
}
fetch_var {
  name: "save_infer_model/scale_0.tmp_0"
  alias_name: "save_infer_model/scale_0.tmp_0"
  is_lod_tensor: false
  fetch_type: 1
  shape: 2
}

成功启动server端,然后client端执行报错

W1209 02:41:42.637696 20343 predictor.hpp:129] inference call failed, message: [E112]1/1 channels failed, fail_limit=1 [C0][E1014]Got EOF of fd=11 SocketId=1@127.0.0.1:9292@34132 [R1][E111]Fail to connect SocketId=8589934594@127.0.0.1:9292: Connection refused [R2][E112]Fail to select server from list://127.0.0.1:9292 lb=la
E1209 02:41:42.637908 20343 general_model.cpp:561] failed call predictor with req: insts { tensor_array { int64_data: 1 int64_data: 6656 int64_data: 17963 int64_data: 1545 int64_data: 2 int64_data: 6656 int64_data: 17963 int64_data: 1801 int64_data: 2 elem_type: 0 shape: 1 shape: 9 shape: 1 } tensor_array { int64_data: 0 int64_data: 0 int64_data: 0 int64_data: 0 int64_data: 0 int64_data: 1 int64_data: 1 int64_data: 1 int64_data: 1 elem_type: 0 shape: 1 shape: 9 shape: 1 } tensor_array { int64_data: 0 int64_data: 1 int64_data: 2 int64_data: 3 int64_data: 4 int64_data: 5 int64_data: 6 int64_data: 7 int64_data: 8 elem_type: 0 shape: 1 shape: 9 shape: 1 } tensor_array { float_data: 1 float_data: 1 float_data: 1 float_data: 1 float_data: 1 float_data: 1 float_data: 1 float_data: 1 float_data: 1 elem_type: 1 shape: 1 shape: 9 shape: 1 } } fetch_var_names: "save_infer_model/scale_0.tmp_0"

server端报错信息为

----------------------
Error Message Summary:
----------------------
InvalidArgumentError: The first dimension value of Input(Scale) must equal to be thesecond dimension value of the flattened 2D matrix of Input(X),But received the first dimension value of Input(Scale) is[768], the second dimension value of the flattened 2D matrix of Input(Scale) is [6912].
  [Hint: Expected ctx->GetInputDim("Scale")[0] == right, but received ctx->GetInputDim("Scale")[0]:768 != right:6912.] at (/paddle/paddle/fluid/operators/layer_norm_op.cc:66)
  [operator < layer_norm > error]
Aborted (core dumped)

请问是什么原因呢

TeslaZhao commented 3 years ago

使用哪个Serving版本?

lerry-lee commented 3 years ago

使用哪个Serving版本?

0.3.2

TeslaZhao commented 3 years ago

请使用最新0.4.0版本或最新develop分支试一下,这个问题已经修复了

lerry-lee commented 3 years ago

请使用最新0.4.0版本或最新develop分支试一下,这个问题已经修复了 服务端可以启动,客户端报以下错误: from .serving_client import PredictorRes ModuleNotFoundError: No module named 'paddle_serving_client.serving_client' 我用的是0.4.0版本

Karenlyw commented 3 years ago

您好 请问这个问题解决了吗 我也报了同样的错

pal-duan commented 2 years ago

您好,这个问题怎么解决的呢?

TeslaZhao commented 2 years ago

您好,使用的paddle,paddle serving版本是什么? 报错信息是什么?

lerry-lee commented 2 years ago

您好,使用的paddle,paddle serving版本是什么? 报错信息是什么?

您好,报错信息是最上面展示的,这个问题去年经历的,当时没有解决后,我就没有再管了...

TeslaZhao commented 2 years ago

已经更新很多版本了,安装最新paddle serving v0.7代码和Paddle 2.2版本,再更新代码试一下?

TeslaZhao commented 2 years ago

模型使用哪个paddle版本训练的?

lerry-lee commented 2 years ago

已经更新很多版本了,安装最新paddle serving v0.7代码和Paddle 2.2版本,再更新代码试一下?

好的,也让后面出现过同样问题的伙伴试试吧

lerry-lee commented 2 years ago

您好 请问这个问题解决了吗 我也报了同样的错

可以看看后面paddle开发者的回复哈

lerry-lee commented 2 years ago

您好,这个问题怎么解决的呢?

可以看看后面paddle开发者的回复哈

lerry-lee commented 2 years ago

模型使用哪个paddle版本训练的?

好像是1.7或者1.8

TeslaZhao commented 2 years ago

从报错信息看,疑似是输入参数shape和模型feed var不一致。建议还是先更新一下Paddle 和Serving版本再试一下。更新版本不保证能解决问题,但新版本修复了旧版本的bug,可排除一些问题

pal-duan commented 2 years ago

从报错信息看,疑似是输入参数shape和模型feed var不一致。建议还是先更新一下Paddle 和Serving版本再试一下。更新版本不保证能解决问题,但新版本修复了旧版本的bug,可排除一些问题

您好,Paddle和Serving都是最新的版本,用Serving部署后可以预测单个数据,批量预测就会报这个错误,在本地是可以批量预测的。 Error Message Summary:

InvalidArgumentError: The first dimension value of Input(Scale) must equal to be thesecond dimension value of the flattened 2D matrix of Input(X),But received the first dimension value of Input(Scale) is[768], the second dimension value of the flattened 2D matrix of Input(Scale) is [17664]. [Hint: Expected ctx->GetInputDim("Scale")[0] == right, but received ctx->GetInputDim("Scale")[0]:768 != right:17664.] (at /paddle/paddle/fluid/operators/layer_norm_op.cc:72) [operator < layer_norm > error] Aborted (core dumped)

yangxuan14nlp commented 1 year ago

请问,维度不一致,怎么解决的