code: def apply_transpose(
      transpose: TransposeType, weight, match_shape=None, pt_to_tf=True
  ):
      """
      Apply a transpose to some weight then tries to reshape the weight to the same shape as a given shape, all in a
      framework agnostic way.
      """
      if transpose is TransposeType.CONV2D:
          # Conv2D weight:
          #    PT: (num_out_channel, num_in_channel, kernel[0], kernel[1])
          # -> TF: (kernel[0], kernel[1], num_in_channel, num_out_channel)
          axes = (2, 3, 1, 0) if pt_to_tf else (3, 2, 0, 1)
          weight = transpose_func(weight, axes=axes)
      elif transpose is TransposeType.CONV1D:
          # Conv1D weight:
          #    PT: (num_out_channel, num_in_channel, kernel)
          # -> TF: (kernel, num_in_channel, num_out_channel)
          weight = transpose_func(weight, axes=(2, 1, 0))
      elif transpose is TransposeType.SIMPLE:
          weight = transpose_func(weight)
  
      if match_shape is None:
          return weight
  
      if len(match_shape) < len(weight.shape):
          weight = squeeze(weight)
      elif len(match_shape) > len(weight.shape):
          weight = expand_dims(weight, axis=0)
  
      if list(match_shape) != list(weight.shape):
          try:
              weight = reshape(weight, match_shape)
          except AssertionError as e:
              e.args += (match_shape, match_shape)
              raise e
  
      return weight
  
file_path: H2O/h2o_flexgen/benchmark/third_party/transformers/src/transformers/modeling_tf_pytorch_utils.py
imports: import os
  import re
  import numpy
  from .utils import ExplicitEnum, expand_dims, is_numpy_array, is_torch_tensor, logging, reshape, squeeze, tensor_size
  from .utils import transpose
label_desc: Use image node_id 2 for calling a global function with example usage: apply_transpose(transpose, weight, match_shape, pt_to_tf) and returns: weight, weight