code: def apply_to_tensor(
      x: Union[
          torch.Tensor,
          collections.Sequence,
          collections.Mapping,
          str,
          bytes,
      ],
      func: Callable,
  ) -> Union[
      torch.Tensor,
      collections.Sequence,
      collections.Mapping,
      str,
      bytes,
  ]:
      """Apply a function on a tensor or mapping, or sequence of tensors.
  
      Args:
          x: input tensor or mapping, or sequence of tensors.
          func: the function to apply on ``x``.
      """
      return apply_to_type(x, torch.Tensor, func)
  
imports: import collections.abc
  import functools
  import hashlib
  import logging
  import random
  import shutil
  import warnings
  from pathlib import Path
  from typing import Any, Callable, cast, Dict, List, Optional, TextIO, Tuple, Type, TypeVar, Union
  import torch
label_desc: Use image node_id 2 for calling a global function with example usage: apply_to_tensor(x, func) and returns: apply_to_type