Skip to content

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

Closed
wants to merge 3 commits into from
Closed

Conversation

Copy link

pytorch-bot bot commented Jun 20, 2024

🔗 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 SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit e6b6dd2 with merge base f2b8a1b (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

oulgen added a commit that referenced this pull request Jun 20, 2024
ghstack-source-id: d8f2a08def6c1c4d260939e82ec1be61f5fe1578
Pull Request resolved: #2951
@oulgen oulgen requested a review from masnesral June 20, 2024 20:24
oulgen added a commit that referenced this pull request Jun 20, 2024
ghstack-source-id: 380379506af15164aeea1456ffa437ca2f5d1b33
Pull Request resolved: #2951
Copy link
Contributor

@svekars svekars left a 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``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

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).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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..

Copy link
Contributor

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]
oulgen added a commit that referenced this pull request Jun 20, 2024
ghstack-source-id: 2c70215fd150e2a16abc55fe1ff8b1e7639e50c9
Pull Request resolved: #2951
oulgen added a commit that referenced this pull request Jun 20, 2024
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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inductor's config file

@oulgen
Copy link
Contributor Author

oulgen commented Jun 20, 2024

Apparently I should not be using ghstack so closing this and creating a new PR: #2952

@oulgen oulgen closed this Jun 20, 2024

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:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enables caching

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disables it

oulgen added a commit that referenced this pull request Jun 20, 2024
ghstack-source-id: 2c70215fd150e2a16abc55fe1ff8b1e7639e50c9
Pull Request resolved: #2951
oulgen added a commit that referenced this pull request Jun 20, 2024
ghstack-source-id: 2c70215fd150e2a16abc55fe1ff8b1e7639e50c9
Pull Request resolved: #2951
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants