code: def transform_transpose_pattern(pattern):
      is_deconv = pattern.conv.op_type == "conv_transpose"
  
      # get the bias
      bias = (
          pattern.add_or_sub.x.val
          if pattern.add_or_sub.x.val is not None
          else pattern.add_or_sub.y.val
      )
      is_first_input = pattern.add_or_sub.y.val is not None
      is_sub = pattern.add_or_sub.op_type == "sub"
  
      # get the conv bias/weight
      conv_shape = pattern.conv.outputs[0].shape
      Cout = conv_shape[1]
      conv_weight = pattern.conv.weight.val
      conv_weight_type = conv_weight.dtype
      conv_bias = (
          np.zeros(Cout).astype(conv_weight_type)
          if pattern.conv.bias is None
          else pattern.conv.bias.val
      )
  
      bias = _bias_mod_and_validity(bias, Cout, pattern)
  
      # compute the new bias
      if is_sub:
          if is_first_input:
              bias = -bias
          else:
              conv_bias = -conv_bias
  
      new_bias = conv_bias + bias
  
      # compute the new weight
      if is_sub and not is_first_input:
          new_weight = -conv_weight
      else:
          new_weight = conv_weight
  
      # create a new conv op with the new weight, bias value, copying rest of the attributes
      conv_kargs = {
          "weight": new_weight,
          "bias": new_bias,
          "before_op": pattern.conv,
      }
  
      for k, v in pattern.conv.inputs.items():
          if k in ["weight", "bias"]:
              continue
          conv_kargs[k] = v
  
      if is_deconv:
          x = mb.conv_transpose(**conv_kargs)
      else:
          x = mb.conv(**conv_kargs)
  
      # create a new transpose op
      out_name = pattern.add_or_sub.outputs[0].name
      tranpose_kargs = {
          "x": x,
          "name": out_name,
          "before_op": pattern.transpose,
      }
      for k, v in pattern.transpose.inputs.items():
          if k == "x":
              continue
          tranpose_kargs[k] = v
      x = mb.transpose(**tranpose_kargs)
  
      pattern.add_or_sub.enclosing_block.replace_uses_of_var_after_op(
          anchor_op=pattern.add_or_sub,
          old_var=pattern.add_or_sub.outputs[0],
          new_var=x,
      )
  
      # Remove all the ops at once
      pattern.block.remove_ops(pattern.op_list())
  
file_path: coremltools/coremltools/converters/mil/experimental/passes/generic_conv_bias_fusion.py
imports: import os
  import numpy
  from coremltools import _logger
  from coremltools.converters.mil import Builder
  from coremltools.converters.mil.experimental.passes.generic_pass_infrastructure import register_generic_pass
  from coremltools.converters.mil.mil import types
label_desc: Use image node_id 5 for calling a global function with example usage: transform_transpose_pattern(pattern) without return types