-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Model Builder: fix config access, add UT, clean up CI yamls (#1638)
## Describe your changes - Fix config access in model builder pass - Add unit test for model builder. CPU tests now has its own requirements file. - Do some clean up in the pipeline yamls: - set gpu defaults in gpu test templates - removed unused `device` template parameters - remove redundant parameter assignment from template calls - nightly gpu test uses gpu image ## Checklist before requesting a review - [x] Add unit tests for this change. - [x] Make sure all tests can pass. - [ ] Update documents if necessary. - [ ] Lint and apply fixes to your code by running `lintrunner -a` - [ ] Is this a user-facing change? If yes, give a description of this change to be included in the release notes. - [ ] Is this PR including examples changes? If yes, please remember to update [example documentation](https://github.com/microsoft/Olive/blob/main/docs/source/examples.md) in a follow-up PR. ## (Optional) Issue link Fixes #1635
- Loading branch information
Showing
9 changed files
with
74 additions
and
26 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
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
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
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,2 @@ | ||
-r requirements-test.txt | ||
onnxruntime-genai |
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
auto-gptq | ||
autoawq | ||
bitsandbytes | ||
onnxruntime-genai-cuda | ||
triton |
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,50 @@ | ||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
# -------------------------------------------------------------------------- | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from olive.model import HfModelHandler, ONNXModelHandler | ||
from olive.passes.olive_pass import create_pass_from_dict | ||
from olive.passes.onnx.model_builder import ModelBuilder | ||
|
||
|
||
def make_local_model(save_path, model_type="hf"): | ||
input_model = HfModelHandler(model_path="hf-internal-testing/tiny-random-LlamaForCausalLM") | ||
loaded_model = input_model.load_model() | ||
# this checkpoint has an invalid generation config that cannot be saved | ||
loaded_model.generation_config.pad_token_id = 1 | ||
|
||
save_path.mkdir(parents=True, exist_ok=True) | ||
if model_type == "hf": | ||
loaded_model.save_pretrained(save_path) | ||
else: | ||
onnx_file_path = save_path / "model.onnx" | ||
onnx_file_path.write_text("dummy onnx file") | ||
loaded_model.config.save_pretrained(save_path) | ||
loaded_model.generation_config.save_pretrained(save_path) | ||
input_model.get_hf_tokenizer().save_pretrained(save_path) | ||
|
||
return ( | ||
HfModelHandler(model_path=save_path) | ||
if model_type == "hf" | ||
else ONNXModelHandler(model_path=save_path, onnx_file_name="model.onnx") | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("metadata_only", [True, False]) | ||
def test_model_builder(tmp_path, metadata_only): | ||
input_model = make_local_model(tmp_path / "input_model", "onnx" if metadata_only else "hf") | ||
|
||
p = create_pass_from_dict(ModelBuilder, {"precision": "fp32", "metadata_only": metadata_only}, disable_search=True) | ||
output_folder = tmp_path / "output_model" | ||
|
||
# execute the pass | ||
output_model = p.run(input_model, output_folder) | ||
|
||
# assert | ||
assert isinstance(output_model, ONNXModelHandler) | ||
assert Path(output_model.model_path).exists() | ||
assert Path(output_folder / "genai_config.json").exists() |