Skip to content

Commit ba8b711

Browse files
authored
Qualcomm AI Engine Direct - Move QCOM_AXIS_ORDER pop into LayoutTransform pass (pytorch#21932)
### Context This PR supersedes pytorch#21630. The original PR was closed due to CLA issues. This new PR is created from a new branch to track CLA status and continue the review process. Please refer to pytorch#21630 for previous review comments and discussion. ### Summary: - The pop of QCOM_AXIS_ORDER was previously done in QnnBackend._build_op_wrappers before calling transform_for_preprocess_pipeline. Moving it into LayoutTransform.call() when insert_permute=True keeps the cleanup logic co-located with the code that depends on it. - The pop is necessary because the delegated subgraph is created via deepcopy, which carries over the QCOM_AXIS_ORDER tags written by the to-edge LayoutTransform run. Without clearing them, is_transformed_node() returns True for every sensitive node in the main for-loop, causing all traversals to be skipped and no permute nodes to be inserted. ### Test plan ```bash python -m backends.qualcomm.tests.test_qnn_delegate TestQNNQuantizedOperator --device ${SERIAL_NUM} --soc_model ${SOC_MODEL} --build_folder build-android --executorch_root . ``` cc @cccclai @winskuo-quic @shewu-quic @haowhsu-quic @DannyYuyang-quic @cbilgin @abhinaykukkadapu @psiddh
1 parent 8789aa5 commit ba8b711

3 files changed

Lines changed: 9 additions & 15 deletions

File tree

‎backends/qualcomm/_passes/layout_transform.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,14 @@ def call(self, graph_module: torch.fx.GraphModule):
354354
self.traverse(node, graph_module)
355355
self.insert_permute, self.transformed_tag = True, QCOM_AXIS_ORDER
356356

357+
for node in graph.nodes:
358+
if hasattr(node, "meta"):
359+
# Pop QCOM_AXIS_ORDER written by the to-edge LayoutTransform pass.
360+
# Without this, the main for-loop below would see is_transformed_node=True
361+
# for every sensitive node (deepcopy carries the tag from to-edge) and
362+
# skip them entirely, so no permute nodes would ever be inserted.
363+
node.meta.pop(QCOM_AXIS_ORDER, "")
364+
357365
for node in sensitive_nodes:
358366
if not self.is_transformed_node(node):
359367
self.mark_as_transformed(node)

‎backends/qualcomm/qnn_preprocess.py‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
from executorch.backends.qualcomm.serialization.qc_schema_serialize import (
2424
flatbuffer_to_option,
2525
)
26-
from executorch.backends.qualcomm.utils.constants import (
27-
QCOM_AXIS_ORDER,
28-
QCOM_TENSOR_NAME,
29-
)
26+
from executorch.backends.qualcomm.utils.constants import QCOM_TENSOR_NAME
3027
from executorch.backends.qualcomm.utils.qnn_manager_lifecycle import (
3128
get_current_qnn_manager,
3229
)
@@ -100,10 +97,6 @@ def _build_op_wrappers(
10097
use_mha2sha: bool,
10198
backend_type: QnnExecuTorchBackendType,
10299
):
103-
for node in edge_program.graph_module.graph.nodes:
104-
if hasattr(node, "meta"):
105-
# pop certain keys in meta for not affecting the passes in compilation
106-
node.meta.pop(QCOM_AXIS_ORDER, "")
107100
# QNN Delegate Specific Passes
108101
graph_module = get_qnn_pass_manager_cls(
109102
backend_type

‎backends/qualcomm/tests/rework/passes/passes_helper.py‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,6 @@ def lower_preprocess_gm(
300300
quantizer=quantizer,
301301
)
302302
gm = edge_ep.graph_module
303-
# Mirror qnn_preprocess.py: strip QCOM_AXIS_ORDER from all nodes
304-
from executorch.backends.qualcomm.utils.constants import QCOM_AXIS_ORDER
305-
306-
for node in gm.graph.nodes:
307-
if hasattr(node, "meta"):
308-
node.meta.pop(QCOM_AXIS_ORDER, "")
309-
310303
pm_cls = get_qnn_pass_manager_cls(backend_type)
311304
pass_classes = PassPipeline._slice_to_target(
312305
pm_cls.get_preprocess_passes(use_mha2sha=use_mha2sha),

0 commit comments

Comments
 (0)