@@ -118,10 +118,19 @@ def __init__(
118118 external_ids ,
119119 edge_program : torch .export .ExportedProgram ,
120120 enable_tensor_dump ,
121+ is_qnn_partitioner = True ,
121122 ) -> None :
123+ # is_qnn_partitioner: True for the real qnn_partitioner / qnn_preprocess
124+ # flows, where external_ids is built from the program being processed so
125+ # graph-input ids resolve correctly.
126+ # Set False for lpai_partition_fallback_support pass, where constructor
127+ # takes an older exported_program whose node objects differ from the
128+ # live graph; the input_{id} naming would mismatch there, so we skip
129+ # it during op validation.
122130 self .external_ids = external_ids or {}
123131 self .edge_program = edge_program
124132 self .enable_tensor_dump = enable_tensor_dump
133+ self .is_qnn_partitioner = is_qnn_partitioner
125134
126135 def get_node (self , node ):
127136 """
@@ -371,9 +380,11 @@ def get_tensor_type(
371380 is_output = is_graph_output (node )
372381 # handle logic for input/output tensors
373382 if is_input or is_output :
374- assert (
375- node in self .external_ids
376- ), f"Node { node } , is_input: { is_input } , is_output: { is_output } , ext_ids: { self .external_ids .keys ()} "
383+ # For more info about existence of self.is_qnn_partitioner, check constructor for explanation.
384+ assert not self .is_qnn_partitioner or node in self .external_ids , (
385+ f"Node { node } , is_input: { is_input } , is_output: { is_output } , "
386+ f"ext_ids: { self .external_ids .keys ()} "
387+ )
377388 if is_input :
378389 return PyQnnManager .Qnn_TensorType_t .QNN_TENSOR_TYPE_APP_WRITE
379390 if is_output :
@@ -422,21 +433,24 @@ def get_tensor_name(
422433 # the input order between QNN and the original graph’s forward function may differ.
423434 # The `mutbuf_{id}` is utilized for mapping I/O of mutable buffer at runtime.
424435 # The `output_` is identified as the graph’s output at runtime to prevent confusion with per_tensor_dump.
425- if is_mutable_buffer_input (node , self .edge_program ):
426- fqn = self .edge_program .graph_signature .inputs_to_buffers [node .target ]
427- position_index = list (
428- self .edge_program .graph_signature .buffers_to_mutate .values ()
429- ).index (fqn )
430- tensor_name = f"input_{ str (self .external_ids [node ])} _mutbuf_{ str (position_index )} _{ tensor_name } "
431- elif is_graph_input (node , self .edge_program ):
432- tensor_name = f"input_{ str (self .external_ids [node ])} _{ tensor_name } "
433- elif is_mutable_buffer_output (node , self .edge_program ):
434- position_index = list (
435- self .edge_program .graph_signature .buffers_to_mutate .keys ()
436- ).index (node .name )
437- tensor_name = f"output_mutbuf_{ position_index } _{ tensor_name } "
438- elif is_graph_output (node ):
439- tensor_name = f"output_{ tensor_name } "
436+
437+ # For more info about self.is_qnn_partitioner, check constructor for explanation.
438+ if self .is_qnn_partitioner :
439+ if is_mutable_buffer_input (node , self .edge_program ):
440+ fqn = self .edge_program .graph_signature .inputs_to_buffers [node .target ]
441+ position_index = list (
442+ self .edge_program .graph_signature .buffers_to_mutate .values ()
443+ ).index (fqn )
444+ tensor_name = f"input_{ str (self .external_ids [node ])} _mutbuf_{ str (position_index )} _{ tensor_name } "
445+ elif is_graph_input (node , self .edge_program ):
446+ tensor_name = f"input_{ str (self .external_ids [node ])} _{ tensor_name } "
447+ elif is_mutable_buffer_output (node , self .edge_program ):
448+ position_index = list (
449+ self .edge_program .graph_signature .buffers_to_mutate .keys ()
450+ ).index (node .name )
451+ tensor_name = f"output_mutbuf_{ position_index } _{ tensor_name } "
452+ elif is_graph_output (node ):
453+ tensor_name = f"output_{ tensor_name } "
440454
441455 # Only add qcom_tensor_name when enable tensor dump.
442456 # Only runs in qnn_preprocess (not op validation) since that's when
0 commit comments