code: def apply_to_tensors(x: Any, fn: Callable):
      if torch.is_tensor(x):
          return fn(x)
      elif isinstance(x, list):
          return [apply_to_tensors(t, fn) for t in x]
      elif isinstance(x, tuple):
          return tuple(apply_to_tensors(t, fn) for t in x)
      elif isinstance(x, dict):
          return {
              key: apply_to_tensors(val, fn) for key, val in x.items()
          }
      else:
          return x
  
file_path: ColossalAI/colossalai/legacy/zero/sharded_model/_utils.py
imports: from typing import Any, Callable, List, Tuple, Union
  import torch
  import torch.nn.functional
  from colossalai.legacy.zero.gemini.stateful_tensor import StatefulTensor
label_desc: Use image node_id 7 for calling a global function with example usage: apply_to_tensors(x, fn) and returns: fn, unknown, tuple, unknown, x