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

Optimizer return an empty model #144

Open
pd-intra opened this issue Oct 12, 2023 · 1 comment
Open

Optimizer return an empty model #144

pd-intra opened this issue Oct 12, 2023 · 1 comment

Comments

@pd-intra
Copy link

Hello,

I have an issue using this command line python -m onnxoptimizer "model.onnx" "model_opti.onnx"

The script fail at onnx.checker.check_model(output_file) in file onnxoptimizer_main.py line 85
with the error : onnx.onnx_cpp2py_export.checker.ValidationError: model with IR version >= 3 must specify opset_import for ONNX

When i check what's in the model file, i only find
ir_version: 8
producer_name: "pytorch"
producer_version: "2.1.0"
graph {
}

Now more context

i took the model "togethercomputer/LLaMA-2-7B-32K" in huggingface
convert with the following commands

from transformers import AutoTokenizer, LlamaForCausalLM

CACHE_DIR = r".\cache_dir"

tokenizer = AutoTokenizer.from_pretrained("togethercomputer/LLaMA-2-7B-32K", cache_dir=CACHE_DIR)
model = LlamaForCausalLM.from_pretrained("togethercomputer/LLaMA-2-7B-32K", cache_dir=CACHE_DIR, use_safetensors = False)

prompt = "test"
inputs = tokenizer(prompt, return_tensors="pt")

input_names = ["input_ids"]
output_names = ["output"]
torch.onnx.export(model, inputs.input_ids, r'.\model\llama2_32k_with_weight.onnx',export_params=True, input_names=input_names, output_names=output_names, dynamic_axes={'input_ids' : {1 : 'context_length'}, 'output' : {1 : 'context_length'}})

`from transformers import AutoTokenizer, LlamaForCausalLM

CACHE_DIR = r".\cache_dir"

tokenizer = AutoTokenizer.from_pretrained("togethercomputer/LLaMA-2-7B-32K", cache_dir=CACHE_DIR)
model = LlamaForCausalLM.from_pretrained("togethercomputer/LLaMA-2-7B-32K", cache_dir=CACHE_DIR, use_safetensors = False)

prompt = "test"
inputs = tokenizer(prompt, return_tensors="pt")

input_names = ["input_ids"]
output_names = ["output"]
torch.onnx.export(model, inputs.input_ids, r'.\model\llama2_32k_with_weight.onnx',export_params=True, input_names=input_names, output_names=output_names, dynamic_axes={'input_ids' : {1 : 'context_length'}, 'output' : {1 : 'context_length'}})`from transformers import AutoTokenizer, LlamaForCausalLM

CACHE_DIR = r".\cache_dir"

tokenizer = AutoTokenizer.from_pretrained("togethercomputer/LLaMA-2-7B-32K", cache_dir=CACHE_DIR)
model = LlamaForCausalLM.from_pretrained("togethercomputer/LLaMA-2-7B-32K", cache_dir=CACHE_DIR, use_safetensors = False)

prompt = "test"
inputs = tokenizer(prompt, return_tensors="pt")

input_names = ["input_ids"]
output_names = ["output"]
torch.onnx.export(model, inputs.input_ids, r'.\model\llama2_32k_with_weight.onnx',export_params=True, input_names=input_names, output_names=output_names, dynamic_axes={'input_ids' : {1 : 'context_length'}, 'output' : {1 : 'context_length'}})

After that i use :

python -m onnxoptimizer "llama2_32k_with_weight.onnx" "model_opti.onnx"

And it fail

I tried to check where the optimizer fail exactly

in onnxoptimizer\init

model_str = model.SerializeToString()
length of model_str is 26988224572

optimized_model_str =C.optimize(model_str, passes)
length of model_str is 20

If someone have an idea
Thank in advance,
I use your package for a long time and it's the first time i encounter a problem, love your work

@jibinghu
Copy link

jibinghu commented Aug 7, 2024

hey, b,ro, have the trouble solved?

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

2 participants