Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onnx导出失败 #3

Open
DrewdropLife opened this issue Oct 9, 2024 · 3 comments
Open

onnx导出失败 #3

DrewdropLife opened this issue Oct 9, 2024 · 3 comments

Comments

@DrewdropLife
Copy link

你好,我尝试将GOT-OCR导出为onnx,但是遭遇了如下错误:
AttributeError: 'GOT' object has no attribute 'image_start_id'
我仔细查看后,发现GOT类和LLM类里都没有初始化self.image_start_id,翻看了相应的config.json文件,也没有image_start_id参数,只有一个image_start_token。
于是我手动在GOT类里初始化了一个self.image_start_id=151857,现在运行导出代码没有报错,结果如下:

 1.5625e-02  3.0518e-02 -3.2227e-02  1.9531e-01
-9.8145e-02  4.4434e-02 -6.8848e-02  1.4258e-01
-2.6611e-02  3.1982e-02  1.0352e-01 -9.6680e-02
 1.0742e-01  2.8809e-02 -2.0020e-01  7.2266e-02
-3.5889e-02  5.6641e-02  2.1973e-01 -7.4707e-02
[ torch.FloatTensor{1024,1024} ]

但发现最终没有保存任何的onnx文件,文件夹里为空。这是哪里出了问题?我的执行命令如下:
python llm-export/llm_export.py --path="GOT_weights/" --export --export_test --onnx_path="onnx/"

@Mercury528
Copy link

Mercury528 commented Nov 7, 2024

遇到跟楼主一样的问题,目前已解决。
第一步,在GOT类下添加self.image_start_id = self.config.im_start_token
这里跟self.image_start_id=151857一个道理。结果就是有了onnx文件夹但里面啥也没有。
第二步,
pict1
把parser.add_argument('--path', type=str, default=r'E:\GOT-OCR2\GOT-OCR2_0\model.safetensors',
help='path(str or os.PathLike):\nCan be either:'
'\n\t- A string, the model id of a pretrained model like THUDM/chatglm-6b. [TODO]'
'\n\t- A path to a directory clone from repo like ../chatglm-6b.')里的default=r”你自己本地GOT-OCR2的模型路径“。
第三步,运行python llm_export.py --path E:\GOT-OCR2\GOT-OCR2_0 --export_lm --export_verbose (根据你自己的路径来)
第四步,成功了。
结果1
结果2

@Mercury528
Copy link

Mercury528 commented Nov 8, 2024

另外将原GOT-OCR2的文件夹下的json,py,qwen.tiktoken文件全部复制到onnx下
pict2

最后记得pip install onnxruntime-gpu,运行OnnxLLM\examples\got.py,结果如下图:
123

结论:onnx就是有很多,不是一整个大文件,能跑。

@myy-uniview
Copy link

使用 --export 时有报错信息,提示tensor有梯度,转onnx失败,所以没有保存onnx模型。
请问你们最终转成单个Onnx模型了吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants