code: def patch_dtype(
      from_dtype: Union[str, torch.dtype] = "fp64",
      to_dtype: Union[str, torch.dtype] = "fp32",
  ):
      """
      patch_dtype is used to change the tensor's dtype in users' application
      from `from_dtype` to `to_dtype`.
  
      e.g.
          >>> from bigdl.nano.pytorch.patching import patch_dtype
          >>> patch_dtype(from_dtype="fp64", to_dtype="fp32")
          >>> # will replace all tensors that has fp64 precision to fp32.
  
      :param from_dtype: the tensors' dtype to be replaced. default to "fp64"
      :param to_dtype: the tensors' dtype to use. default to "fp32"
      """
  
      if isinstance(from_dtype, str):
          invalidInputError(
              from_dtype.lower() in STR_TO_DTYPE.keys(),
              f"from_dtype should be one of {STR_TO_DTYPE.keys()}, "
              f"while get {from_dtype}.",
          )
          from_dtype = STR_TO_DTYPE[from_dtype.lower()]
  
      if isinstance(to_dtype, str):
          invalidInputError(
              to_dtype.lower() in STR_TO_DTYPE.keys(),
              f"to_dtype should be one of {STR_TO_DTYPE.keys()}, "
              f"while get {to_dtype}.",
          )
          to_dtype = STR_TO_DTYPE[to_dtype.lower()]
  
      # set default dtype
      torch.set_default_dtype(to_dtype)
  
      # patch tensor create functions
      for f in CREATE_TENSOR_FUNC:
          try:
              replace_attr(
                  torch,
                  f,
                  create_tensor_func(
                      getattr(torch, f), from_dtype, to_dtype
                  ),
              )
          except AttributeError:
              pass
  
      # patch Tensor.double
      # TODO: add others
      if from_dtype == torch.float64:
          replace_attr(torch.Tensor, "double", np_op_func)
  
imports: import torch
  from typing import Any, List, Optional, Union
  from bigdl.nano.utils.common import invalidInputError
label_desc: Use image node_id 4 for calling a global function with example usage: patch_dtype(from_dtype, to_dtype) without return types