code: def torch_type_from_str(
      identifier: str, type_name: str
  ) -> Union[torch.dtype, torch.device, torch.Size]:
      if type_name == "device":
          return torch.device(identifier)
      if type_name == "dtype":
          return getattr(torch, identifier[6:])
      if type_name == "Size":
          return torch.Size(json.loads(identifier))
      raise ValueError(
          f"Unexpected type: {type_name} for identifier: {identifier}."
      )
  
imports: import json
  from typing import Union
  import torch
  from ax.utils.common.typeutils import checked_cast
label_desc: Use image node_id 2 for calling a global function with example usage: torch_type_from_str(identifier, type_name) and returns: torch, getattr, torch