class_docstr: In the process of generating masks, a large number of operations like pooling or upsampling are involved.
  This class provides tensor-related scaling functions for a given scaling kernel.
  
  Similar to the concept of convolutional kernel, the scaling kernel also moves over the tensor and does operations.
  The scaling kernel in this class is defined by two parts, kernel size and scaling function (shrink and expand).
  
  Parameters
  ----------
  kernel_size
      kernel_size is the scale, which determines how large a range in a tensor should shrink to a value,
      or how large a value in a tensor should expand.
      `-1` can be used to indicate that it is a full step in this dimension,
      and the dimension where -1 is located will be reduced or unsqueezed during scaling.
  
      Example::
  
          kernel_size = [2, -1]
  
          # For a given 2D-tensor with size (4, 3),
          [[1, 2, 3],
           [4, 5, 6],
           [7, 8, 9],
           [10, 11, 12]]
  
          # shrinking it by shrink function, its size becomes (2,) after shrinking:
          [shrink([[1, 2, 3], [4, 5, 6]]), shrink([[7, 8, 9], [10, 11, 12]])]
  
          # expanding it by expand function with a given expand size,
          # if the expand function is repeating the values, and the expand size is (4, 6, 2):
          [[[1, 1],
            [1, 1],
            [2, 2],
            [2, 2],
            [3, 3],
            [3, 3]],
              ...
            [9, 9]]]
          # note that the original tensor with size (4, 3) will unsqueeze to size (4, 3, 1) at first
          # for the `-1` in kernel_size, then expand size (4, 3, 1) to size (4, 6, 2).
  kernel_padding_mode
      'front' or 'back', default is 'front'.
      If set 'front', for a given tensor when shrinking,
      padding `1` at front of kernel_size until `len(tensor.shape) == len(kernel_size)`;
      for a given expand size when expanding,
      padding `1` at front of kernel_size until `len(expand_size) == len(kernel_size)`.
      If set 'back', for a given tensor when shrinking,
      padding `-1` at back of kernel_size until `len(tensor.shape) == len(kernel_size)`;
      for a given expand size when expanding,
      padding `-1` at back of kernel_size until `len(expand_size) == len(kernel_size)`.
  
      The default padding value (1 or -1) can be set by passing ``kernel_padding_val``.
  kernel_padding_val
      If ``kernel_padding_val`` is not None, the padding value in kernel padding will be specifed.
code: def shrink(
      self,
      target: Tensor,
      reduce_func: Callable[[Tensor], Tensor] | None = None,
      keepdim: bool = False,
  ) -> Tensor:
      # Canonicalize kernel_size to target size length at first.
      # If kernel_padding_mode is 'front', padding 1 at the front of `self.kernel_size`.
      # e.g., padding kernel_size [2, 2] to [1, 2, 2] when target size length is 3.
      # If kernel_padding_mode is 'back', padding -1 at the back of `self.kernel_size`.
      # e.g., padding kernel_size [1] to [1, -1, -1] when target size length is 3.
      if self.kernel_padding_mode == "front":
          kernel_size = self._padding(
              self.kernel_size,
              len(target.shape),
              self.kernel_padding_val,
              "front",
          )
      elif self.kernel_padding_mode == "back":
          kernel_size = self._padding(
              self.kernel_size,
              len(target.shape),
              self.kernel_padding_val,
              "back",
          )
      else:
          raise ValueError(
              f"Unsupported kernel padding mode: {self.kernel_padding_mode}."
          )
      return self._shrink(target, kernel_size, reduce_func, keepdim)
  
file_path: nni/nni/compression/utils/scaling.py
imports: from __future__ import annotations
  from functools import reduce
  from typing import Callable, List
  from typing_extensions import Literal
  import torch
  from torch import Tensor
label_desc: Use image node_id 5 for calling the Scaling obj's underlying member method code with example usage: obj.shrink(target, reduce_func, keepdim) and returns: self