code: def test_double_backward_errors(self):
      # Remove this test after we get double backward to actually work
      for grad_output in (torch.tensor(1.0, requires_grad=True), None):
          x = torch.tensor(1.0, requires_grad=True)
          err = "torch.compile with aot_autograd does not currently support double backward"
  
          # The following cases should be equivalent:
  
          # (1) double backward entirely inside compiled function
          def f1(x):
              y = x.sin().exp()
              (gx,) = torch.autograd.grad(
                  y, x, create_graph=True, grad_outputs=grad_output
              )
              torch.autograd.grad(gx, x)
              return gx
  
          compiled_f1 = torch.compile(backend="aot_eager")(f1)
          f1(x)
          with self.assertRaisesRegex(RuntimeError, err):
              compiled_f1(x)
  
          # (2) the second half of double backward outside compiled function
          def f2(x):
              y = x.sin().exp()
              (gx,) = torch.autograd.grad(
                  y, x, create_graph=True, grad_outputs=grad_output
              )
              return gx
  
          compiled_f2 = torch.compile(backend="aot_eager")(f2)
          gx = compiled_f2(x)
          with self.assertRaisesRegex(RuntimeError, err):
              torch.autograd.grad(gx, x)
  
          # (3) double backward entirely outside compiled function
          def f3(x):
              y = x.sin().exp()
              return y
  
          compiled_f3 = torch.compile(backend="aot_eager")(f3)
          y = compiled_f3(x)
          (gx,) = torch.autograd.grad(
              y, x, create_graph=True, grad_outputs=grad_output
          )
          with self.assertRaisesRegex(RuntimeError, err):
              torch.autograd.grad(gx, x)
  
      # create_graph=False
      def f4(x):
          y = x.sin().exp()
          return y
  
      compiled_f4 = torch.compile(backend="aot_eager")(f4)
      x = torch.tensor(1.0, requires_grad=True)
      y = compiled_f4(x)
      (gx,) = torch.autograd.grad(
          y, x, create_graph=False, grad_outputs=grad_output
      )
  
imports: import re
  from textwrap import dedent
  from unittest.mock import patch
  import torch
  import torch._dynamo
  import torch._dynamo.test_case
  import torch.fx.traceback
  import torch.utils._pytree
  from torch._dynamo.testing import CompileCounter, expectedFailureDynamic, rand_strided
  from torch._functorch.aot_autograd import _aot_export_function, create_functional_call
  from torch.profiler import profile
  from torch.testing._internal.common_utils import compare_equal_outs_and_grads
label_desc: Use image node_id 10 for calling the AotAutogradFallbackTests obj's underlying member method code with example usage: obj.test_double_backward_errors() and returns: y, gx, gx, y