code: def __init__(self, device: Optional[torch.device] = None):
      with_cuda = torch.cuda.is_available()
      with_xpu = torch.xpu.is_available() if WITH_IPEX else False
  
      if device is None:
          if with_cuda:
              device = "cuda"
          elif with_xpu:
              device = "xpu"
          else:
              device = "cpu"
  
      self.device = torch.device(device)
      self.is_gpu = self.device.type in ["cuda", "xpu"]
  
      if (self.device.type == "cuda" and not with_cuda) or (
          self.device.type == "xpu" and not with_xpu
      ):
          warnings.warn(
              f"Requested device '{self.device.type}' is not "
              f"available, falling back to CPU"
          )
          self.device = torch.device("cpu")
  
      self.stream = None
      self.stream_context = nullcontext
      self.module = (
          getattr(torch, self.device.type) if self.is_gpu else None
      )
  
file_path: pytorch_geometric/torch_geometric/loader/prefetch.py
imports: import warnings
  from contextlib import nullcontext
  from functools import partial
  from typing import Any, Optional
  import torch
  from torch.utils.data import DataLoader
  from torch_geometric.typing import WITH_IPEX
label_desc: Use image node_id 1 to create a new DeviceHelper object  with example: obj = DeviceHelper(device)