-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ONNXRT example with upgraded optimum 1.14.0 (#1381)
Signed-off-by: Mengni Wang <[email protected]> Signed-off-by: yuwenzho <[email protected]>
- Loading branch information
1 parent
f5167dc
commit da3442d
Showing
5 changed files
with
97 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...xrt/nlp/huggingface_model/text_generation/llama/quantization/weight_only/prepare_model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters