-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Can't export GPT2-XL to ONNX: ModelProto exceeds maximum protobuf size of 2GB #4707
Comments
according to onnx.save_model, if you pass in 'f' a path, it will save external tensors which will avoid 2gb limit. May you give onnx_model_path a folder name and see what happens? |
@liqunfu unfortunately it didn't seem to help. I edited
I also made sure
According to the log, this method is indeed called and
|
@klimentij, I can reproduce the problem. I will try modify the save_model_to_file function and let you know when there is progress. |
@klimentij, It seems that the following change could help export large model to ONNX:
The output model will contain two files like name.onnx and name.onnx.data. I'll send a pull request later after more testing. It seems that the model is very large, so benchmark will get out of memory exception when both PyTorch model and ONNX model are loaded in V100 GPU (with 16GB memory). After ONNX model is exported, use ONNX model only might avoid the problem. |
Thank you @tianleiwu! I managed to export it to .onnx and .onnx.data files using the edit you suggested. |
Describe the bug
I use
onnxruntime/onnxruntime/python/tools/transformers/benchmark_gpt2.py
script to benchmark and export GPT2-XL (1.5B) to ONNX and apply optimizations:When I use it for
gpt2-large
, it works without a problem. When I switchmodel_name
togpt2-xl
, it shows that optimizations are being applied, but fails to save optimized model to disk:I also added
use_external_data_format=True
totorch.onnx.export()
method ingpt2_helper.py
and expected that it would help, but it did not. I can't use other scripts (benchmark.py
) because I need GPT2 to be exported with the past state support.Urgency
I'm blocked on my current GPT2 deployment project because of this issue. The model is approximately 4x more expensive and slow in our production without ONNX optimizations.
System information
use_external_data_format
flag intorch.onnx.export()
)To Reproduce
use_external_data_format=True
totorch.onnx.export()
method ingpt2_helper.py
gpt2-xl
toPRETRAINED_MODELS
list inbenchmark_gpt2.py
https://huggingface.co/gpt2-xl
Expected behavior
gpt2-xl is benchmarked and exported to ONNX without any error.
The text was updated successfully, but these errors were encountered: