Skip to content

[Cortex-M] Support public edge transforms - #22980

Merged
rascani merged 1 commit into
pytorch:mainfrom
rascani:cortex-m-exported-program-pass-manager
Sep 22, 2026
Merged

rascani merged 1 commit into
pytorch:mainfrom
rascani:cortex-m-exported-program-pass-manager

Conversation

@rascani

@rascani rascani commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Passing CortexMPassManager to edge.transform() currently fails because it inherits a graph-module pass manager while keeping its lowering pipeline in a separate .transform() method. Callers consequently have to replace edge._edge_programs["forward"] directly.

Make it an ExportedProgramPassManager with a program-aware adapter around the existing pipeline. Each pass is instantiated against the current exported program, preserving updates to constants and graph signatures. This enables edge.transform(CortexMPassManager(...)) and to_edge_transform_and_lower(..., transform_passes=CortexMPassManager(...)), while retaining the legacy bound-program constructor and .transform() entry point. Update the exporters, examples, documentation, and test harness to use the public APIs.

Authored with OpenAI Codex.

Test plan

The following tests passed: 307 passed, 1 skipped, and 24 expected failures. The new regression tests cover both layouts and all three entry points, serialization, multiple methods, target configuration, and constant lifting.

python -m pytest -q \
  backends/cortex_m/test/test_pass_manager.py \
  backends/cortex_m/test/test_explicit_layout_pipeline.py \
  backends/cortex_m/test/misc/test_target_config.py

OMP_NUM_THREADS=1 python -m pytest -q -n 4 \
  backends/cortex_m/test/ops exir/tests/test_pass_infra.py \
  -k 'test_dialect or TestExportedProgramPassManager'

Additional smoke checks passed for the Arm AOT exporter, CMSIS metadata, and ETRecord generation. Executed the export cells in examples/arm/ethos_u_cmsis_nn_fallback_example.ipynb with the pinned ethos-u-vela==5.1.0, confirming that the compiled delegate survives Cortex-M lowering and serialization.

Built a fresh Cortex-M55 semihosting runner from this checkout with CORTEX_M_ENABLE_RUNTIME_CHECKS=ON and EXECUTORCH_ENABLE_PROGRAM_VERIFICATION=ON. Ran four serialized programs on Corstone-300 FVP: mixed Ethos-U/Cortex-M, convolution with each layout, and linear. All four outputs matched quantized PyTorch exactly, with zero maximum absolute error; the mixed case executed one NPU delegation.

Lintrunner passed for all 18 changed files. Three independent Codex reviews found no actionable regressions. Buck execution has not been validated locally.

cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @psiddh @AdrianLundell

@rascani rascani added release notes: arm Changes to the ARM backend delegate module: microcontrollers For embedded MCUs like Cortex-M, or RTOS like Zephyr, does not track NPU backend like Arm Ethos. labels Sep 21, 2026
@pytorch-bot

pytorch-bot Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22980

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 1 New Failure, 2 Unrelated Failures

As of commit c472672 with merge base 9b91b43 (image):

NEW FAILURE - The following job has failed:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 21, 2026
@github-actions github-actions Bot added ciflow/trunk module: arm Issues related to arm backend labels Sep 21, 2026
Migrate CortexMPassManager to ExportedProgramPassManager so callers can use
edge.transform() and to_edge_transform_and_lower() without replacing private
program entries. Preserve the existing lowering sequence and legacy entry
point, update callers, and cover program state and serialization in tests.

Authored with OpenAI Codex.
@rascani
rascani force-pushed the cortex-m-exported-program-pass-manager branch from 54366e3 to c472672 Compare September 21, 2026 22:12
@rascani
rascani marked this pull request as ready for review September 21, 2026 22:15

@AdrianLundell AdrianLundell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff!

@rascani

rascani commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Failures unrelated.

@rascani
rascani merged commit 7cc8379 into pytorch:main Sep 22, 2026
459 of 463 checks passed
@rascani
rascani deleted the cortex-m-exported-program-pass-manager branch September 22, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: arm Issues related to arm backend module: microcontrollers For embedded MCUs like Cortex-M, or RTOS like Zephyr, does not track NPU backend like Arm Ethos. release notes: arm Changes to the ARM backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants