huggingface / transformers

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
128.66k stars 25.52k forks source link

Using this command(optimum-cli export onnx --model Qwen1.5-0.5B-Chat --task text-generation Qwen1.5-0.5B-Chat_onnx/) to perform onnx transformation, it is found that the tensor type of the model becomes int64. How to solve this problem? #30827

Closed JameslaoA closed 1 week ago

JameslaoA commented 1 month ago

System Info

transformers version : 4.38.1 platform: ubuntu 22.04 python version : 3.10.14 optimum version : 1.19.2

Who can help?

@ArthurZucker and @younesbelkada

Information

Tasks

Reproduction

1.reference conversion command link: https://huggingface.co/docs/transformers/v4.40.1/zh/serialization 2.download model files offline (https://huggingface.co/Qwen/Qwen1.5-0.5B-Chat/tree/main) 3.Execute transition instruction:optimum-cli export onnx --model Qwen1.5-0.5B-Chat --task text-generation Qwen1.5-0.5B-Chat_onnx/

The conversion results are as follows: (mypy3.10_qnn) zhengjr@ubuntu-ThinkStation-P3-Tower:~$ optimum-cli export onnx --model Qwen1.5-0.5B-Chat --task text-generation Qwen1.5-0.5B-Chat_onnx/ 2024-05-15 19:42:07.726433: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 AVX_VNNI FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2024-05-15 19:42:07.916257: I tensorflow/core/util/util.cc:169] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable TF_ENABLE_ONEDNN_OPTS=0. 2024-05-15 19:42:07.997974: E tensorflow/stream_executor/cuda/cuda_blas.cc:2981] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered 2024-05-15 19:42:08.545959: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory 2024-05-15 19:42:08.546100: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory 2024-05-15 19:42:08.546104: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly. Framework not specified. Using pt to export the model. The task text-generation was manually specified, and past key values will not be reused in the decoding. if needed, please pass --task text-generation-with-past to export using the past key values. Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained. Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained. Using the export variant default. Available variants are:

Exporting submodel 1/1: Qwen2ForCausalLM Using framework PyTorch: 1.13.1 Overriding 1 configuration item(s)

Validating ONNX model Qwen1.5-0.5B-Chat_onnx/model.onnx... -[✓] ONNX model output names match reference model (logits)

Expected behavior

I expect the input and output tensor type converted to the onnx model to be fp16 again.

younesbelkada commented 1 month ago

cc @fxmarty @michaelbenayoun for optimum

JameslaoA commented 1 month ago

@younesbelkada thanks for your help. @fxmarty @michaelbenayoun pls help to confirm the issue,thanks.

JameslaoA commented 1 month ago

@fxmarty @michaelbenayoun can you hlep to confirm the issue?

Thanks.

JameslaoA commented 1 month ago

@younesbelkada can you help to contact the @fxmarty @michaelbenayoun to help the issue?

Thanks.

michaelbenayoun commented 1 month ago

Hi @JameslaoA , what's the issue exactly? When conversion is done the model seems to run nicely and have logits matching the original model. The inputs should be int64 no? And the outputs are int64? Are you sure? The logits seem to be computed well.

JameslaoA commented 1 month ago

Hi @michaelbenayoun thanks you for your response.

Through the model.onnx model after optimum cli conversion, open it with the netron.app tool, I see the input is int64 and the output is fp32,pls see the screenshot below image

I used the following script to convert onnx to qnn lib, but the compiler failed because int64 was not supported. image image

Could you please help me confirm whether the reason for the problem is that the output format converted is not supported, or what is the reason? I have also raised questions to Qualcomm and requested their help.

Thanks.

JameslaoA commented 1 month ago

Hello @michaelbenayoun I expect the converted onnx model inputs to be int8/int16/int32 rather than int64.

can you help me to resolves it?

Thanks.

michaelbenayoun commented 1 month ago

So it seems that everything is fine on the export side. But you need to have int32 inputs instead of int64. I think this script could help you.

JameslaoA commented 1 month ago

Hi @michaelbenayoun thanks for your help,I'll try to verify that.

Thanks.

github-actions[bot] commented 2 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.