code: def _get_and_verify_dtype(
      config: PretrainedConfig,
      dtype: str,
  ) -> torch.dtype:
      # NOTE: getattr(config, "torch_dtype", torch.float32) is not correct
      # because config.torch_dtype can be None.
      config_dtype = getattr(config, "torch_dtype", None)
      if config_dtype is None:
          config_dtype = torch.float32
  
      dtype = dtype.lower()
      if dtype == "auto":
          if config_dtype == torch.float32:
              # Following the common practice, we use float16 for float32 models.
              torch_dtype = torch.float16
          else:
              torch_dtype = config_dtype
      else:
          if dtype not in _STR_DTYPE_TO_TORCH_DTYPE:
              invalidInputError(False, f"Unknown dtype: {dtype}")
          torch_dtype = _STR_DTYPE_TO_TORCH_DTYPE[dtype]
  
      # Verify the dtype.
      if torch_dtype != config_dtype:
          if torch_dtype == torch.float32:
              # Upcasting to float32 is allowed.
              pass
          elif config_dtype == torch.float32:
              # Downcasting from float32 to float16 or bfloat16 is allowed.
              pass
          else:
              # Casting between float16 and bfloat16 is allowed with a warning.
              logger.warning(
                  f"Casting {config_dtype} to {torch_dtype}."
              )
  
      return torch_dtype
  
imports: from typing import Optional
  import torch
  from transformers import AutoConfig, PretrainedConfig
  from bigdl.llm.vllm.logger import init_logger
  from bigdl.llm.utils.common import invalidInputError
label_desc: Use image node_id 1 for calling a global function with example usage: _get_and_verify_dtype(config, dtype) and returns: torch_dtype