code: def test_context_wrapping_set_grad_enabled_nested_function(self):
      modes = [True, False]
      for decorator in [True, False]:
          for i in range(2):
              torch._dynamo.reset()
  
              mode = modes[i]
              mode_inverse = modes[(i + 1) % 2]
  
              def fn(x):
                  with torch.set_grad_enabled(mode_inverse):
                      if decorator:
  
                          @torch.set_grad_enabled(mode)
                          def inner_func(x):
                              return x.sin()
  
                      else:
  
                          def inner_func(x):
                              return x.sin()
  
                          inner_func = torch.set_grad_enabled(mode)(
                              inner_func
                          )
  
                      # Consuming set_grad_enabled by calling it on a function
                      # should not mutate global state
                      assert torch.is_grad_enabled() == mode_inverse
  
                  with torch.set_grad_enabled(mode_inverse):
                      return inner_func(x)
  
          x = torch.zeros(10, requires_grad=True)
          opt_fn = torch.compile(fn, backend="eager", fullgraph=True)
          self.assertEqual(fn(x), opt_fn(x))
          self.assertEqual(fn(x).requires_grad, opt_fn(x).requires_grad)
  
imports: import unittest
  import torch
  import torch._dynamo.test_case
  import torch._dynamo.testing
  import torch.onnx.operators
  from torch._dynamo.testing import EagerAndRecordGraphs, normalize_gm, same
  from torch.nn import functional
  from torch.testing._internal.common_cuda import PLATFORM_SUPPORTS_FLASH_ATTENTION
  from torch.testing._internal.common_utils import TEST_WITH_ROCM
label_desc: Use image node_id 38 for calling the CtxManagerTests obj's underlying member method code with example usage: obj.test_context_wrapping_set_grad_enabled_nested_function() and returns: inner_func, x, x