code: def _detach_tensor(tensor: Any, requires_grad: bool = False) -> Any:
      """Recursively detach all the tensors."""
      if isinstance(tensor, (list, tuple)):
          return tuple(_detach_tensor(t, requires_grad) for t in tensor)
      elif isinstance(tensor, dict):
          return {
              k: _detach_tensor(v, requires_grad)
              for k, v in tensor.items()
          }
      elif isinstance(tensor, torch.Tensor):
          tensor = tensor.detach()
          if requires_grad:
              tensor.requires_grad_()
          return tensor
      else:
          return tensor
  
imports: from __future__ import annotations
  from typing import Any, cast
  import torch
  import torch.nn
  from nni.mutable import Categorical, Mutable, Sample, SampleValidationError, MutableExpression, label_scope, auto_label
  from nni.nas.nn.pytorch import Repeat, recursive_freeze
  from .base import BaseSuperNetModule
  from .differentiable import DifferentiableMixedLayer, DifferentiableMixedInput
  from ._expression_utils import traverse_all_options
label_desc: Use image node_id 1 for calling a global function with example usage: _detach_tensor(tensor, requires_grad) and returns: tuple, unknown, tensor, tensor