55
66import copy
77
8+ from executorch .backends .nxp .backend .ir .edge_passes .remove_io_quant_ops_pass import (
9+ RemoveIOQuantOpsPass ,
10+ )
11+
812from executorch .backends .nxp .edge_passes .move_auxiliary_operator_into_separate_qdq_cluster_pass import (
913 MoveLeadingAuxiliaryOperatorIntoSeparateQDQClusterPass ,
1014 MoveTrailingAuxiliaryOperatorIntoSeparateQDQClusterPass ,
2428
2529class NeutronEdgePassManager (PassManager ):
2630
27- def __init__ (self , passes : list [NeutronEdgePass ] = None ):
31+ def __init__ (
32+ self , passes : list [NeutronEdgePass ] = None , remove_io_quant_ops : bool = False
33+ ):
2834 passes : list [NeutronEdgePass ] = passes or [
2935 MoveLeadingAuxiliaryOperatorIntoSeparateQDQClusterPass (),
3036 MoveTrailingAuxiliaryOperatorIntoSeparateQDQClusterPass (),
@@ -35,6 +41,8 @@ def __init__(self, passes: list[NeutronEdgePass] = None):
3541 steps = 10 , # Empirical value. At most 10 cycles of passes will be run.
3642 )
3743
44+ self .remove_io_quant_ops = remove_io_quant_ops
45+
3846 def _transform_graph_module (self , module : nn .Module ) -> PassResult :
3947 """Apply the passes to a single graph module."""
4048 pass_result : PassResult = super ().__call__ (module )
@@ -78,12 +86,15 @@ def __call__(self, epm: EdgeProgramManager) -> EdgeProgramManager:
7886
7987 new_programs [name ] = new_program
8088
81- if len (new_programs ) == 0 :
82- # No passes were run, return the old EdgeProgramManager.
83- return epm
89+ result = epm
8490
85- else :
86- # Return a new EdgeProgramManager with the updated programs.
87- return EdgeProgramManager (
91+ if len ( new_programs ) > 0 :
92+ # Use a new EdgeProgramManager with the updated programs if any update was performed .
93+ result = EdgeProgramManager (
8894 new_programs , copy .deepcopy (epm ._config_methods ), epm .compile_config
8995 )
96+
97+ if self .remove_io_quant_ops :
98+ result = result .transform ([RemoveIOQuantOpsPass (edge_program_manager = result )])
99+
100+ return result
0 commit comments