-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Add tutorial about inductor caching #2951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/tutorials/2951
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit e6b6dd2 with merge base f2b8a1b ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
ghstack-source-id: d8f2a08def6c1c4d260939e82ec1be61f5fe1578 Pull Request resolved: #2951
[ghstack-poisoned]
ghstack-source-id: 380379506af15164aeea1456ffa437ca2f5d1b33 Pull Request resolved: #2951
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick editorial pass - let me know if you have any questions.
------------------ | ||
|
||
PyTorch Inductor implements several caches to reduce compilation latency. These caches are transparent to the user. | ||
This recipes demonstrates how you to configure various parts of the caching in ``torch.compile``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This recipes demonstrates how you to configure various parts of the caching in ``torch.compile``. | |
This recipe demonstrates how you can configure various parts of the caching in ``torch.compile``. |
Inductor Cache Settings | ||
---------------------------- | ||
|
||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. | |
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. |
|
||
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. | ||
|
||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. | |
There are a few settings relevant to caching and to FX graph caching in particular. | |
The settings are accessible via environment variables listed below or can be hard-coded in the Inductor’s config file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I'd do: "the Inductor's config file" -> "Inductor's config file"
~~~~~~~~~~~~~~~~~~~~~~~~ | ||
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``. | ||
|
||
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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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). | |
Note that if ``TRITON_CACHE_DIR`` is not set in the environment, Inductor sets the Triton cache directory to this same temporary location, under the Triton subdirectory. |
|
||
TORCHINDUCTOR_CACHE_DIR | ||
~~~~~~~~~~~~~~~~~~~~~~~~ | ||
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``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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``. | |
This setting specifies the location of all on-disk caches. By default, the location is in the system temporary directory under ``torchinductor_<username>``, for example, ``/tmp/torchinductor_myusername``. |
|
||
TORCHINDUCTOR_AUTOTUNE_REMOTE_CACHE | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
This setting enables a remote cache for Inductor’s autotuner. As with the remote FX graph cache, the current implementation uses Redis. ``1`` enables, and any other value disables. The same host / port environment variables listed above apply to this cache. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This setting enables a remote cache for Inductor’s autotuner. As with the remote FX graph cache, the current implementation uses Redis. ``1`` enables, and any other value disables. The same host / port environment variables listed above apply to this cache. | |
This setting enables a remote cache for Inductor’s autotuner. As with the remote FX graph cache, the current implementation uses Redis. ``1`` enables cache, and any other value disables. The same host / port environment variables listed above apply to this cache. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I do: enables cache -> enables caching
|
||
TORCHINDUCTOR_FORCE_DISABLE_CACHES | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. | |
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.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also add a Conclusion section, something like:
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. Additionally, we explored the various settings and
environment variables that allow users to configure and optimize these caching features according
to their specific needs.
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 ColinPeppler amjames desertfire chauhang [ghstack-poisoned]
ghstack-source-id: 2c70215fd150e2a16abc55fe1ff8b1e7639e50c9 Pull Request resolved: #2951
ghstack-source-id: 2c70215fd150e2a16abc55fe1ff8b1e7639e50c9 Pull Request resolved: #2951
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. | ||
|
||
There are a few settings relevant to caching and to FX graph caching in particular. | ||
The settings are accessible via environment variables listed below or can be hard-coded in the Inductor’s config file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inductor's config file
Apparently I should not be using ghstack so closing this and creating a new PR: #2952 |
|
||
TORCHINDUCTOR_FX_GRAPH_REMOTE_CACHE | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enables caching
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disables it
ghstack-source-id: 2c70215fd150e2a16abc55fe1ff8b1e7639e50c9 Pull Request resolved: #2951
ghstack-source-id: 2c70215fd150e2a16abc55fe1ff8b1e7639e50c9 Pull Request resolved: #2951
Stack from ghstack (oldest at bottom):
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @ColinPeppler @amjames @desertfire @chauhang