From 33b5010e624d0c649e121a323eda29dfa4074e2a Mon Sep 17 00:00:00 2001 From: Yang Chen <40417152+yangchen-MS@users.noreply.github.com> Date: Sat, 28 Mar 2020 16:15:45 -0700 Subject: [PATCH] skip optional inputs for scan subgraphs (#3349) * skip optional inputs for scan subgraphs We may have cases where the subgraph has optionial inputs that appear in both subgraph's input and initializer, but not in the node's input. In such cases, the input model might be invalid, but let's not choke on it. Instead, let's issue a warning, skip the optional inputs, and keep going forward. * address CR feedback --- .../core/providers/nuphar/scripts/symbolic_shape_infer.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/nuphar/scripts/symbolic_shape_infer.py b/onnxruntime/core/providers/nuphar/scripts/symbolic_shape_infer.py index d834026f81..5ef2ac4c2a 100755 --- a/onnxruntime/core/providers/nuphar/scripts/symbolic_shape_infer.py +++ b/onnxruntime/core/providers/nuphar/scripts/symbolic_shape_infer.py @@ -903,7 +903,11 @@ class SymbolicShapeInference: scan_input_axes = get_attribute(node, 'scan_input_axes', [0]*num_scan_inputs) num_scan_states = len(node.input) - num_scan_inputs scan_input_axes = [handle_negative_axis(ax, self._get_shape_rank(node, i + num_scan_states)) for i, ax in enumerate(scan_input_axes)] - for i, si in enumerate(subgraph.input): + # We may have cases where the subgraph has optionial inputs that appear in both subgraph's input and initializer, + # but not in the node's input. In such cases, the input model might be invalid, but let's skip those optional inputs. + assert len(subgraph.input) >= len(node.input) + subgraph_inputs = subgraph.input[:len(node.input)] + for i, si in enumerate(subgraph_inputs): subgraph_name = si.name si.CopyFrom(self.known_vi_[node.input[i]]) if i >= num_scan_states: