docstr: Sets the device if using pytorch backend.
  
  Parameters
  ----------
  device: str (default: None)
      Either 'cuda': to create arrays on GPU, or 'cpu' to create arrays on CPU.
      If None, sets to cuda if GPU is available else uses CPU.
docstr_tok: ["Sets","the","device","if","using","pytorch","backend",".","Parameters","--","--","--","--","--","device",":","str","(","default",":","None",")","Either","'cuda","'",":","to","create","arrays","on","GPU",",","or","'cpu","'","to","create","arrays","on","CPU",".","If","None",",","sets","to","cuda","if","GPU","is","available","else","uses","CPU","."]
code: def set_device(self, device=None):
      """
      Sets the device if using pytorch backend.
  
      Parameters
      ----------
      device: str (default: None)
          Either 'cuda': to create arrays on GPU, or 'cpu' to create arrays on CPU.
          If None, sets to cuda if GPU is available else uses CPU.
      """
      if self.BACKEND == "numpy":
          raise ValueError(
              f"Current backend is numpy. Device can only be set for torch backend"
          )
  
      if device is None:
          if torch.cuda.is_available():
              self.DEVICE = torch.device("cuda:0")
          else:
              self.DEVICE = torch.device("cpu")
      else:
          if not device.startswith(("cuda", "cpu")):
              raise ValueError(
                  f"device must be either 'cuda', 'cuda:x' or 'cpu'. Got: {device}"
              )
          elif device.startswith("cuda"):
              if torch.cuda.is_available():
                  self.DEVICE = torch.device(device)
          else:
              self.DEVICE = torch.device(device)
  
file_path: pgmpy/pgmpy/global_vars.py
imports: import logging
  import numpy
  import torch
label_desc: Use image node_id 2 for calling the Config obj's underlying member method code with example usage: obj.set_device(device) without return types