code: def convert_optimized_rnnstack(cudnn_model):
      """
      Converts model that contains cudnn optimized_rnnstack to use non-cudnn functions,
      so it can be used in non-CUDA environment
  
      Args:
          cudnn_model: a model that contains optimized_rnnstacks
      Returns:
          Converted model on GEMM based implementation of rnn that can be used on CPU
      """
  
      class CuDNNOptimizedRNNConverter:
          def __init__(self, model):
              self.filter = (
                  lambda x: type(x) == C.Function
                  and x.root_function.op_name == "OptimizedRNNStack"
              )
              all_cudnn_rnns = C.logging.graph.depth_first_search(
                  model, self.filter, depth=-1
              )
              unique_params = set(
                  [
                      cudnn_rnn.parameters[0]
                      for cudnn_rnn in all_cudnn_rnns
                  ]
              )
              self.map_param_to_func = {p: None for p in unique_params}
  
          def converter(self, cudnn_rnn):
              param = cudnn_rnn.parameters[0]
              if self.map_param_to_func[param]:
                  # shared parameter, clone
                  converted = self.map_param_to_func[param][0].clone(
                      C.CloneMethod.share,
                      {
                          self.map_param_to_func[param][
                              1
                          ]: cudnn_rnn.inputs[0],
                          self.map_param_to_func[param][
                              2
                          ]: C.placeholder(),
                      },
                  )
              else:
                  # unique or first parameter, convert
                  converted = _from_optimized_rnnstack(cudnn_rnn)
                  self.map_param_to_func[param] = (
                      converted,
                      cudnn_rnn.inputs[0],
                      cudnn_rnn.output,
                  )
  
              return converted
  
      optimizedRNNConverter = CuDNNOptimizedRNNConverter(cudnn_model)
      return convert(
          cudnn_model,
          optimizedRNNConverter.filter,
          optimizedRNNConverter.converter,
      )
  
imports: import numpy
  import cntk
  from .converter import *
label_desc: Use image node_id 2 for calling a global function with example usage: convert_optimized_rnnstack(cudnn_model) and returns: convert, converted