code: def maybe_convert_str_to_dtype(
      dtype: _Union[str, _torch.dtype]
  ) -> _torch.dtype:
      _str_to_dtype_map = {
          "quint8": _torch.quint8,
          "qint8": _torch.qint8,
          "float32": _torch.float32,
      }
      if isinstance(dtype, str):
          dtype = dtype.lower()
          if dtype in _str_to_dtype_map:
              return _str_to_dtype_map[dtype]
          else:
              raise ValueError(f"Received unsupported dtype: {dtype}")
      elif isinstance(dtype, _torch.dtype):
          return dtype
      else:
          raise ValueError(
              f"Received unrecognized type for dtype: {type(dtype)}"
          )
  
file_path: coremltools/coremltools/optimize/torch/_utils/torch_utils.py
imports: import logging
  import operator
  import re
  from contextlib import contextmanager
  from typing import List
  from typing import Tuple
  from typing import Union
  import numpy
  import torch
label_desc: Use image node_id 2 for calling a global function with example usage: maybe_convert_str_to_dtype(dtype) and returns: _str_to_dtype_map, dtype