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

Fix ONNXRT example with upgraded optimum 1.14.0 #1381

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import argparse
import os
import subprocess
import optimum.version
from packaging.version import Version
OPTIMUM114_VERSION = Version("1.14.0")


def parse_arguments():
Expand All @@ -12,20 +15,37 @@ def parse_arguments():

def prepare_model(input_model, output_model):
print("\nexport model...")
subprocess.run(
[
"optimum-cli",
"export",
"onnx",
"--model",
f"{input_model}",
"--task",
"text-generation-with-past",
f"{output_model}",
],
stdout=subprocess.PIPE,
text=True,
)
if Version(optimum.version.__version__) >= OPTIMUM114_VERSION:
subprocess.run(
[
"optimum-cli",
"export",
"onnx",
"--model",
f"{input_model}",
"--task",
"text-generation-with-past",
"--legacy",
f"{output_model}",
],
stdout=subprocess.PIPE,
text=True,
)
else:
subprocess.run(
[
"optimum-cli",
"export",
"onnx",
"--model",
f"{input_model}",
"--task",
"text-generation-with-past",
f"{output_model}",
],
stdout=subprocess.PIPE,
text=True,
)

assert os.path.exists(output_model), f"{output_model} doesn't exist!"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pip install -r requirements.txt
## 2. Prepare Model

```bash
optimum-cli export onnx --model decapoda-research/llama-7b-hf --task text-generation-with-past ./llama_7b
python prepare_model.py --input_model="decapoda-research/llama-7b-hf" --output_model="./llama_7b"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unable to access decapoda-research/llama-7b-hf on huggingface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in this pr: #1345

```

# Run
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import argparse
import os
import subprocess
import optimum.version
from packaging.version import Version
OPTIMUM114_VERSION = Version("1.14.0")


def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("--input_model", type=str, required=False, default="")
parser.add_argument("--output_model", type=str, required=True)
return parser.parse_args()


def prepare_model(input_model, output_model):
print("\nexport model...")
if Version(optimum.version.__version__) >= OPTIMUM114_VERSION:
subprocess.run(
[
"optimum-cli",
"export",
"onnx",
"--model",
f"{input_model}",
"--task",
"text-generation-with-past",
"--legacy",
f"{output_model}",
],
stdout=subprocess.PIPE,
text=True,
)
else:
subprocess.run(
[
"optimum-cli",
"export",
"onnx",
"--model",
f"{input_model}",
"--task",
"text-generation-with-past",
f"{output_model}",
],
stdout=subprocess.PIPE,
text=True,
)

assert os.path.exists(output_model), f"{output_model} doesn't exist!"


if __name__ == "__main__":
args = parse_arguments()
prepare_model(args.input_model, args.output_model)