-
Notifications
You must be signed in to change notification settings - Fork 330
[LP] MLIA (Ethos-U target) #3769
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
80108f5
First draft MLIA LP
matt-cossins 1d8e0f2
Merge branch 'ArmDeveloperEcosystem:main' into mlia
matt-cossins 050e868
Merge remote-tracking branch 'origin/main' into mlia
matt-cossins b72ac8b
Updates
matt-cossins 315bc13
Review updates
matt-cossins 01515dd
Switch to draft
matt-cossins 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
75 changes: 75 additions & 0 deletions
75
...hs/embedded-and-microcontrollers/analyze-ethos-u-models-with-mlia/1-overview.md
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,75 @@ | ||
| --- | ||
| title: What is the ML Inference Advisor? | ||
|
|
||
| description: Understand where MLIA fits in model preparation and how Vela, Corstone FVP, Model Explorer, and runtime profiling tools support different checks. | ||
|
|
||
| weight: 2 | ||
|
|
||
| ### FIXED, DO NOT MODIFY | ||
| layout: "learningpathall" | ||
| --- | ||
|
|
||
| ## Understand what MLIA does | ||
|
|
||
| Arm ML Inference Advisor (MLIA) helps you evaluate whether a machine learning model is suitable for a target inference platform. | ||
|
|
||
| In this Learning Path, you use MLIA from the command line to check model compatibility, estimate performance, and read advice that points toward useful model changes. This Learning Path uses Arm Ethos-U as an example target. | ||
|
|
||
| MLIA is most useful before full deployment or runtime profiling, when you are asking questions such as: | ||
|
|
||
| - Will this model map cleanly to my target? | ||
| - Which operators or layers are likely to matter most for performance? | ||
|
matt-cossins marked this conversation as resolved.
|
||
| - Is the model compute-bound, memory-bound, or affected by low MAC utilization? | ||
| - Is the model well-optimized for my Arm target hardware? | ||
| - What should I investigate before building firmware or running on a board? | ||
|
|
||
| MLIA does not make the final optimization decision for you. It gives target-aware evidence so you can decide what to change, what to measure next, and which workflow stage deserves attention. | ||
|
|
||
| ## Use the CLI first | ||
|
|
||
| The MLIA CLI is the primary workflow in this Learning Path. You will use it to: | ||
|
|
||
| - discover installed targets, target profiles, and backends | ||
| - run compatibility checks | ||
| - run performance analysis | ||
| - inspect advice and metrics | ||
|
|
||
| If you want to automate the same checks, there is an optional Python API section at the end of this Learning Path. The API is useful when you want to embed MLIA results in another product, dashboard, CI job, or tool. | ||
|
|
||
| ## Using MLIA alongside other tools | ||
|
|
||
| MLIA is not a replacement for graph visualization or runtime profiling. It is an advisory layer that helps earlier in the model preparation workflow. | ||
|
|
||
| | Tool or backend | Use it to answer | | ||
| | --- | --- | | ||
| | MLIA | Is this model suitable for my target, and what should I change? | | ||
| | Vela | Which operators are supported, and which layers dominate compiler-estimated cycles? | | ||
| | Corstone FVP | What NPU performance counters does a packaged `.pte` artifact produce for the whole model run on a virtual platform? | | ||
| | Model Explorer | What does the generated model artifact graph look like? | | ||
| | Runtime-specific profiling tools | What happened when the model actually ran? For example, use ETRecord, ETDump, and ExecuTorch Inspector for ExecuTorch deployments, or LiteRT benchmark and profiling tools for LiteRT deployments. | | ||
|
|
||
| Vela-backed MLIA checks use compiler estimates. They can include operator-level breakdowns, such as which layers dominate estimated cycles or have low MAC utilization. Corstone-backed MLIA checks run a packaged `.pte` file on an FVP and report NPU performance counters for the whole model run. They do not provide per-layer estimates or operator breakdowns. | ||
|
|
||
| Model Explorer can show how an ExecuTorch `.pte` artifact is partitioned into delegate regions. Runtime-specific profiling tools can show behavior after you have a runnable deployment. | ||
|
|
||
| Use these tools together: | ||
|
|
||
| - Use MLIA before or during model preparation. | ||
| - Use Model Explorer to inspect generated artifacts and delegation structure. | ||
| - Use runtime profiling tools after you can execute the model. | ||
|
|
||
| ## Understand the model formats | ||
|
|
||
| MLIA can analyze different kinds of model artifacts depending on what workflow you are using and the stage you want to analyze. | ||
|
|
||
| | Format | Where it fits | | ||
| | --- | --- | | ||
| | `.pte` | Serialized ExecuTorch program. Ethos-U `.pte` performance analysis uses Corstone backends. | | ||
| | `.tflite` | LiteRT model format used in many Ethos-U and embedded ML workflows. | | ||
| | `.tosa` | Intermediate representation consumed by compiler/backend flows such as Ethos-U Vela. | | ||
|
|
||
| ## What you have learned | ||
|
|
||
| You have learned what MLIA does, what you use it for, and how MLIA fits alongside other tools. | ||
|
|
||
| Next, you will install MLIA and inspect the capabilities available in your environment. | ||
169 changes: 169 additions & 0 deletions
169
...and-microcontrollers/analyze-ethos-u-models-with-mlia/2-install-and-discover.md
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,169 @@ | ||
| --- | ||
| title: Install MLIA and discover capabilities | ||
|
|
||
| description: Install the MLIA Ethos-U plugin, inspect target profiles and backends, and download the model artifacts used in the analysis examples. | ||
|
|
||
| weight: 3 | ||
|
|
||
| ### FIXED, DO NOT MODIFY | ||
| layout: "learningpathall" | ||
| --- | ||
|
|
||
| ## Check your environment | ||
|
|
||
| Use Ubuntu 22.04 LTS or another compatible Linux environment with Python 3.10 or later. | ||
|
|
||
| Check that Git LFS is installed: | ||
|
|
||
| ```bash | ||
| git lfs version | ||
| ``` | ||
|
|
||
| If this command fails, install Git LFS and the Python development package: | ||
|
|
||
| ```bash | ||
| sudo apt update | ||
| sudo apt install -y git-lfs python3.10-dev | ||
| ``` | ||
|
|
||
| ## Create a Python environment | ||
|
|
||
| Create a virtual environment so the MLIA packages do not conflict with any existing ML framework environment. | ||
|
|
||
| ```bash | ||
| python3 -m venv mlia_env | ||
| source mlia_env/bin/activate | ||
| python -m pip install --upgrade pip | ||
| ``` | ||
|
|
||
| ## Install MLIA | ||
|
|
||
| MLIA uses plugins. The examples in this Learning Path use Ethos-U as the target, so install the Ethos-U plugin package: | ||
|
|
||
| ```bash | ||
| pip install mlia-ethos-u | ||
| ``` | ||
|
|
||
| The Ethos-U plugin package depends on a compatible MLIA core package. Installing the target plugin is the recommended starting point because it brings in the matching MLIA core dependency. | ||
|
|
||
| ## Confirm the CLI works | ||
|
|
||
| Display top-level help: | ||
|
|
||
| ```bash | ||
| mlia --help | ||
| ``` | ||
|
|
||
| You should see commands similar to: | ||
|
|
||
| ```output | ||
| check Generate compatibility/performance advice for a model | ||
| backend Manage MLIA backends | ||
| target Manage MLIA targets | ||
| ``` | ||
|
|
||
| The `mlia check` command is the main command you will use to ask MLIA compatibility and performance questions about model artifacts. | ||
|
|
||
| ## Discover target profiles | ||
|
|
||
| MLIA target profiles describe the target configuration used for analysis. List the target profiles available in your environment: | ||
|
|
||
| ```bash | ||
| mlia target list | ||
| ``` | ||
|
|
||
| For Ethos-U, typical bundled profiles include: | ||
|
|
||
| | Target profile | Ethos-U NPU | MACs per cycle | | ||
| | --- | --- | --- | | ||
| | `ethos-u55-128` | Ethos-U55 | 128 | | ||
| | `ethos-u55-256` | Ethos-U55 | 256 | | ||
| | `ethos-u65-256` | Ethos-U65 | 256 | | ||
| | `ethos-u65-512` | Ethos-U65 | 512 | | ||
| | `ethos-u85-128` | Ethos-U85 | 128 | | ||
| | `ethos-u85-256` | Ethos-U85 | 256 | | ||
| | `ethos-u85-512` | Ethos-U85 | 512 | | ||
| | `ethos-u85-1024` | Ethos-U85 | 1024 | | ||
| | `ethos-u85-2048` | Ethos-U85 | 2048 | | ||
|
|
||
| In this Learning Path, the examples use one Ethos-U85 profile: | ||
|
|
||
| ```output | ||
| ethos-u85-256 | ||
| ``` | ||
|
|
||
| Use a different profile if you want MLIA to evaluate the same model for a different Ethos-U configuration. | ||
|
|
||
| ## Discover backends | ||
|
|
||
| Backends perform the work behind an MLIA analysis flow. List available and installed backends: | ||
|
|
||
| ```bash | ||
| mlia backend list | ||
| ``` | ||
|
|
||
| For this Ethos-U demonstration, you should expect Vela and Corstone backend options. You use Vela for the LiteRT and TOSA checks, and Corstone for the packaged ExecuTorch `.pte` checks later in this Learning Path. | ||
|
|
||
| ```output | ||
| Name Installed Installable | ||
| corstone-300 no yes | ||
| corstone-310 no yes | ||
| corstone-320 no yes | ||
| vela no yes | ||
| ``` | ||
|
|
||
| When we later use `mlia check`, any missing backends required by your target will be installed. | ||
|
|
||
| ## Clone model artifacts | ||
|
|
||
| This Learning Path uses prebuilt artifacts from the Arm ML model artifacts repository: | ||
|
|
||
| ```bash | ||
| git lfs install | ||
| git clone --filter=blob:none --sparse https://github.com/arm-education/ml-model-artifacts.git | ||
| cd ml-model-artifacts | ||
| git sparse-checkout set pte tflite tosa | ||
| git lfs pull \ | ||
| --include="pte/toy_conditional_select_int8_ethos_u55_256.pte,pte/toy_conditional_select_int8_ethos_u85_256.pte,tflite/mv2_fp32.tflite,tflite/mv2_int8.tflite,tosa/mv2_fp32.tosa,tosa/mv2_int8.tosa" \ | ||
| --exclude="" | ||
| git lfs checkout | ||
| ``` | ||
|
|
||
| This downloads only the artifacts used in this Learning Path. It avoids larger unrelated files, such as transformer `.pte`, `.etdp`, and `.etrecord` artifacts. | ||
|
|
||
| Confirm that the artifacts are real model files, not Git LFS pointer files: | ||
|
|
||
| ```bash | ||
| wc -c tflite/mv2_int8.tflite | ||
| ``` | ||
|
|
||
| You should see a size of several megabytes, similar to: | ||
|
|
||
| ```output | ||
| 3942808 tflite/mv2_int8.tflite | ||
| ``` | ||
|
|
||
| If the file is about 100 to 200 bytes, it is still a Git LFS pointer file. Run the `git lfs pull` command again from the `ml-model-artifacts` directory, then rerun the size check. | ||
|
|
||
| The model artifacts are provided for learning and analysis exercises. Use them to explore MLIA workflows, model formats, and target-aware advice, not as accuracy reference models. | ||
|
|
||
| The repository contains model artifacts such as: | ||
|
|
||
| ```output | ||
| ml-model-artifacts/ | ||
| ├── pte/ | ||
| │ ├── toy_conditional_select_int8_ethos_u55_256.pte | ||
| │ └── toy_conditional_select_int8_ethos_u85_256.pte | ||
| ├── tflite/ | ||
| │ ├── mv2_fp32.tflite | ||
| │ └── mv2_int8.tflite | ||
| └── tosa/ | ||
| ├── mv2_fp32.tosa | ||
| └── mv2_int8.tosa | ||
| ``` | ||
|
|
||
| ## What you have learned | ||
|
|
||
| You have installed MLIA, along with the Ethos-U plugin, discovered available target profiles and backends from the CLI, and cloned model artifacts for analysis. | ||
|
|
||
| Next, you will run your first MLIA compatibility and performance checks. |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.