code: def to_tensor(X, device, accept_sparse=False):
      """Turn input data to torch tensor.
  
      Parameters
      ----------
      X : input data
        Handles the cases:
          * PackedSequence
          * numpy array
          * torch Tensor
          * scipy sparse CSR matrix
          * list or tuple of one of the former
          * dict with values of one of the former
  
      device : str, torch.device
        The compute device to be used. If set to 'cuda', data in torch
        tensors will be pushed to cuda tensors before being sent to the
        module.
  
      accept_sparse : bool (default=False)
        Whether to accept scipy sparse matrices as input. If False,
        passing a sparse matrix raises an error. If True, it is
        converted to a torch COO tensor.
  
      Returns
      -------
      output : torch Tensor
  
      """
      to_tensor_ = partial(to_tensor, device=device)
  
      if is_torch_data_type(X):
          return to_device(X, device)
      if TORCH_GEOMETRIC_INSTALLED and is_geometric_data_type(X):
          return to_device(X, device)
      if hasattr(X, "convert_to_tensors"):
          # huggingface transformers BatchEncoding
          return X.convert_to_tensors("pt")
      if isinstance(X, Mapping):
          return {key: to_tensor_(val) for key, val in X.items()}
      if isinstance(X, (list, tuple)):
          return [to_tensor_(x) for x in X]
      if np.isscalar(X):
          return torch.as_tensor(X, device=device)
      if isinstance(X, Sequence):
          return torch.as_tensor(np.array(X), device=device)
      if isinstance(X, np.ndarray):
          return torch.as_tensor(X, device=device)
      if sparse.issparse(X):
          if accept_sparse:
              return torch.sparse_coo_tensor(
                  X.nonzero(), X.data, size=X.shape
              ).to(device)
          raise TypeError(
              "Sparse matrices are not supported. Set "
              "accept_sparse=True to allow sparse matrices."
          )
  
      raise TypeError(
          "Cannot convert this data type to a torch tensor."
      )
  
imports: from collections.abc import Mapping, Sequence
  from contextlib import contextmanager
  from enum import Enum
  from functools import partial
  import io
  from itertools import tee
  import pathlib
  import warnings
  import numpy
  from scipy import sparse
  import sklearn
  from sklearn.exceptions import NotFittedError
  from sklearn.utils import _safe_indexing
  from sklearn.utils.validation import check_is_fitted
  import torch
  from torch.nn import BCELoss
  from torch.nn import BCEWithLogitsLoss
  from torch.nn import CrossEntropyLoss
  from torch.nn.utils.rnn import PackedSequence
  from torch.utils.data.dataset import Subset
  from skorch.exceptions import DeviceWarning
  from skorch.exceptions import NotInitializedError
label_desc: Use image node_id 4 for calling a global function with example usage: to_tensor(X, device, accept_sparse) and returns: to_device, to_device, X, unknown, unknown, torch, torch, torch, torch