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

Avoid appending to external data when running onnx_save #320

Merged
merged 4 commits into from
Jun 2, 2023

Conversation

dbogunowicz
Copy link
Contributor

@dbogunowicz dbogunowicz commented May 26, 2023

When running onnx_save(model) and the model is >2Gb, its initializers, and parameters are saved to one external data file model.data. However, when running onnx_save(...) multiple times, by default we are not strictly overwriting the old model.data file (the expected behavior), but we are overwriting the previously seen parameters and appending the unseen ones to the file.

This is why, when exporting a QAT model, the model.data keep growing very large.
It eventually contains:

The problem of exploding model.data does not concern us in the context of FP32 model, because onnx_save is being called only once.

Testing:

import onnx
import os
from sparsezoo.utils.onnx import save_onnx
model = onnx.load("/network/damian/sparsegpt_webinar_fp32/sparsegpt_1.3b/model.onnx")
# model.ByteSize() -> 5675170625 which is less then 5.6G
save_onnx(model, model_path = "tmp.onnx")
# The ONNX model is too large to be saved as a single protobuf. Saving with external data: model.data
model = onnx.load("tmp.onnx")
save_onnx(model, model_path = "tmp.onnx")
# The ONNX model is too large to be saved as a single protobuf. Saving with external data: model.data
# Attempting to save external data for a model: tmp.onnx to a directory: that already contains external data file: model.data. The external data file will be overwritten.
# du -sh model.data -> 5.3G

This has been also successfully tested with the sparseml.transformers.export pathway.

(venv) damian@nmgpuserver1:~/sparsegpt@opt-2.7b@c4@opt2.7b.W8A8linear.fp16_matmul_resi_relu_ln_emb_head@SQ1@PTQ1@ID21988/deployment$ du -sh *
4.0K	config.json
448K	merges.txt
**3.4G	model.data**
996K	model.onnx
4.0K	special_tokens_map.json
4.0K	tokenizer_config.json
976K	vocab.json

@dbogunowicz dbogunowicz merged commit 4486de9 into main Jun 2, 2023
4 checks passed
@dbogunowicz dbogunowicz deleted the feature/damian/avoid_appending_to_external_data branch June 2, 2023 10:41
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

Successfully merging this pull request may close these issues.

None yet

3 participants