-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add tutorial inductor on Windows CPU #3062
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
00c6211
add tutorial for inductor on windows cpu
ZhaoqiongZ 10b6d4b
update tutorial inductor_windows_cpu
ZhaoqiongZ d1a98df
update inductor windows cpu
ZhaoqiongZ 4df70a7
update inductor windows cpu
ZhaoqiongZ c8f29b6
update inductor windows cpu and fix format
ZhaoqiongZ d0c485b
remove icx guide
ZhaoqiongZ 3ea5e05
Editorial and formatting fixes
svekars 7216e5c
Apply suggestions from code review
svekars d2e1f27
Apply suggestions from code review
svekars 0bfbceb
add alternative compiler based on svekars comments
ZhaoqiongZ b6c69db
add doc to prototype_index
ZhaoqiongZ b6c5ea6
fix command format
ZhaoqiongZ 84a84f7
Update prototype_source/inductor_windows_cpu.rst
ZhaoqiongZ ae04689
Update prototype_source/inductor_windows_cpu.rst
ZhaoqiongZ c7ce4a0
Update prototype_source/inductor_windows_cpu.rst
ZhaoqiongZ 51b154a
Update prototype_source/inductor_windows_cpu.rst
ZhaoqiongZ 8a8fe38
Update prototype_source/inductor_windows_cpu.rst
ZhaoqiongZ 319c395
Merge branch 'main' into main
svekars File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
How to use TorchInductor on Windows CPU | ||
======================================= | ||
|
||
**Author**: `Zhaoqiong Zheng <https://github.com/ZhaoqiongZ>`_, `Xu, Han <https://github.com/xuhancn>`_ | ||
|
||
|
||
Introduction | ||
------------ | ||
|
||
TorchInductor is the new compiler backend that compiles the FX Graphs generated by TorchDynamo into optimized C++/Triton kernels. | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This tutorial introduces the steps for utilizing TorchInductor on Windows CPU. | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Software Installation | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--------------------- | ||
|
||
Now, we will walk you through a step-by-step tutorial for how to use torchinductor on Windows CPU. | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Install a Compiler | ||
^^^^^^^^^^^^^^^^^^ | ||
|
||
C++ compiler is required for torchinductor optimization, let's take Microsoft Visual C++ (MSVC) as an example. | ||
|
||
Download and install `MSVC <https://visualstudio.microsoft.com/downloads/>`_. | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
During Installation, chosse `Desktop Development with C++` in the `Desktop & Mobile` Section and then install. | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. note:: | ||
|
||
We recommend C++ compiler `Clang <https://github.com/llvm/llvm-project/releases>`_ and `Intel Compiler <https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit-download.html>`_. | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Install Miniforge | ||
^^^^^^^^^^^^^^^^^ | ||
|
||
Download and install `Miniforge <https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Windows-x86_64.exe>`_. | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Set Up Environment | ||
^^^^^^^^^^^^^^^^^^ | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#. Open a command line environment via cmd.exe. | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#. Activate `MSVC` via below command:: | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat" | ||
#. Activate `conda` via below command:: | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
"C:/ProgramData/miniforge3/Scripts/activate.bat" | ||
#. Create and activate customer conda environment:: | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
conda create -n inductor_cpu_windows python=3.10 -y | ||
conda activate inductor_cpu_windows | ||
#. Install `PyTorch 2.5 <https://pytorch.org/get-started/locally/>`_ or later. | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#. Use torchinductor on Windows CPU:: | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import torch | ||
def foo(x, y): | ||
a = torch.sin(x) | ||
b = torch.cos(x) | ||
Comment on lines
+75
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If function takes two arguments, should 2nd one be used somewhere? (i.e. |
||
return a + b | ||
opt_foo1 = torch.compile(foo) | ||
print(opt_foo1(torch.randn(10, 10), torch.randn(10, 10))) | ||
|
||
#. Output of the above example:: | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
tensor([[-3.9074e-02, 1.3994e+00, 1.3894e+00, 3.2630e-01, 8.3060e-01, | ||
1.1833e+00, 1.4016e+00, 7.1905e-01, 9.0637e-01, -1.3648e+00], | ||
[ 1.3728e+00, 7.2863e-01, 8.6888e-01, -6.5442e-01, 5.6790e-01, | ||
5.2025e-01, -1.2647e+00, 1.2684e+00, -1.2483e+00, -7.2845e-01], | ||
[-6.7747e-01, 1.2028e+00, 1.1431e+00, 2.7196e-02, 5.5304e-01, | ||
6.1945e-01, 4.6654e-01, -3.7376e-01, 9.3644e-01, 1.3600e+00], | ||
[-1.0157e-01, 7.7200e-02, 1.0146e+00, 8.8175e-02, -1.4057e+00, | ||
8.8119e-01, 6.2853e-01, 3.2773e-01, 8.5082e-01, 8.4615e-01], | ||
[ 1.4140e+00, 1.2130e+00, -2.0762e-01, 3.3914e-01, 4.1122e-01, | ||
8.6895e-01, 5.8852e-01, 9.3310e-01, 1.4101e+00, 9.8318e-01], | ||
[ 1.2355e+00, 7.9290e-02, 1.3707e+00, 1.3754e+00, 1.3768e+00, | ||
9.8970e-01, 1.1171e+00, -5.9944e-01, 1.2553e+00, 1.3394e+00], | ||
[-1.3428e+00, 1.8400e-01, 1.1756e+00, -3.0654e-01, 9.7973e-01, | ||
1.4019e+00, 1.1886e+00, -1.9194e-01, 1.3632e+00, 1.1811e+00], | ||
[-7.1615e-01, 4.6622e-01, 1.2089e+00, 9.2011e-01, 1.0659e+00, | ||
9.0892e-01, 1.1932e+00, 1.3888e+00, 1.3898e+00, 1.3218e+00], | ||
[ 1.4139e+00, -1.4000e-01, 9.1192e-01, 3.0175e-01, -9.6432e-01, | ||
-1.0498e+00, 1.4115e+00, -9.3212e-01, -9.0964e-01, 1.0127e+00], | ||
[ 5.7244e-04, 1.2799e+00, 1.3595e+00, 1.0907e+00, 3.7191e-01, | ||
1.4062e+00, 1.3672e+00, 6.8502e-02, 8.5216e-01, 8.6046e-01]]) | ||
|
||
Conclusion | ||
---------- | ||
|
||
With this tutorial, we introduce how to use Inductor on Windows CPU with PyTorch 2.5 or later. | ||
svekars marked this conversation as resolved.
Show resolved
Hide resolved
ZhaoqiongZ marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.