Skip to content

Commit bd435fd

Browse files
committed
Qualcomm AI Engine Direct - Check passes_job for ResolveDebugHandle
to_edge_transform_and_lower_to_qnn, the QNN FP16 recipe and the other QNN entry points run only the active passes listed in passes_job, and the pass manager then checks that ResolveDebugHandle ran at the end. A passes_job that lists only the passes to change, like passes_job = {SomePass: {QCOM_PASS_ACTIVATE_KEY: False}} leaves ResolveDebugHandle out, and failed there with a bare IndexError (or an AssertionError) that did not say how to build a valid job. So did a passes_job that turns ResolveDebugHandle off. get_to_edge_transform_passes now raises a ValueError when passes_job has no active ResolveDebugHandle, naming the dict to start from for that backend, for example: passes_job = QnnHtpPassManager.get_capture_program_passes() passes_job[SomePass][QCOM_PASS_ACTIVATE_KEY] = False A passes_job with an active ResolveDebugHandle, or a subclass of it, goes through as before, including a reduced one that runs only the passes it lists. Test: a passes_job without ResolveDebugHandle, or with it turned off, raises the ValueError naming the pass manager, also through the QNN recipe, and a reduced one with it still yields exactly its passes.
1 parent b6033c8 commit bd435fd

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

‎backends/qualcomm/_passes/qnn_pass_manager.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def get_capture_program_passes(cls):
383383

384384
# TODO: Move these passes into qnn_partitioner and qnn_preprocess to
385385
# prevent users from needing to call custom APIs like capture_program
386-
def get_to_edge_transform_passes(
386+
def get_to_edge_transform_passes( # noqa: C901
387387
self,
388388
exported_program: ExportedProgram,
389389
passes_job: OrderedDict = None,
@@ -397,6 +397,19 @@ def get_to_edge_transform_passes(
397397
passes_job = (
398398
passes_job if passes_job is not None else self.get_capture_program_passes()
399399
)
400+
# Only the listed passes that are active run, and _validate_edge_passes
401+
# needs ResolveDebugHandle among them.
402+
if not any(
403+
isinstance(p, type)
404+
and issubclass(p, ResolveDebugHandle)
405+
and job[QCOM_PASS_ACTIVATE_KEY]
406+
for p, job in passes_job.items()
407+
):
408+
raise ValueError(
409+
"passes_job lacks an active ResolveDebugHandle. Start from "
410+
f"{type(self).__name__}.get_capture_program_passes() and edit "
411+
"it in place."
412+
)
400413
if ConvertLinearToConv2d in passes_job and convert_linear_to_conv2d:
401414
passes_job[ConvertLinearToConv2d][QCOM_PASS_ACTIVATE_KEY] = True
402415
dep_table = (

‎backends/qualcomm/tests/test_passes.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
RecomposeRmsNorm,
2121
Remove0DTensor,
2222
RemoveRedundancy,
23+
ResolveDebugHandle,
2324
TagPositionalSinCos,
2425
)
2526
from executorch.backends.qualcomm._passes.qnn_pass_manager import (
@@ -2129,6 +2130,42 @@ def forward(self, x, m: int):
21292130
[True, True, True, True, True, False],
21302131
)
21312132

2133+
def test_to_edge_passes_need_resolve_debug_handle(self):
2134+
program = torch.export.export(
2135+
torch.nn.Linear(8, 8), (torch.rand(4, 8),), strict=True
2136+
)
2137+
pass_manager = get_qnn_pass_manager_cls()()
2138+
passes_job = pass_manager.get_capture_program_passes()
2139+
message = f"{type(pass_manager).__name__}.get_capture_program_passes"
2140+
partial = {RemoveRedundancy: passes_job[RemoveRedundancy]}
2141+
inactive = {
2142+
**passes_job,
2143+
ResolveDebugHandle: {
2144+
**passes_job[ResolveDebugHandle],
2145+
QCOM_PASS_ACTIVATE_KEY: False,
2146+
},
2147+
}
2148+
for job in (partial, inactive):
2149+
with self.assertRaisesRegex(ValueError, message):
2150+
pass_manager.get_to_edge_transform_passes(program, passes_job=job)
2151+
# The QNN recipe hands passes_job to the same check.
2152+
recipe = QNNRecipeProvider().create_recipe(
2153+
QNNRecipeType.FP16, soc_model=QcomChipset.SM8650, passes_job=partial
2154+
)
2155+
with self.assertRaisesRegex(ValueError, message):
2156+
recipe.lowering_recipe.edge_transform_passes[0](None, program)
2157+
# A reduced job that keeps ResolveDebugHandle runs only what it lists.
2158+
reduced = {p: passes_job[p] for p in (RemoveRedundancy, ResolveDebugHandle)}
2159+
self.assertEqual(
2160+
[
2161+
type(p)
2162+
for p in pass_manager.get_to_edge_transform_passes(
2163+
program, passes_job=reduced
2164+
)
2165+
],
2166+
[RemoveRedundancy, ResolveDebugHandle],
2167+
)
2168+
21322169
def test_qnn_recipe_can_turn_off_tag_positional_sin_cos(self):
21332170
program = torch.export.export(
21342171
torch.nn.Linear(8, 8), (torch.rand(4, 8),), strict=True

0 commit comments

Comments
 (0)