code: def test_tensor_autograd(self):
      # dynamo errors when Tensor.requires_grad_ change the autograd state
      def f1(a):
          a.requires_grad_(True)
          b = a + a
          return b
  
      # dynamo errors when Tensor.requires_grad_ change the autograd state
      def f2(a):
          a.requires_grad_(False)
          b = a + a
          return b
  
      # dynamo always errors on Tensor.requires_grad
      def f3(a):
          a.requires_grad = False
          b = a + a
          return b
  
      export(f1, (torch.randn(10, requires_grad=True),))
      export(f2, (torch.randn(10, requires_grad=False),))
  
      with self.assertRaises(RuntimeError):
          export(f1, (torch.randn(10, requires_grad=False),))
      with self.assertRaises(RuntimeError):
          export(f2, (torch.randn(10, requires_grad=True),))
      with self.assertRaises(RuntimeError):
          export(f3, (torch.randn(10, requires_grad=False),))
  
file_path: pytorch/test/export/test_safeguard.py
imports: import unittest
  import torch
  import torch._dynamo
  from torch.export import export
  from torch.testing._internal.common_utils import run_tests, TestCase
label_desc: Use image node_id 2 for calling the TestSafeguard obj's underlying member method code with example usage: obj.test_tensor_autograd() and returns: b, b, b