-
Notifications
You must be signed in to change notification settings - Fork 724
Add support for model-explorer in ArmTester #6750
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
Closed
Closed
Changes from all commits
Commits
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
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,62 @@ | ||
| # Copyright 2024 Arm Limited and/or its affiliates. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| import logging | ||
| from typing import Optional | ||
|
|
||
| from executorch.backends.arm.test.common import arm_test_options, get_option | ||
| from torch.export import ExportedProgram | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
| _model_explorer_installed = False | ||
|
|
||
| try: | ||
| # pyre-ignore[21]: We keep track of whether import succeeded manually. | ||
| from model_explorer import config, visualize_from_config, visualize_pytorch | ||
|
|
||
| _model_explorer_installed = True | ||
| except ImportError: | ||
| logger.warning("model-explorer is not installed, can't visualize models.") | ||
|
|
||
|
|
||
| def is_model_explorer_installed() -> bool: | ||
| return _model_explorer_installed | ||
|
|
||
|
|
||
| def get_pytest_option_host() -> str | None: | ||
| host = get_option(arm_test_options.model_explorer_host) | ||
| return str(host) if host else None | ||
|
|
||
|
|
||
| def get_pytest_option_port() -> int | None: | ||
| port = get_option(arm_test_options.model_explorer_port) | ||
| return int(port) if port else None | ||
|
|
||
|
|
||
| def visualize( | ||
| exported_program: ExportedProgram, | ||
| host: Optional[str] = None, | ||
| port: Optional[int] = None, | ||
| ): | ||
| """Attempt visualizing exported_program using model-explorer.""" | ||
|
|
||
| host = host if host else get_pytest_option_host() | ||
| port = port if port else get_pytest_option_port() | ||
|
|
||
| if not is_model_explorer_installed(): | ||
| logger.warning("Can't visualize model since model-explorer is not installed.") | ||
| return | ||
|
|
||
| # If a host is provided, we attempt connecting to an already running server. | ||
| # Note that this needs a modified model-explorer | ||
| if host: | ||
| explorer_config = ( | ||
| config() | ||
| .add_model_from_pytorch("ExportedProgram", exported_program) | ||
| .set_reuse_server(server_host=host, server_port=port) | ||
| ) | ||
| visualize_from_config(explorer_config) | ||
| else: | ||
| visualize_pytorch(exported_program) | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you just test locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this has only been tested locally. I am not sure how to test in ci since it requires an external dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Olivia-liu - what do you think of this vs. our SDK plans for visualization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bump @Olivia-liu, some kind of visualization would be great, so would really appreciate merging unless you have other plans soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Erik-Lundell Sorry about the delay! This is great. Glad to see integration with model-explorer going on!