code: def to_device(x: Any, device: Optional[torch.device] = None) -> Any:
      """Move object to device if it is a tensor.
  
      Args:
          x (Any): Object to be moved.
          device (Optional[torch.device], optional): Target device. Defaults to None.
  
      Returns:
          Any: Moved object.
      """
      if isinstance(x, torch.Tensor):
          return x.to(device)
      return x
  
file_path: colossalai/colossalai/pipeline/schedule/_utils.py
imports: from collections import OrderedDict
  from typing import Any, List, Optional, Tuple
  import torch
  import torch.cuda
  from torch.nn import Module
  from torch.utils._pytree import SUPPORTED_NODES, TreeSpec, _register_pytree_node, tree_flatten, tree_map, tree_unflatten
label_desc: Use image node_id 5 for calling a global function with example usage: to_device(x, device) and returns: x, x