Skip to content

Commit 03f0df4

Browse files
authored
Merge branch 'main' into 2.4-RC-TEST
2 parents 48447d9 + cbde504 commit 03f0df4

File tree

3 files changed

+442
-0
lines changed

3 files changed

+442
-0
lines changed

recipes_source/recipes_index.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ Recipes are bite-sized, actionable examples of how to use specific PyTorch featu
274274
:link: ../recipes/recipes/tuning_guide.html
275275
:tags: Model-Optimization
276276

277+
.. customcarditem::
278+
:header: CPU launcher script for optimal performance on Intel® Xeon
279+
:card_description: How to use launcher script for optimal runtime configurations on Intel® Xeon CPUs.
280+
:image: ../_static/img/thumbnails/cropped/profiler.png
281+
:link: ../recipes/recipes/xeon_run_cpu.html
282+
:tags: Model-Optimization
283+
277284
.. customcarditem::
278285
:header: PyTorch Inference Performance Tuning on AWS Graviton Processors
279286
:card_description: Tips for achieving the best inference performance on AWS Graviton CPUs
@@ -317,6 +324,15 @@ Recipes are bite-sized, actionable examples of how to use specific PyTorch featu
317324
:link: ../recipes/torch_compile_user_defined_triton_kernel_tutorial.html
318325
:tags: Model-Optimization
319326

327+
.. Compile Time Caching in ``torch.compile``
328+
329+
.. customcarditem::
330+
:header: Compile Time Caching in ``torch.compile``
331+
:card_description: Learn how to configure compile time caching in ``torch.compile``
332+
:image: ../_static/img/thumbnails/cropped/generic-pytorch-logo.png
333+
:link: ../recipes/torch_compile_caching_tutorial.html
334+
:tags: Model-Optimization
335+
320336
.. Intel(R) Extension for PyTorch*
321337
322338
.. customcarditem::
@@ -415,6 +431,7 @@ Recipes are bite-sized, actionable examples of how to use specific PyTorch featu
415431
/recipes/recipes/dynamic_quantization
416432
/recipes/recipes/amp_recipe
417433
/recipes/recipes/tuning_guide
434+
/recipes/recipes/xeon_run_cpu
418435
/recipes/recipes/intel_extension_for_pytorch
419436
/recipes/compiling_optimizer
420437
/recipes/torch_compile_backend_ipex
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Compile Time Caching in ``torch.compile``
2+
=========================================================
3+
**Authors:** `Oguz Ulgen <https://github.com/oulgen>`_ and `Sam Larsen <https://github.com/masnesral>`_
4+
5+
Introduction
6+
------------------
7+
8+
PyTorch Inductor implements several caches to reduce compilation latency.
9+
This recipe demonstrates how you can configure various parts of the caching in ``torch.compile``.
10+
11+
Prerequisites
12+
-------------------
13+
14+
Before starting this recipe, make sure that you have the following:
15+
16+
* Basic understanding of ``torch.compile``. See:
17+
18+
* `torch.compiler API documentation <https://pytorch.org/docs/stable/torch.compiler.html#torch-compiler>`__
19+
* `Introduction to torch.compile <https://pytorch.org/tutorials/intermediate/torch_compile_tutorial.html>`__
20+
21+
* PyTorch 2.4 or later
22+
23+
Inductor Cache Settings
24+
----------------------------
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). 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+
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 Inductor’s config file.
30+
31+
TORCHINDUCTOR_FX_GRAPH_CACHE
32+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33+
This setting enables the local FX graph cache feature, i.e., by storing artifacts in the host’s temp directory. ``1`` enables, and any other value disables it. By default, the disk location is per username, but users can enable sharing across usernames by specifying ``TORCHINDUCTOR_CACHE_DIR`` (below).
34+
35+
TORCHINDUCTOR_CACHE_DIR
36+
~~~~~~~~~~~~~~~~~~~~~~~~
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``.
38+
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.
40+
41+
TORCHINDUCTOR_FX_GRAPH_REMOTE_CACHE
42+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43+
This setting enables the remote FX graph cache feature. The current implementation uses Redis. ``1`` enables caching, and any other value disables it. The following environment variables configure the host and port of the Redis server:
44+
45+
``TORCHINDUCTOR_REDIS_HOST`` (defaults to ``localhost``)
46+
``TORCHINDUCTOR_REDIS_PORT`` (defaults to ``6379``)
47+
48+
Note that if Inductor locates a remote cache entry, it stores the compiled artifact in the local on-disk cache; that local artifact would be served on subsequent runs on the same machine.
49+
50+
TORCHINDUCTOR_AUTOTUNE_REMOTE_CACHE
51+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52+
This setting enables a remote cache for Inductor’s autotuner. As with the remote FX graph cache, the current implementation uses Redis. ``1`` enables caching, and any other value disables it. The same host / port environment variables listed above apply to this cache.
53+
54+
TORCHINDUCTOR_FORCE_DISABLE_CACHES
55+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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

Comments
 (0)