code: def change_device(var, device):
      if isinstance(var, torch.Tensor):
          if var.device == "cpu":
              var.to(device)
              return var
          elif var.device != device:
              return var.cpu().to(device)
          else:
              return var
      if isinstance(var, dict):
          for key in var.keys():
              if isinstance(var[key], torch.Tensor):
                  var[key] = var[key].to(device)
          return var
  
      return torch.from_numpy(var).float().to(device)
  
file_path: gluonts/src/gluonts/nursery/robust-mts-attack/pts/trainer.py
imports: import time
  from typing import List, Optional, Union
  from tqdm.auto import tqdm
  import torch
  import torch.nn
  from torch.optim import Adam
  from torch.optim.lr_scheduler import OneCycleLR
  from torch.utils.data import DataLoader
  from gluonts.core.component import validated
label_desc: Use image node_id 2 for calling a global function with example usage: change_device(var, device) and returns: torch, var, var, var, var