We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[HF: AllenaiLongformerBase, GoogleFnet] RuntimeError: CUDA error: an illegal memory access was encountered
Repro:
```
benchmarks/huggingface.py -d cuda --inductor --training --float32 --use-eval-mode -k   AllenaiLongformerBase
benchmarks/huggingface.py -d cuda --inductor --training --float32 --use-eval-mode -k   GoogleFnet
```

Error:
```
RuntimeError: CUDA error: an illegal memory access was encountered
```

The error disappears if we set `config.triton.cudagraph` to False.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `torchinductor/compile_fx.py`
Content:
```
1 import dataclasses
2 import functools
3 import logging
4 import operator
5 from typing import List
6 
7 import torch.fx
8 from functorch.compile import min_cut_rematerialization_partition
9 
10 from torchdynamo.debug_utils import wrap_debug
11 from torchdynamo.optimizations.backends import aot_autograd
12 from torchdynamo.optimizations.normalize import normalize_ir
13 from torchdynamo.testing import same
14 from torchdynamo.utils import identity
15 from torchdynamo.utils import init_logging
16 
17 from . import config
18 from . import overrides
19 from .decomposition import select_decomp_table
20 from .graph import GraphLowering
21 from .utils import gen_gm_and_inputs
22 from .virtualized import V
23 
24 log = logging.getLogger(__name__)
25 
26 
27 @dataclasses.dataclass
28 class BoxedBool:
29     value: bool
30 
31     def __bool__(self):
32         return self.value
33 
34     @staticmethod
35     def disable(obj):
36         if isinstance(obj, BoxedBool):
37             obj.value = False
38             return obj
39         return False
40 
41 
42 class CheckEachNode(torch.fx.Interpreter):
43     def call_function(self, target, args, kwargs):
44         expected = target(*args, **kwargs)
45         if target in (operator.getitem,):
46             return expected
47 
48         gm, gm_inps = gen_gm_and_inputs(target, args, kwargs)
49         graph = GraphLowering(gm)
50         with V.set_graph_handler(graph):
51             graph.run(*args, **kwargs)
52             actual = graph.compile_to_fn()(*gm_inps)
53 
54         if isinstance(expected, torch.Tensor):
55             actual = actual[0]
56 
57         print(target, same(expected, actual))
58         assert same(expected, actual)
59 
60         return expected
61 
62 
63 @functools.partial(wrap_debug, compiler_name="inductor")
64 def compile_fx_inner(
65     gm: torch.fx.GraphModule,
66     example_inputs: List[torch.Tensor],
67     wrap=identity,
68     cudagraphs=None,
69     num_fixed=0,
70 ):
71     init_logging()
72 
73     if cudagraphs is None:
74         cudagraphs = config.triton.cudagraphs
75 
76     graph = GraphLowering(gm, num_dynamic_inputs=len(example_inputs))
77     with V.set_graph_handler(graph):
78         wrap(graph.run)(*example_inputs)
79         compiled_fn = wrap(graph.compile_to_fn())
80 
81     if cudagraphs and set(graph.device_types) == {"cuda"} and not graph.mutated_inputs:
82         compiled_fn = cudagraphify(
83             compiled_fn, example_inputs, static_input_idxs=range(num_fixed)
84         )
85     elif cudagraphs:
86         BoxedBool.disable(cudagraphs)
87 
88         if len(set(graph.device_types)) > 1:
89             log.warning("skipping cudagraphs due to multiple devices")
90         elif graph.mutated_inputs and set(graph.device_types) == {"cuda"}:
91             log.warning("skipping cudagraphs due to input mutation")
92 
93     return compiled_fn
94 
95 
96 def cudagraphify(model, inputs, static_input_idxs=()):
97     """
98     Assumes inputs[static_input_idxs[i]] are always the same memory address
99     """
100     assert isinstance(inputs, (list, tuple))
101     static_inputs = [
102         torch.zeros_like(x) if idx not in static_input_idxs else inputs[idx]
103         for idx, x in enumerate(inputs)
104     ]
105 
106     # warmup
107     torch.cuda.synchronize()
108     stream = torch.cuda.Stream()
109     stream.wait_stream(torch.cuda.current_stream())
110     with torch.cuda.stream(stream):
111         model(*inputs)
112     stream.synchronize()
113     torch.cuda.current_stream().wait_stream(stream)
114     torch.cuda.synchronize()
115 
116     # record
117     graph = torch.cuda.CUDAGraph()
118     with torch.cuda.graph(graph, stream=stream):
119         static_outputs = model(*static_inputs)
120     if not isinstance(static_outputs, (list, tuple)):
121         static_outputs = (static_outputs,)
122 
123     if config.size_asserts:
124 
125         def run(*new_inputs):
126             assert len(static_inputs) == len(new_inputs)
127             for idx, (dst, src) in enumerate(zip(static_inputs, new_inputs)):
128                 if idx in static_input_idxs:
129                     assert dst.data_ptr() == src.data_ptr()
130                 else:
131                     dst.copy_(src)
132             graph.replay()
133             return static_outputs
134 
135     else:
136         copy_indices = [
137             idx for idx in range(len(static_inputs)) if idx not in static_input_idxs
138         ]
139 
140         def run(*new_inputs):
141             for idx in copy_indices:
142                 static_inputs[idx].copy_(new_inputs[idx])
143             graph.replay()
144             return static_outputs
145 
146     return run
147 
148 
149 def count_tangents(fx_g: torch.fx.GraphModule):
150     """
151     Infers which inputs are static for a backwards graph
152     """
153 
154     def is_not_gradout(x):
155         return "tangents" not in x.name
156 
157     arg_count = 0
158     static_arg_idxs = []
159     for n in fx_g.graph.nodes:
160         if n.op == "placeholder":
161             if is_not_gradout(n):
162                 static_arg_idxs.append(arg_count)
163             arg_count += 1
164 
165     assert static_arg_idxs == list(range(len(static_arg_idxs)))
166     return len(static_arg_idxs)
167 
168 
169 def compile_fx(model_: torch.fx.GraphModule, example_inputs_: List[torch.Tensor]):
170     """Main entrypoint to a compile given FX graph"""
171     logging.getLogger("torchinductor").setLevel(
172         logging.DEBUG if config.debug else logging.WARNING
173     )
174 
175     with overrides.patch_functions():
176         model_ = normalize_ir(model_, example_inputs_)
177         model_ = overrides.replace_fx(model_)
178     num_example_inputs = len(example_inputs_)
179     cudagraphs = BoxedBool(config.triton.cudagraphs)
180 
181     def fw_compiler(model: torch.fx.GraphModule, example_inputs):
182         if config.debug:
183             print("FORWARD GRAPH:")
184             model.graph.print_tabular()
185         fixed = len(example_inputs) - num_example_inputs
186         return compile_fx_inner(
187             model, example_inputs, num_fixed=fixed, cudagraphs=cudagraphs
188         )
189 
190     def bw_compiler(model: torch.fx.GraphModule, example_inputs):
191         if config.debug:
192             print("BACKWARD GRAPH:")
193             model.graph.print_tabular()
194         fixed = count_tangents(model)
195         return compile_fx_inner(
196             model, example_inputs, num_fixed=fixed, cudagraphs=cudagraphs
197         )
198 
199     with overrides.patch_functions():
200         return aot_autograd(
201             model_,
202             example_inputs_,
203             fw_compiler=fw_compiler,
204             bw_compiler=bw_compiler,
205             decompositions=select_decomp_table(),
206             partition_fn=functools.partial(
207                 min_cut_rematerialization_partition, compiler="inductor"
208             ),
209         )
210
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/torchinductor/compile_fx.py b/torchinductor/compile_fx.py
--- a/torchinductor/compile_fx.py
+++ b/torchinductor/compile_fx.py
@@ -18,6 +18,7 @@
 from . import overrides
 from .decomposition import select_decomp_table
 from .graph import GraphLowering
+from .utils import ceildiv
 from .utils import gen_gm_and_inputs
 from .virtualized import V
 
@@ -97,9 +98,22 @@
     """
     Assumes inputs[static_input_idxs[i]] are always the same memory address
     """
+
+    def static_input(x):
+        # make sure alignment and contiguity of inputs is preserved
+        needed_size = (
+            sum((shape - 1) * stride for shape, stride in zip(x.size(), x.stride())) + 1
+        )
+        needed_size = ceildiv(needed_size, 32) * 32
+        buffer = torch.zeros(needed_size, dtype=x.dtype, device=x.device)
+        cache_line_offset = (
+            (x.data_ptr() - buffer.data_ptr()) % 32
+        ) // x.element_size()
+        return torch.as_strided(buffer, x.size(), x.stride(), cache_line_offset)
+
     assert isinstance(inputs, (list, tuple))
     static_inputs = [
-        torch.zeros_like(x) if idx not in static_input_idxs else inputs[idx]
+        static_input(x) if idx not in static_input_idxs else inputs[idx]
         for idx, x in enumerate(inputs)
     ]

{"golden_diff": "diff --git a/torchinductor/compile_fx.py b/torchinductor/compile_fx.py\n--- a/torchinductor/compile_fx.py\n+++ b/torchinductor/compile_fx.py\n@@ -18,6 +18,7 @@\n from . import overrides\n from .decomposition import select_decomp_table\n from .graph import GraphLowering\n+from .utils import ceildiv\n from .utils import gen_gm_and_inputs\n from .virtualized import V\n \n@@ -97,9 +98,22 @@\n     \"\"\"\n     Assumes inputs[static_input_idxs[i]] are always the same memory address\n     \"\"\"\n+\n+    def static_input(x):\n+        # make sure alignment and contiguity of inputs is preserved\n+        needed_size = (\n+            sum((shape - 1) * stride for shape, stride in zip(x.size(), x.stride())) + 1\n+        )\n+        needed_size = ceildiv(needed_size, 32) * 32\n+        buffer = torch.zeros(needed_size, dtype=x.dtype, device=x.device)\n+        cache_line_offset = (\n+            (x.data_ptr() - buffer.data_ptr()) % 32\n+        ) // x.element_size()\n+        return torch.as_strided(buffer, x.size(), x.stride(), cache_line_offset)\n+\n     assert isinstance(inputs, (list, tuple))\n     static_inputs = [\n-        torch.zeros_like(x) if idx not in static_input_idxs else inputs[idx]\n+        static_input(x) if idx not in static_input_idxs else inputs[idx]\n         for idx, x in enumerate(inputs)\n     ]\n", "issue": "[HF: AllenaiLongformerBase, GoogleFnet] RuntimeError: CUDA error: an illegal memory access was encountered\nRepro:\r\n```\r\nbenchmarks/huggingface.py -d cuda --inductor --training --float32 --use-eval-mode -k   AllenaiLongformerBase\r\nbenchmarks/huggingface.py -d cuda --inductor --training --float32 --use-eval-mode -k   GoogleFnet\r\n```\r\n\r\nError:\r\n```\r\nRuntimeError: CUDA error: an illegal memory access was encountered\r\n```\r\n\r\nThe error disappears if we set `config.triton.cudagraph` to False.\n", "before_files": [{"content": "import dataclasses\nimport functools\nimport logging\nimport operator\nfrom typing import List\n\nimport torch.fx\nfrom functorch.compile import min_cut_rematerialization_partition\n\nfrom torchdynamo.debug_utils import wrap_debug\nfrom torchdynamo.optimizations.backends import aot_autograd\nfrom torchdynamo.optimizations.normalize import normalize_ir\nfrom torchdynamo.testing import same\nfrom torchdynamo.utils import identity\nfrom torchdynamo.utils import init_logging\n\nfrom . import config\nfrom . import overrides\nfrom .decomposition import select_decomp_table\nfrom .graph import GraphLowering\nfrom .utils import gen_gm_and_inputs\nfrom .virtualized import V\n\nlog = logging.getLogger(__name__)\n\n\n@dataclasses.dataclass\nclass BoxedBool:\n    value: bool\n\n    def __bool__(self):\n        return self.value\n\n    @staticmethod\n    def disable(obj):\n        if isinstance(obj, BoxedBool):\n            obj.value = False\n            return obj\n        return False\n\n\nclass CheckEachNode(torch.fx.Interpreter):\n    def call_function(self, target, args, kwargs):\n        expected = target(*args, **kwargs)\n        if target in (operator.getitem,):\n            return expected\n\n        gm, gm_inps = gen_gm_and_inputs(target, args, kwargs)\n        graph = GraphLowering(gm)\n        with V.set_graph_handler(graph):\n            graph.run(*args, **kwargs)\n            actual = graph.compile_to_fn()(*gm_inps)\n\n        if isinstance(expected, torch.Tensor):\n            actual = actual[0]\n\n        print(target, same(expected, actual))\n        assert same(expected, actual)\n\n        return expected\n\n\n@functools.partial(wrap_debug, compiler_name=\"inductor\")\ndef compile_fx_inner(\n    gm: torch.fx.GraphModule,\n    example_inputs: List[torch.Tensor],\n    wrap=identity,\n    cudagraphs=None,\n    num_fixed=0,\n):\n    init_logging()\n\n    if cudagraphs is None:\n        cudagraphs = config.triton.cudagraphs\n\n    graph = GraphLowering(gm, num_dynamic_inputs=len(example_inputs))\n    with V.set_graph_handler(graph):\n        wrap(graph.run)(*example_inputs)\n        compiled_fn = wrap(graph.compile_to_fn())\n\n    if cudagraphs and set(graph.device_types) == {\"cuda\"} and not graph.mutated_inputs:\n        compiled_fn = cudagraphify(\n            compiled_fn, example_inputs, static_input_idxs=range(num_fixed)\n        )\n    elif cudagraphs:\n        BoxedBool.disable(cudagraphs)\n\n        if len(set(graph.device_types)) > 1:\n            log.warning(\"skipping cudagraphs due to multiple devices\")\n        elif graph.mutated_inputs and set(graph.device_types) == {\"cuda\"}:\n            log.warning(\"skipping cudagraphs due to input mutation\")\n\n    return compiled_fn\n\n\ndef cudagraphify(model, inputs, static_input_idxs=()):\n    \"\"\"\n    Assumes inputs[static_input_idxs[i]] are always the same memory address\n    \"\"\"\n    assert isinstance(inputs, (list, tuple))\n    static_inputs = [\n        torch.zeros_like(x) if idx not in static_input_idxs else inputs[idx]\n        for idx, x in enumerate(inputs)\n    ]\n\n    # warmup\n    torch.cuda.synchronize()\n    stream = torch.cuda.Stream()\n    stream.wait_stream(torch.cuda.current_stream())\n    with torch.cuda.stream(stream):\n        model(*inputs)\n    stream.synchronize()\n    torch.cuda.current_stream().wait_stream(stream)\n    torch.cuda.synchronize()\n\n    # record\n    graph = torch.cuda.CUDAGraph()\n    with torch.cuda.graph(graph, stream=stream):\n        static_outputs = model(*static_inputs)\n    if not isinstance(static_outputs, (list, tuple)):\n        static_outputs = (static_outputs,)\n\n    if config.size_asserts:\n\n        def run(*new_inputs):\n            assert len(static_inputs) == len(new_inputs)\n            for idx, (dst, src) in enumerate(zip(static_inputs, new_inputs)):\n                if idx in static_input_idxs:\n                    assert dst.data_ptr() == src.data_ptr()\n                else:\n                    dst.copy_(src)\n            graph.replay()\n            return static_outputs\n\n    else:\n        copy_indices = [\n            idx for idx in range(len(static_inputs)) if idx not in static_input_idxs\n        ]\n\n        def run(*new_inputs):\n            for idx in copy_indices:\n                static_inputs[idx].copy_(new_inputs[idx])\n            graph.replay()\n            return static_outputs\n\n    return run\n\n\ndef count_tangents(fx_g: torch.fx.GraphModule):\n    \"\"\"\n    Infers which inputs are static for a backwards graph\n    \"\"\"\n\n    def is_not_gradout(x):\n        return \"tangents\" not in x.name\n\n    arg_count = 0\n    static_arg_idxs = []\n    for n in fx_g.graph.nodes:\n        if n.op == \"placeholder\":\n            if is_not_gradout(n):\n                static_arg_idxs.append(arg_count)\n            arg_count += 1\n\n    assert static_arg_idxs == list(range(len(static_arg_idxs)))\n    return len(static_arg_idxs)\n\n\ndef compile_fx(model_: torch.fx.GraphModule, example_inputs_: List[torch.Tensor]):\n    \"\"\"Main entrypoint to a compile given FX graph\"\"\"\n    logging.getLogger(\"torchinductor\").setLevel(\n        logging.DEBUG if config.debug else logging.WARNING\n    )\n\n    with overrides.patch_functions():\n        model_ = normalize_ir(model_, example_inputs_)\n        model_ = overrides.replace_fx(model_)\n    num_example_inputs = len(example_inputs_)\n    cudagraphs = BoxedBool(config.triton.cudagraphs)\n\n    def fw_compiler(model: torch.fx.GraphModule, example_inputs):\n        if config.debug:\n            print(\"FORWARD GRAPH:\")\n            model.graph.print_tabular()\n        fixed = len(example_inputs) - num_example_inputs\n        return compile_fx_inner(\n            model, example_inputs, num_fixed=fixed, cudagraphs=cudagraphs\n        )\n\n    def bw_compiler(model: torch.fx.GraphModule, example_inputs):\n        if config.debug:\n            print(\"BACKWARD GRAPH:\")\n            model.graph.print_tabular()\n        fixed = count_tangents(model)\n        return compile_fx_inner(\n            model, example_inputs, num_fixed=fixed, cudagraphs=cudagraphs\n        )\n\n    with overrides.patch_functions():\n        return aot_autograd(\n            model_,\n            example_inputs_,\n            fw_compiler=fw_compiler,\n            bw_compiler=bw_compiler,\n            decompositions=select_decomp_table(),\n            partition_fn=functools.partial(\n                min_cut_rematerialization_partition, compiler=\"inductor\"\n            ),\n        )\n", "path": "torchinductor/compile_fx.py"}], "after_files": [{"content": "import dataclasses\nimport functools\nimport logging\nimport operator\nfrom typing import List\n\nimport torch.fx\nfrom functorch.compile import min_cut_rematerialization_partition\n\nfrom torchdynamo.debug_utils import wrap_debug\nfrom torchdynamo.optimizations.backends import aot_autograd\nfrom torchdynamo.optimizations.normalize import normalize_ir\nfrom torchdynamo.testing import same\nfrom torchdynamo.utils import identity\nfrom torchdynamo.utils import init_logging\n\nfrom . import config\nfrom . import overrides\nfrom .decomposition import select_decomp_table\nfrom .graph import GraphLowering\nfrom .utils import ceildiv\nfrom .utils import gen_gm_and_inputs\nfrom .virtualized import V\n\nlog = logging.getLogger(__name__)\n\n\n@dataclasses.dataclass\nclass BoxedBool:\n    value: bool\n\n    def __bool__(self):\n        return self.value\n\n    @staticmethod\n    def disable(obj):\n        if isinstance(obj, BoxedBool):\n            obj.value = False\n            return obj\n        return False\n\n\nclass CheckEachNode(torch.fx.Interpreter):\n    def call_function(self, target, args, kwargs):\n        expected = target(*args, **kwargs)\n        if target in (operator.getitem,):\n            return expected\n\n        gm, gm_inps = gen_gm_and_inputs(target, args, kwargs)\n        graph = GraphLowering(gm)\n        with V.set_graph_handler(graph):\n            graph.run(*args, **kwargs)\n            actual = graph.compile_to_fn()(*gm_inps)\n\n        if isinstance(expected, torch.Tensor):\n            actual = actual[0]\n\n        print(target, same(expected, actual))\n        assert same(expected, actual)\n\n        return expected\n\n\n@functools.partial(wrap_debug, compiler_name=\"inductor\")\ndef compile_fx_inner(\n    gm: torch.fx.GraphModule,\n    example_inputs: List[torch.Tensor],\n    wrap=identity,\n    cudagraphs=None,\n    num_fixed=0,\n):\n    init_logging()\n\n    if cudagraphs is None:\n        cudagraphs = config.triton.cudagraphs\n\n    graph = GraphLowering(gm, num_dynamic_inputs=len(example_inputs))\n    with V.set_graph_handler(graph):\n        wrap(graph.run)(*example_inputs)\n        compiled_fn = wrap(graph.compile_to_fn())\n\n    if cudagraphs and set(graph.device_types) == {\"cuda\"} and not graph.mutated_inputs:\n        compiled_fn = cudagraphify(\n            compiled_fn, example_inputs, static_input_idxs=range(num_fixed)\n        )\n    elif cudagraphs:\n        BoxedBool.disable(cudagraphs)\n\n        if len(set(graph.device_types)) > 1:\n            log.warning(\"skipping cudagraphs due to multiple devices\")\n        elif graph.mutated_inputs and set(graph.device_types) == {\"cuda\"}:\n            log.warning(\"skipping cudagraphs due to input mutation\")\n\n    return compiled_fn\n\n\ndef cudagraphify(model, inputs, static_input_idxs=()):\n    \"\"\"\n    Assumes inputs[static_input_idxs[i]] are always the same memory address\n    \"\"\"\n\n    def static_input(x):\n        # make sure alignment and contiguity of inputs is preserved\n        needed_size = (\n            sum((shape - 1) * stride for shape, stride in zip(x.size(), x.stride())) + 1\n        )\n        needed_size = ceildiv(needed_size, 32) * 32\n        buffer = torch.zeros(needed_size, dtype=x.dtype, device=x.device)\n        cache_line_offset = (\n            (x.data_ptr() - buffer.data_ptr()) % 32\n        ) // x.element_size()\n        return torch.as_strided(buffer, x.size(), x.stride(), cache_line_offset)\n\n    assert isinstance(inputs, (list, tuple))\n    static_inputs = [\n        static_input(x) if idx not in static_input_idxs else inputs[idx]\n        for idx, x in enumerate(inputs)\n    ]\n\n    # warmup\n    torch.cuda.synchronize()\n    stream = torch.cuda.Stream()\n    stream.wait_stream(torch.cuda.current_stream())\n    with torch.cuda.stream(stream):\n        model(*inputs)\n    stream.synchronize()\n    torch.cuda.current_stream().wait_stream(stream)\n    torch.cuda.synchronize()\n\n    # record\n    graph = torch.cuda.CUDAGraph()\n    with torch.cuda.graph(graph, stream=stream):\n        static_outputs = model(*static_inputs)\n    if not isinstance(static_outputs, (list, tuple)):\n        static_outputs = (static_outputs,)\n\n    if config.size_asserts:\n\n        def run(*new_inputs):\n            assert len(static_inputs) == len(new_inputs)\n            for idx, (dst, src) in enumerate(zip(static_inputs, new_inputs)):\n                if idx in static_input_idxs:\n                    assert dst.data_ptr() == src.data_ptr()\n                else:\n                    dst.copy_(src)\n            graph.replay()\n            return static_outputs\n\n    else:\n        copy_indices = [\n            idx for idx in range(len(static_inputs)) if idx not in static_input_idxs\n        ]\n\n        def run(*new_inputs):\n            for idx in copy_indices:\n                static_inputs[idx].copy_(new_inputs[idx])\n            graph.replay()\n            return static_outputs\n\n    return run\n\n\ndef count_tangents(fx_g: torch.fx.GraphModule):\n    \"\"\"\n    Infers which inputs are static for a backwards graph\n    \"\"\"\n\n    def is_not_gradout(x):\n        return \"tangents\" not in x.name\n\n    arg_count = 0\n    static_arg_idxs = []\n    for n in fx_g.graph.nodes:\n        if n.op == \"placeholder\":\n            if is_not_gradout(n):\n                static_arg_idxs.append(arg_count)\n            arg_count += 1\n\n    assert static_arg_idxs == list(range(len(static_arg_idxs)))\n    return len(static_arg_idxs)\n\n\ndef compile_fx(model_: torch.fx.GraphModule, example_inputs_: List[torch.Tensor]):\n    \"\"\"Main entrypoint to a compile given FX graph\"\"\"\n    logging.getLogger(\"torchinductor\").setLevel(\n        logging.DEBUG if config.debug else logging.WARNING\n    )\n\n    with overrides.patch_functions():\n        model_ = normalize_ir(model_, example_inputs_)\n        model_ = overrides.replace_fx(model_)\n    num_example_inputs = len(example_inputs_)\n    cudagraphs = BoxedBool(config.triton.cudagraphs)\n\n    def fw_compiler(model: torch.fx.GraphModule, example_inputs):\n        if config.debug:\n            print(\"FORWARD GRAPH:\")\n            model.graph.print_tabular()\n        fixed = len(example_inputs) - num_example_inputs\n        return compile_fx_inner(\n            model, example_inputs, num_fixed=fixed, cudagraphs=cudagraphs\n        )\n\n    def bw_compiler(model: torch.fx.GraphModule, example_inputs):\n        if config.debug:\n            print(\"BACKWARD GRAPH:\")\n            model.graph.print_tabular()\n        fixed = count_tangents(model)\n        return compile_fx_inner(\n            model, example_inputs, num_fixed=fixed, cudagraphs=cudagraphs\n        )\n\n    with overrides.patch_functions():\n        return aot_autograd(\n            model_,\n            example_inputs_,\n            fw_compiler=fw_compiler,\n            bw_compiler=bw_compiler,\n            decompositions=select_decomp_table(),\n            partition_fn=functools.partial(\n                min_cut_rematerialization_partition, compiler=\"inductor\"\n            ),\n        )\n", "path": "torchinductor/compile_fx.py"}]}