code: def _construct_subgraph(sym_out, sym_states):
      sym_out = _as_list(sym_out)
      sym_states = _as_list(sym_states)
      all_outputs = []
      all_outputs.extend(sym_out)
      all_outputs.extend(sym_states)
      g = symbol.Group(all_outputs)
  
      flat_out = []
      all_input_names = g.list_inputs()
      output_names = {o.name for o in sym_out}
      for o in sym_out:
          if o.name in all_input_names:
              flat_out.append(symbol.op.identity(o))
          else:
              flat_out.append(o)
  
      for s in sym_states:
          if s.name in all_input_names or s.name in output_names:
              flat_out.append(symbol.op.identity(s))
          else:
              flat_out.append(s)
      return symbol.Group(flat_out)
  
file_path: mxnet/python/mxnet/ndarray/numpy_extension/control_flow.py
imports: from .None import _api_internal
  from .._internal import NDArrayBase
  from ...util import set_module
  from ...numpy import ndarray
  from ...symbol import Symbol
  from ...base import _as_list
  from ...None import symbol, _deferred_compute, autograd
  from ...attribute import AttrScope, current
label_desc: Use image node_id 4 for calling a global function with example usage: _construct_subgraph(sym_out, sym_states) and returns: symbol