-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Cortex-M: share one to_edge config instead of five hand-copied ones #21826
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| import torch | ||
| from executorch.exir import EdgeCompileConfig | ||
|
|
||
| # Ops that must survive to_edge for the Cortex-M passes to lower them directly. | ||
| # Omitting one does not degrade gracefully. The activations decompose into a | ||
| # multiply whose qparams are gone by then, which fails AtenToCortexMPass; linear | ||
| # decomposes into addmm and silently stays on portable float kernels. | ||
| _PRESERVE_OPS = ( | ||
| torch.ops.aten.linear.default, | ||
| torch.ops.aten.hardsigmoid.default, | ||
| torch.ops.aten.hardsigmoid_.default, | ||
| torch.ops.aten.hardswish.default, | ||
| torch.ops.aten.hardswish_.default, | ||
| torch.ops.aten.silu.default, | ||
| ) | ||
|
|
||
|
|
||
| def cortex_m_edge_compile_config() -> EdgeCompileConfig: | ||
| """The to_edge configuration the Cortex-M backend requires. | ||
|
|
||
| Shared by the AOT compiler and the test harness so the two cannot drift: an | ||
| entry present in only one of them means the tests exercise a lowering users | ||
| never get, or the reverse. | ||
|
|
||
| Edge-dialect validation is off because the backend's quantized graphs do not | ||
| pass it: enabling it fails the model tests with mismatched-dtype | ||
| SpecViolationErrors. That also makes a _core_aten_ops_exception_list pointless | ||
| here, since the verifier it feeds never runs. max_pool2d would need an entry if | ||
| validation is ever turned on. | ||
| """ | ||
| return EdgeCompileConfig( | ||
| preserve_ops=list(_PRESERVE_OPS), | ||
| _check_ir_validity=False, | ||
|
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. Is _check_ir_validity=False necessary for the op set ?Asking because preserve_ops and _core_aten_ops_exception_list look like they'd already cover the non-core ops , alsi if validity is off, does the exception list still do anything?
Contributor
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, it is necessary. I removed the exception list. |
||
| ) | ||
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.
Are there other hand-written EdgeCompileConfigs left that should use this factory?
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, I missed one in the cortex-m skill. Added.