55# LICENSE file in the root directory of this source tree.
66
77from executorch .backends .qualcomm ._passes import (
8+ ConvertMhaToSha ,
89 DecomposeHardsigmoid ,
910 DecomposeReciprocal ,
1011 FoldQDQ ,
12+ FuseConsecutiveCast ,
13+ FuseConsecutiveTranspose ,
14+ InsertRequantize ,
15+ LayoutTransform ,
16+ LpaiPartitionFallbackSupport ,
1117 RemoveRedundancy ,
18+ ResolveDebugHandle ,
19+ TagQuantIO ,
1220)
13- from executorch .backends .qualcomm ._passes .backends .lpai .fold_qdq import LpaiFoldQDQ
1421from executorch .backends .qualcomm ._passes .qnn_pass_manager import QnnPassManager
1522
1623
@@ -24,37 +31,38 @@ class QnnLpaiPassManager(QnnPassManager):
2431 @classmethod
2532 def get_default_pass_activations (cls ):
2633 pass_activations = super ().get_default_pass_activations ()
27- pass_activations = [
28- (LpaiFoldQDQ if p is FoldQDQ else p , act ) for p , act in pass_activations
29- ]
3034 # Hardsigmoid and Reciprocal no longer appear at to_edge stage as it is decomposed in the export/annotation pipeline.
3135 # The current change is intended to proactively prepare for the upcoming deprecation of the export pipeline.
3236 pass_activations .extend (
3337 [
3438 (DecomposeHardsigmoid , True ),
3539 (DecomposeReciprocal , True ),
40+ (LpaiPartitionFallbackSupport , True ),
3641 ]
3742 )
3843 return pass_activations
3944
4045 @classmethod
4146 def get_passes_dependency_for_capture_program (cls ):
4247 deps = super ().get_passes_dependency_for_capture_program ()
43- # Replace FoldQDQ with LpaiFoldQDQ in the dependency table
44- if FoldQDQ in deps :
45- deps [LpaiFoldQDQ ] = deps .pop (FoldQDQ )
46- for key in deps :
47- deps [key ] = [LpaiFoldQDQ if v is FoldQDQ else v for v in deps [key ]]
4848 # Hardsigmoid and Reciprocal no longer appear at to_edge stage as it is decomposed in the export/annotation pipeline.
4949 # The current change is intended to proactively prepare for the upcoming deprecation of the export pipeline.
5050 deps .update (
5151 {
5252 DecomposeHardsigmoid : [RemoveRedundancy ],
5353 DecomposeReciprocal : [RemoveRedundancy ],
54+ LpaiPartitionFallbackSupport : [TagQuantIO ],
55+ ResolveDebugHandle : [LpaiPartitionFallbackSupport ],
5456 }
5557 )
5658 return deps
5759
60+ def _validate_edge_passes (self ) -> None :
61+ super ()._validate_edge_passes ()
62+ assert isinstance (
63+ self .passes [- 2 ], LpaiPartitionFallbackSupport
64+ ), "Please ensure LpaiPartitionFallbackSupport is the last edge pass before ResolveDebugHandle."
65+
5866 @classmethod
5967 def get_annotation_passes (cls ):
6068 passes = [DecomposeHardsigmoid , DecomposeReciprocal ]
@@ -74,5 +82,14 @@ def get_export_passes(
7482
7583 @classmethod
7684 def get_preprocess_passes (cls , use_mha2sha = False ):
77- passes = super ().get_preprocess_passes (use_mha2sha )
78- return [LpaiFoldQDQ if p is FoldQDQ else p for p in passes ]
85+ passes = [
86+ FoldQDQ ,
87+ ConvertMhaToSha ,
88+ InsertRequantize ,
89+ LayoutTransform ,
90+ FuseConsecutiveCast ,
91+ FuseConsecutiveTranspose ,
92+ ]
93+ if not use_mha2sha :
94+ passes .remove (ConvertMhaToSha )
95+ return passes
0 commit comments