code: def make_convolution_transpose_fn_with_dilation(
      filter_shape,
      strides,
      padding,
      rank=2,
      dilations=None,
      dtype=tf.int32,
      validate_args=False,
      name=None,
  ):
      """Like `tf.nn.conv2d` except applies batch of kernels to batch of `x`.
  
      This version tends to be fastest on GPU. It implements the transposed
      convolution as a regular convolution of an image that is dilated by
      interleaving rows and columns of zeros equal to the number of strides.
  
      Args:
        filter_shape: ...
        strides: ...
        padding: ...
        rank: ...
        dilations: ...
        dtype: ...
        validate_args: ...
        name: ...
      Returns:
        convolution_transpose_fn: A callable that takes an input `Tensor` and kernel
          and applies the transpose convolution operation.
      """
      with tf.name_scope(
          name or "make_convolution_transpose_fn_with_dilation"
      ):
          if tf.get_static_value(rank) != 2:
              raise NotImplementedError(
                  "Argument `rank` currently only supports `2`; "
                  'saw "{}".'.format(rank)
              )
          [
              filter_shape,
              rank,
              strides,
              padding,
              dilations,
          ] = prepare_conv_args(
              filter_shape,
              rank=rank,
              strides=strides,
              padding=padding,
              dilations=dilations,
              is_transpose=True,
              validate_args=validate_args,
          )
  
          sh, sw = strides
          fh, fw = filter_shape
  
          pad_values = [
              _get_transpose_conv_dilated_padding(
                  k, stride=s, dilation=d, padding=padding
              )
              for (k, s, d) in zip(filter_shape, strides, dilations)
          ]
  
          def op(x, kernel):
              input_dtype = dtype_util.common_dtype(
                  [x, kernel], dtype_hint=tf.float32
              )
              x = tf.convert_to_tensor(x, dtype=input_dtype, name="x")
              kernel = tf.convert_to_tensor(
                  kernel, dtype=input_dtype, name="kernel"
              )
  
              batch_shape, event_shape = ps.split(
                  ps.shape(x), num_or_size_splits=[-1, 3]
              )
              xh, xw, c_in = ps.unstack(event_shape, num=3)
              kernel_shape = ps.shape(kernel)
              assertions = _maybe_validate_input_shapes(
                  kernel_shape,
                  channels_in=c_in,
                  filter_height=fh,
                  filter_width=fw,
                  validate_args=validate_args,
              )
  
              with tf.control_dependencies(assertions):
                  # If the kernel does not have batch shape, fall back to
                  # `conv2d_transpose` (unless dilations > 1, which is not implemented in
                  # `conv2d_transpose`).
                  if tf.get_static_value(ps.rank(kernel)) == 2 and all(
                      d == 1 for d in dilations
                  ):
                      return _call_conv2d_transpose(
                          x,
                          kernel,
                          filter_shape,
                          strides,
                          padding,
                          dilations,
                          kernel_shape[-1],
                          batch_shape,
                          event_shape,
                      )
  
                  idx, shape = im2row_index(
                      (
                          xh * sh + sum(pad_values[0]),
                          xw * sw + sum(pad_values[1]),
                          c_in,
                      ),
                      block_shape=filter_shape,
                      slice_step=(1, 1),
                      dilations=dilations,
                      dtype=dtype,
                      transpose=True,
                  )
  
                  n = ps.maximum(0, ps.rank(x) - 3)
                  paddings = ps.pad(
                      pad_values,
                      paddings=[[n, 1], [0, 0]],
                      constant_values=0,
                  )
  
                  # Interleave the rows and columns of the input with rows and columns of
                  # zeros equal to the number of strides.
                  x_half_dilated = tf.concat(
                      [
                          tf.zeros(
                              ps.concat(
                                  [
                                      batch_shape,
                                      (xh * xw, sw - 1, c_in),
                                  ],
                                  axis=0,
                              ),
                              dtype=input_dtype,
                          ),
                          tf.reshape(
                              x,
                              shape=ps.concat(
                                  [batch_shape, (xh * xw, 1, c_in)],
                                  axis=0,
                              ),
                          ),
                      ],
                      axis=-2,
                  )
                  y = tf.reshape(
                      x_half_dilated,
                      shape=ps.concat(
                          [batch_shape, (xh, 1, xw * sw, c_in)], axis=0
                      ),
                  )
  
                  x = tf.reshape(
                      tf.concat(
                          [
                              tf.zeros(
                                  ps.concat(
                                      [
                                          batch_shape,
                                          (xh, sh - 1, xw * sw, c_in),
                                      ],
                                      axis=0,
                                  ),
                                  dtype=input_dtype,
                              ),
                              y,
                          ],
                          axis=-3,
                      ),
                      shape=ps.concat(
                          [batch_shape, (xh * sh, xw * sw, c_in)],
                          axis=0,
                      ),
                  )
  
                  truncations = -ps.minimum(
                      ps.cast(paddings, dtype=tf.int32), 0
                  )
                  truncate_start, truncate_end = ps.unstack(
                      truncations, axis=1
                  )
                  x_truncate = tf.slice(
                      x,
                      begin=truncate_start,
                      size=ps.shape(x)
                      - (truncate_start + truncate_end),
                  )
  
                  x_pad = tf.pad(
                      x_truncate,
                      paddings=ps.maximum(paddings, 0),
                      constant_values=0,
                  )
  
                  flat_shape = ps.pad(
                      batch_shape, paddings=[[0, 1]], constant_values=-1
                  )
                  flat_x = tf.gather(
                      tf.reshape(x_pad, shape=flat_shape),
                      indices=idx,
                      axis=-1,
                  )
                  im_x = tf.reshape(
                      flat_x,
                      shape=ps.concat([batch_shape, shape], axis=0),
                  )
                  return tf.matmul(im_x, kernel[..., tf.newaxis, :, :])
  
          return op
  
imports: import tensorflow.compat.v2
  from tensorflow_probability.python.experimental.nn.util import utils
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
label_desc: Use image node_id 7 for calling a global function with example usage: make_convolution_transpose_fn_with_dilation(filter_shape, strides, padding, rank, dilations, dtype, validate_args, name) and returns: op, tf, _call_conv2d_transpose