mindspore-lab / mindnlp

Easy-to-use and high-performance NLP and LLM framework based on MindSpore, compatible with models and datasets of 🤗Huggingface.
https://mindnlp.cqu.ai/
Apache License 2.0
706 stars 200 forks source link

bert模型用mindspore的export方法导出mindir失败 #1848

Open LmYjQ opened 18 hours ago

LmYjQ commented 18 hours ago

Describe the bug/ 问题描述 (Mandatory / 必填) A clear and concise description of what the bug is.

BertForSequenceclassification模型用mindspore.export方法导出失败

To Reproduce / 重现步骤 (Mandatory / 必填) Steps to reproduce the behavior:

import mindspore as ms
import numpy as np
from mindspore import Tensor
from mindnlp.transformers import BertTokenizer
from mindnlp.transformers import BertForSequenceclassification, BertModel
path='/home/kw/huggingface/bert-base-uncased/'
model = BertForsequenceclassification.from pretrained(path, num labels=9, ignore mismatched sizes=True)
print(type(model))
tokenizer =BertTokenizer.from pretrained(path)
text ='hello, mindnlp'
inputs = tokenizer(text, padding='max length', truncation=True, max length=128)
print( inputs )
ms .export(model, *inputs,'file name='model',file format='MINDIR')

Screenshots/ 日志 / 截图 (Mandatory / 必填) If applicable, add screenshots to help explain your problem.

2c856fee675669df56d3814c4465d85

Additional context / 备注 (Optional / 选填) Add any other context about the problem here.

看了一下mindspore的源码,这里导出过程中要验证net是types.FunctionType或者type.MethodType,没有看懂