You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: recipes_source/torch_compile_caching_tutorial.rst
+13-7Lines changed: 13 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ Introduction
6
6
------------------
7
7
8
8
PyTorch Inductor implements several caches to reduce compilation latency. These caches are transparent to the user.
9
-
This recipes demonstrates how you to configure various parts of the caching in ``torch.compile``.
9
+
This recipe demonstrates how you can configure various parts of the caching in ``torch.compile``.
10
10
11
11
Prerequisites
12
12
-------------------
@@ -23,23 +23,24 @@ Before starting this recipe, make sure that you have the following:
23
23
Inductor Cache Settings
24
24
----------------------------
25
25
26
-
Most of these caches are in-memory, only used within the same process, and are transparent to the user. An exception is the FX graph cache that stores compiled FX graphs. This cache allows Inductor to avoid recompilation across process boundaries when it encounters the same graph with the same Tensor input shapes (and the same configuration, etc.). The default implementation stores compiled artifacts in the system temp directory. An optional feature also supports sharing those artifacts within a cluster by storing them in Redis.
26
+
Most of these caches are in-memory, only used within the same process, and are transparent to the user. An exception is the FX graph cache that stores compiled FX graphs. This cache allows Inductor to avoid recompilation across process boundaries when it encounters the same graph with the same Tensor input shapes (and the same configuration). The default implementation stores compiled artifacts in the system temp directory. An optional feature also supports sharing those artifacts within a cluster by storing them in a Redis database.
27
27
28
-
There are a few settings relevant to caching and to FX graph caching in particular. The settings are accessible via environment variables, or can be hard-coded in Inductor’s config file.
28
+
There are a few settings relevant to caching and to FX graph caching in particular.
29
+
The settings are accessible via environment variables listed below or can be hard-coded in the Inductor’s config file.
29
30
30
31
TORCHINDUCTOR_FX_GRAPH_CACHE
31
32
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32
33
This setting enables the local FX graph cache feature, i.e., by storing artifacts on the host’s temp directory. ``1`` enables, and any other value disables. By default, the disk location is per username, but users can enable sharing across usernames by specifying ``TORCHINDUCTOR_CACHE_DIR`` (below).
33
34
34
35
TORCHINDUCTOR_CACHE_DIR
35
36
~~~~~~~~~~~~~~~~~~~~~~~~
36
-
This setting specifies the location of all on-disk caches. By default, the location is in the system temp directory under ``torchinductor_<username>``, e.g., ``/tmp/torchinductor_myusername``.
37
+
This setting specifies the location of all on-disk caches. By default, the location is in the system temp directory under ``torchinductor_<username>``, for example, ``/tmp/torchinductor_myusername``.
37
38
38
-
Note that if ``TRITON_CACHE_DIR`` is not set in the environment, Inductor sets the Triton cache directory to this same temp location (under the Triton subdirectory).
39
+
Note that if ``TRITON_CACHE_DIR`` is not set in the environment, Inductor sets the Triton cache directory to this same temp location, under the Triton subdirectory.
39
40
40
41
TORCHINDUCTOR_FX_GRAPH_REMOTE_CACHE
41
42
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42
-
This setting enables the remote FX graph cache feature. The current implementation uses Redis. ``1`` enables, and any other value disables. The following environment variables configure the host and port of the Redis server:
43
+
This setting enables the remote FX graph cache feature. The current implementation uses Redis. ``1`` enables cache, and any other value disables. The following environment variables configure the host and port of the Redis server:
43
44
44
45
``TORCHINDUCTOR_REDIS_HOST`` (defaults to ``localhost``)
45
46
``TORCHINDUCTOR_REDIS_PORT`` (defaults to ``6379``)
@@ -52,4 +53,9 @@ This setting enables a remote cache for Inductor’s autotuner. As with the remo
52
53
53
54
TORCHINDUCTOR_FORCE_DISABLE_CACHES
54
55
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55
-
Set this value to ``1`` to disable all Inductor caching. This setting is useful to, e.g., experiment with cold-start compile time, or to force recompilation for debugging purposes.
56
+
Set this value to ``1`` to disable all Inductor caching. This setting is useful for tasks like experimenting with cold-start compile times or forcing recompilation for debugging purposes.
57
+
58
+
Conclusion
59
+
-------------
60
+
In this recipe, we have learned that PyTorch Inductor's caching mechanisms significantly reduce compilation latency by utilizing both local and remote caches, which operate seamlessly in the background without requiring user intervention.
61
+
Additionally, we explored the various settings and environment variables that allow users to configure and optimize these caching features according to their specific needs.
0 commit comments