code: def to_tensor(
      X: Union[np.ndarray, torch.Tensor], device: torch.device, **kwargs
  ) -> Optional[torch.Tensor]:
      """
      Converts tensor to `torch.Tensor`
  
      Returns
      -------
      `torch.Tensor` conversion.
      """
      if X is not None:
          if isinstance(X, torch.Tensor):
              return X.to(device)
  
          return torch.tensor(X).to(device)
  
      return None
  
imports: import os
  import random
  from typing import List, Dict, Callable, Union, Optional, TYPE_CHECKING
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.utils.data import DataLoader, Dataset
  from alibi.explainers.backends.cfrl_base import CounterfactualRLDataset
  from alibi.models.pytorch.actor_critic import Actor, Critic
label_desc: Use image node_id 14 for calling a global function with example usage: to_tensor(X, device) and returns: None, torch, X