code: def convert_image_dtype(
      image: torch.Tensor, dtype: torch.dtype = torch.float
  ) -> torch.Tensor:
      if image.dtype == dtype:
          return image
  
      if image.is_floating_point():
          # TODO: replace with dtype.is_floating_point when torchscript supports it
          if torch.tensor(0, dtype=dtype).is_floating_point():
              return image.to(dtype)
  
          # float to int
          if (
              image.dtype == torch.float32
              and dtype in (torch.int32, torch.int64)
          ) or (image.dtype == torch.float64 and dtype == torch.int64):
              msg = f"The cast from {image.dtype} to {dtype} cannot be performed safely."
              raise RuntimeError(msg)
  
          # https://github.com/pytorch/vision/pull/2078#issuecomment-612045321
          # For data in the range 0-1, (float * 255).to(uint) is only 255
          # when float is exactly 1.0.
          # `max + 1 - epsilon` provides more evenly distributed mapping of
          # ranges of floats to ints.
          eps = 1e-3
          max_val = float(_max_value(dtype))
          result = image.mul(max_val + 1.0 - eps)
          return result.to(dtype)
      else:
          input_max = float(_max_value(image.dtype))
  
          # int to float
          # TODO: replace with dtype.is_floating_point when torchscript supports it
          if torch.tensor(0, dtype=dtype).is_floating_point():
              image = image.to(dtype)
              return image / input_max
  
          output_max = float(_max_value(dtype))
  
          # int to int
          if input_max > output_max:
              # factor should be forced to int for torch jit script
              # otherwise factor is a float and image // factor can produce different results
              factor = int((input_max + 1) // (output_max + 1))
              image = torch.div(image, factor, rounding_mode="floor")
              return image.to(dtype)
          else:
              # factor should be forced to int for torch jit script
              # otherwise factor is a float and image * factor can produce different results
              factor = int((output_max + 1) // (input_max + 1))
              image = image.to(dtype)
              return image * factor
  
imports: import warnings
  from typing import List, Optional, Tuple, Union
  import torch
  from torch import Tensor
  from torch.nn.functional import conv2d, grid_sample, interpolate, pad
label_desc: Use image node_id 8 for calling a global function with example usage: convert_image_dtype(image, dtype) and returns: image, result, image, unknown, image, unknown