Skip to content

  • 体验新版
    • 正在加载...
  • 登录
  • PaddlePaddle
  • X2Paddle
  • Issue
  • #267

X
X2Paddle
  • 项目概览

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

通知 329
Star 698
Fork 167
  • 代码
    • 文件
    • 提交
    • 分支
    • Tags
    • 贡献者
    • 分支图
    • Diff
  • Issue 26
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 4
  • Wiki 0
    • Wiki
  • 分析
    • 仓库
    • DevOps
  • 项目成员
  • Pages
X
X2Paddle
  • 项目概览
    • 项目概览
    • 详情
    • 发布
  • 仓库
    • 仓库
    • 文件
    • 提交
    • 分支
    • 标签
    • 贡献者
    • 分支图
    • 比较
  • Issue 26
    • Issue 26
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 4
    • 合并请求 4
  • Pages
  • 分析
    • 分析
    • 仓库分析
    • DevOps
  • Wiki 0
    • Wiki
  • 成员
    • 成员
  • 收起侧边栏
  • 动态
  • 分支图
  • 创建新Issue
  • 提交
  • Issue看板
已关闭
开放中
Opened 6月 05, 2020 by saxon_zh@saxon_zhGuest

Spanbert pytorch模型转换失败

Created by: Akeepers

  • 目标是将spanbert 转化为paddle模型
  • x2paddle采用的是第一种安装方式

pytorch转onnx的时候没有出错,onnx转paddle的时候报错, 以下是转换脚本和报错信息:

x2paddle --framework=onnx --model=spanBert.onnx --save_dir=pd_model

paddle.__version__ = 1.8.1
Now translating model from onnx to paddle.
model ir_version: 6, op version: 9
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:537] Reading dangerously large protocol message.  If the message turns out to be larger than 2147483647 bytes, parsing will be halted for security reasons.  To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:78] The total number of bytes read was 1334456625
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:537] Reading dangerously large protocol message.  If the message turns out to be larger than 2147483647 bytes, parsing will be halted for security reasons.  To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:78] The total number of bytes read was 1334456625
2020-06-05 11:29:45,087-WARNING: During conversion of your  model, some operators will be assignd node.out_shape==None, refer to https://github.com/onnx/onnx/blob/master/docs/ShapeInference.md
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:537] Reading dangerously large protocol message.  If the message turns out to be larger than 2147483647 bytes, parsing will be halted for security reasons.  To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:78] The total number of bytes read was 1334456625
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:537] Reading dangerously large protocol message.  If the message turns out to be larger than 2147483647 bytes, parsing will be halted for security reasons.  To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:78] The total number of bytes read was 1334561477
Total nodes: 2372
Traceback (most recent call last):
  File "/home/yangpan/anaconda3/envs/tf/bin/x2paddle", line 11, in <module>
    load_entry_point('x2paddle==0.7.1', 'console_scripts', 'x2paddle')()
  File "/home/yangpan/anaconda3/envs/tf/lib/python3.6/site-packages/x2paddle-0.7.1-py3.6.egg/x2paddle/convert.py", line 251, in main
    onnx2paddle(args.model, args.save_dir, params_merge)
  File "/home/yangpan/anaconda3/envs/tf/lib/python3.6/site-packages/x2paddle-0.7.1-py3.6.egg/x2paddle/convert.py", line 173, in onnx2paddle
    mapper = ONNXOpMapper(model, save_dir)
  File "/home/yangpan/anaconda3/envs/tf/lib/python3.6/site-packages/x2paddle-0.7.1-py3.6.egg/x2paddle/op_mapper/onnx_op_mapper.py", line 97, in __init__
    self.elementwise_map(node)
  File "/home/yangpan/anaconda3/envs/tf/lib/python3.6/site-packages/x2paddle-0.7.1-py3.6.egg/x2paddle/op_mapper/onnx_op_mapper.py", line 282, in elementwise_map
    if len(val_x_shape) < len(val_y_shape):
TypeError: object of type 'NoneType' has no len()

pytorch转nnox的代码如下:

import torch
import torchvision
from pytorch_pretrained_bert import BertModel
import numpy as np

config_file="/home/yangpan/projects/coref/models/config.json"
model_file="/home/yangpan/projects/coref/models/spanbert_hf.tar.gz"
vocab_file="/home/yangpan/projects/coref/models/bert-large-cased-vocab.txt"

Batch_size=1
seg_length=256

# 指定输入大小的shape
# dummy_input0 = torch.LongTensor(Batch_size, seg_length).to(torch.device("cuda"))
# dummy_input1 = torch.LongTensor(Batch_size, seg_length).to(torch.device("cuda"))
# dummy_input2 = torch.LongTensor(Batch_size, seg_length).to(torch.device("cuda"))
# dummy_input3 = torch.LongTensor(Batch_size, seg_length).to(torch.device("cuda"))
# dummy_input0 = torch.LongTensor(Batch_size, seg_length)
# dummy_input1 = torch.LongTensor(Batch_size, seg_length)
# dummy_input2 = torch.LongTensor(Batch_size, seg_length)
# dummy_input3 = torch.LongTensor(Batch_size, seg_length)


a0=np.random.randint(0,10,size=[Batch_size,seg_length])
a1=np.random.randint(0,10,size=[Batch_size,seg_length])
a2=np.random.randint(0,10,size=[Batch_size,seg_length])
a3=np.random.randint(0,10,size=[Batch_size,seg_length])
dummy_input0=torch.from_numpy(a0)
dummy_input1=torch.from_numpy(a1)
dummy_input2=torch.from_numpy(a2)
dummy_input3=torch.from_numpy(a3)

model = BertModel.from_pretrained(pretrained_model_name_or_path='spanbert-large-cased')
# model = BertModel.from_pretrained(config_file=config_file,
#                                   pretrained_model_name_or_path=model_file,
#                                   vocab_file=vocab_file)

torch.onnx.export(model, dummy_input0,"spanBert.onnx",verbose=True)
指派人
分配到
无
里程碑
无
分配里程碑
工时统计
无
截止日期
无
标识: paddlepaddle/X2Paddle#267
渝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