-
Notifications
You must be signed in to change notification settings - Fork 267
Adding Estimate NPU Latency pass and unit test #2178
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
Open
alinah-amd
wants to merge
10
commits into
microsoft:main
Choose a base branch
from
alinah-amd:alinah/perf_est_pass
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
06f0e90
Adding Estimate NPU Latency pass and unit test
alinah-amd 9e35b6b
Fixed lint issues
alinah-amd d4308ed
Addressed feedback
alinah-amd d34ae53
Merge branch 'main' into alinah/perf_est_pass
alinah-amd 6a23608
Fix EstimatorSettings bug
alinah-amd 72ddba5
Merge branch 'alinah/perf_est_pass' of github.com:alinah-amd/Olive in…
alinah-amd cc281ad
Fix lint error
alinah-amd cf4b6ea
Fixed lint error
alinah-amd 41aa601
Merge branch 'main' into alinah/perf_est_pass
alinah-amd 42f6047
Merge branch 'main' into alinah/perf_est_pass
alinah-amd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,74 @@ | ||
| # | ||
| # Copyright (C) 2025, Advanced Micro Devices, Inc. All rights reserved. | ||
| # SPDX-License-Identifier: MIT | ||
| # | ||
|
|
||
| import logging | ||
|
|
||
| from olive.hardware.accelerator import AcceleratorSpec | ||
| from olive.model import ONNXModelHandler | ||
| from olive.passes import Pass | ||
| from olive.passes.pass_config import BasePassConfig, PassConfigParam | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class EstimateNPULatency(Pass): | ||
| """Returns latency estimates for the model.""" | ||
|
|
||
| @classmethod | ||
| def _default_config(cls, accelerator_spec: AcceleratorSpec) -> dict[str, PassConfigParam]: | ||
| return { | ||
| "target_device": PassConfigParam( | ||
| type_=str, required=False, description="Target device type", default_value="stx" | ||
| ) | ||
| } | ||
|
|
||
| @classmethod | ||
| def validate_config(cls, config: type[BasePassConfig], accelerator_spec: AcceleratorSpec) -> bool: | ||
| if not super().validate_config(config, accelerator_spec): | ||
| return False | ||
|
|
||
| if config.target_device and config.target_device not in ["stx"]: | ||
| logger.warning("Unsupported target device type: %s", config.target_device) | ||
| return False | ||
|
|
||
| return True | ||
|
|
||
| def _run_for_config( | ||
| self, model: ONNXModelHandler, config: BasePassConfig, output_model_path: str | ||
| ) -> ONNXModelHandler: | ||
| perf_installed = True | ||
| try: | ||
| from estimator.config import EstimatorSettings | ||
| from estimator.run import run_perf_estimate | ||
| except ImportError: | ||
| perf_installed = False | ||
| logger.exception( | ||
| "Estimator module not found. Install perf-estimator package and delete cached run before rerunning." | ||
| ) | ||
|
|
||
| if not isinstance(model, ONNXModelHandler): | ||
| raise ValueError("Model must be an instance of ONNXModelHandler") | ||
|
|
||
| input_model_path = model.model_path | ||
|
|
||
| # Bypass if perf estimator package not installed | ||
| if perf_installed: | ||
| EstimatorSettings.model_path = f"{input_model_path}" | ||
|
|
||
| # Override default parameters if specified | ||
| if config.target_device: | ||
| EstimatorSettings.target_device = config.target_device | ||
|
|
||
| logger.info( | ||
| "Running perf estimator for model path: %s and target device: %s", | ||
| input_model_path, | ||
| EstimatorSettings.target_device, | ||
| ) | ||
|
|
||
| run_perf_estimate(EstimatorSettings) | ||
| logger.info("Finish running perf estimator pass") | ||
|
|
||
| # Return the original model as is | ||
| return model | ||
This file contains hidden or 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,37 @@ | ||
| # | ||
| # Copyright (C) 2025, Advanced Micro Devices, Inc. All rights reserved. | ||
| # SPDX-License-Identifier: MIT | ||
| # | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| import onnx | ||
|
|
||
| from olive.passes.olive_pass import create_pass_from_dict | ||
| from olive.passes.onnx.vitis_ai.estimate_npu_latency import EstimateNPULatency | ||
| from test.utils import get_onnx_model | ||
|
|
||
|
|
||
| class TestEstimateNPULatency: | ||
| """Test cases for EstimateNPULatency pass.""" | ||
|
|
||
| def test_estimate_latency_basic(self, tmp_path): | ||
alinah-amd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """Test Perf Estimator call with automatic Olive version.""" | ||
| # Setup | ||
| input_model = get_onnx_model() | ||
| config = {} | ||
| p = create_pass_from_dict(EstimateNPULatency, config, disable_search=True) | ||
| output_folder = str(tmp_path / "onnx") | ||
|
|
||
| # Execute | ||
| output_model = p.run(input_model, output_folder) | ||
|
|
||
| # Assert we created output csv for latency results | ||
| estimates_csv = f"{os.path.dirname(input_model.model_path)}/concise_summary" | ||
| assert Path(estimates_csv).exists() | ||
|
|
||
| # Assert | ||
| assert Path(output_model.model_path).exists() | ||
| # Load the output model and check graph name | ||
| onnx_model = onnx.load_model(output_model.model_path) | ||
| assert onnx_model.graph.name == "main_graph" | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ optimum-intel[openvino]>=1.17.0, <=1.24 | |
| optuna | ||
| pandas | ||
| peft | ||
| perf-estimator | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is no package called perf-estimator on pypi
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we are working to push the package into pypi. Will update once that is done. |
||
| plotly | ||
| polygraphy>=0.49.22 | ||
| psutil | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.