code: def optimizer_to(optim: torch.optim.Optimizer, device: str):
      for param in optim.state.values():
          # Not sure there are any global tensors in the state dict
          if isinstance(param, torch.Tensor):
              param.data = param.data.to(device)
              if param._grad is not None:
                  param._grad.data = param._grad.data.to(device)
          elif isinstance(param, dict):
              for subparam in param.values():
                  if isinstance(subparam, torch.Tensor):
                      subparam.data = subparam.data.to(device)
                      if subparam._grad is not None:
                          subparam._grad.data = subparam._grad.data.to(
                              device
                          )
  
imports: from pathlib import Path
  from typing import Any
  import torch
  from nebullvm.operations.base import Operation
  from open_alpha_tensor.config import BASE_CHECKPOINT_DATA_DIR, BASE_CHECKPOINT_DIR
  from open_alpha_tensor.core.modules.alpha_tensor import AlphaTensorModel
  from open_alpha_tensor.core.training import Trainer
label_desc: Use image node_id 1 for calling a global function with example usage: optimizer_to(optim, device) without return types