code: def test_non_rewrapping_torch_dispatch_subclass_as_parameter_throws_for_detach(
      self,
  ):
      # Define a subclass that does not rewrap for any function in its __torch_dispatch__ impl.
      class NonRewrappingTensor(torch.Tensor):
          @staticmethod
          def __new__(cls, t: torch.Tensor):
              r = super()._make_wrapper_subclass(
                  cls,
                  t.shape,
                  dtype=t.dtype,
                  requires_grad=t.requires_grad,
                  device=t.device,
              )
              return r
  
          def __init__(self, t) -> None:
              self.tensor: torch.Tensor = t
  
          __torch_function__ = torch._C._disabled_torch_function_impl
  
          @classmethod
          def __torch_dispatch__(
              cls, func, types, args=(), kwargs=None
          ):
              def unwrap(e) -> torch.Tensor:
                  if isinstance(e, NonRewrappingTensor):
                      t = e.tensor
                      return t
                  else:
                      return e
  
              r = func(
                  *tree_map(unwrap, args), **tree_map(unwrap, kwargs)
              )
              # Return an unwrapped tensor no longer of original subclass type.
              return r
  
      with self.assertRaisesRegex(
          RuntimeError,
          r"requires that detach\(\) returns an instance of the same type",
      ):
          param = nn.Parameter(NonRewrappingTensor(torch.randn(3)))
  
imports: import tempfile
  from copy import deepcopy
  from functools import partial
  from unittest import expectedFailure
  import torch
  from torch import nn
  from torch.nn.modules.lazy import LazyModuleMixin
  from torch.nn.utils.parametrize import register_parametrization, remove_parametrizations
  from torch.testing._internal.common_subclass import DiagTensorBelow, subclass_db
  from torch.testing._internal.common_utils import TestCase, instantiate_parametrized_tests, parametrize, run_tests, skipIfTorchDynamo, subtest
  from torch.testing._internal.logging_tensor import LoggingTensor
  from torch.utils._pytree import tree_map
label_desc: Use image node_id 10 for calling the TestSubclass obj's underlying member method code with example usage: obj.test_non_rewrapping_torch_dispatch_subclass_as_parameter_throws_for_detach() and returns: r, r, t, e