Skip to content

Commit b9af21b

Browse files
committed
Create 2024-05-21-perfboost-windows-cpu.md
1 parent 1761114 commit b9af21b

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
layout: blog_detail
3+
title: "The Path to Achieve Pytorch Windows Performance boost on CPU"
4+
author: Zhaoqiong Zheng, Xu Han, Haozhe Zhu, Wenzhuo Zhang
5+
---
6+
7+
The challenge of PyTorch's lower CPU performance on Windows compared to Linux has been a significant issue. There are multiple factors leading to this performance disparity. Through meticulous investigation by Intel engineer [Xu Han](https://github.com/xuhancn), we've identified one of the primary reasons for poor CPU performance on Windows, which is linked to the Windows malloc mechanism.
8+
9+
In version 2.0, PyTorch on Windows with CPU directly utilizes the default malloc mechanism of Windows, which, compared to the malloc used in PyTorch Linux version 2.0, significantly increases the time for memory allocation, resulting in decreased performance. Intel engineer Xu Han took the initiative to replace the original Windows malloc mechanism, which PyTorch automatically calls, with another well-known malloc library developed by Microsoft, known as mimalloc. This replacement of malloc has already been released with Pytorch v2.1 and can significantly improve PyTorch's performance on Windows CPUs (See the following graph).
10+
11+
![Windows PC Performance Improvement](../assets/images/2024-05-21-perfboost-windows-cpu/windows_optimization/windows_compare.png)
12+
Image 1: Relative throughput improvement achieved by upgrading from Windows PyTorch version 2.0 to 2.1 (higher is better). The performance is measured on Intel Core 13th Gen i7-13700H with 32G Memory.
13+
14+
15+
From this graph, it's evident that PyTorch on Windows CPU showcases significant performance improvements. The variations in performance enhancements across different workloads mainly stem from varying proportions of different operations within distinct models, consequently affecting the frequency of memory access operations. It shows a comparatively smaller enhancement in BERT model performance, while there is a more substantial improvement in ResNet50 and MobileNetv3 Large model performances.
16+
17+
On a high-performance CPU, memory allocation becomes a performance bottleneck. This is also why addressing this issue has led to such significant performance improvements.
18+
19+
![Windows vs Linux Performance on Pytorch 2.0](../assets/images/2024-05-21-perfboost-windows-cpu/pytorch_20_win_linux.png)
20+
Image 2.1: Relative performance of Windows vs Linux with Pytorch version 2.0 (higher is better). The performance is measured on Intel Core 13th Gen i7-13700H with 32G Memory.
21+
22+
![Windows vs Linux Performance on Pytorch 2.1](../assets/images/2024-05-21-perfboost-windows-cpu/pytorch_21_win_linux.png)
23+
Image 2.2: Relative performance of Windows vs Linux with Pytorch version 2.1 (higher is better). The performance is measured on Intel Core 13th Gen i7-13700H with 32G Memory.
24+
25+
As shown in the graphs, it is evident that PyTorch's performance on Windows CPUs can significantly improved. However, there is still a noticeable gap when compared to its performance on Linux. This can be attributed to several factors, including the fact that malloc has not yet fully reached the performance level of Linux, among other reasons. Intel engineers will continue to delve into this issue, collaborating with Meta engineers, to reduce the performance gap of PyTorch between Windows and Linux.
26+
27+
28+
## HOW TO TAKE ADVANTAGE OF THE OPTIMIZATIONS
29+
30+
Install PyTorch version 2.1 or higher using the Windows CPU wheel from the official repository, and you will automatically experience a performance boost.
31+
32+
33+
## CONCLUSION
34+
35+
Comparing PyTorch 2.0 and PyTorch 2.1, we can observe varying degrees of performance improvement on Windows CPU. The extent of performance improvement becomes more pronounced as the number of memory allocation operations called within an op in a workload increases. A more powerful CPU computing capability will also make this performance enhancement more pronounced, as the proportion of operations outside of computation increases.
36+
37+
This performance enhancement to a certain extent helps to bridge the Pytorch CPU performance gap between Windows and Linux. Intel will continue to collaborate with Meta, dedicated to enhancing the performance of PyTorch on CPUs!
38+
39+
## ACKNOWLEDGMENTS
40+
41+
The results presented in this blog post was achieved through the collaborative effort of the Intel PyTorch team and Meta. We would like to express our sincere gratitude to [Xu Han](https://github.com/xuhancn), [Jiong Gong](https://github.com/jgong5), [Mingfei Ma](https://github.com/mingfeima), [Haozhe Zhu](https://github.com/zhuhaozhe), [Chuanqi Wang](https://github.com/chuanqi129), [Guobing Chen](https://github.com/Guobing-Chen), [Eikan Wang](https://github.com/EikanWang). Their expertise and dedication have been instrumental in achieving the optimizations and performance improvements discussed here. Thanks to [Jiachen Pu](https://github.com/peterjc123) for his participation in the issue discussion and suggesting the use of [mimalloc](https://github.com/microsoft/mimalloc), and we'd also like to express our gratitude to Microsoft for providing such easily integratable and performant mallocation library. Finally we want to thank [Jing Xu](https://github.com/jingxu10), [Weizhuo Zhang](https://github.com/WeizhuoZhang-intel) for their contributions to this blog.
42+
43+
44+
## Notices and Disclaimers
45+
46+
Performance varies by use, configuration and other factors. Learn more on the [Performance Index site](https://edc.intel.com/content/www/us/en/products/performance/benchmarks/overview/).
47+
48+
Performance results are based on testing as of dates shown in configurations and may not reflect all publicly available updates. See backup for configuration details. No product or component can be absolutely secure.
49+
50+
Your costs and results may vary.
51+
52+
### Configurations
53+
54+
The configurations in the table are collected with [svr-info](https://github.com/intel/svr-info)
55+
56+
57+
| Specification | Configuration1 | Configuration2 |
58+
|-----------------------------|----------------------------------------|----------------------------------------|
59+
| Name | ThinkBook 14 G5+ IRH | ThinkBook 14 G5+ IRH |
60+
| Time | Mon Apr 15 01:13:48 PM UTC 2024 | Mon Apr 15 01:13:48 PM UTC 2024 |
61+
| System | LENOVO | LENOVO |
62+
| Baseboard | LENOVO | LENOVO |
63+
| Chassis | LENOVO | LENOVO |
64+
| CPU Model | 13th Gen Intel(R) Core(TM) i7-13700H | 13th Gen Intel(R) Core(TM) i7-13700H |
65+
| Microarchitecture | Unknown Intel | Unknown Intel |
66+
| Sockets | 1 | 1 |
67+
| Cores per Socket | 14 | 14 |
68+
| Hyperthreading | Enabled | Enabled |
69+
| CPUs | 20 | 20 |
70+
| Intel Turbo Boost | Enabled | Enabled |
71+
| Base Frequency | 2.4GHz | 2.4GHz |
72+
| All-core Maximum Frequency | 4.7GHz | 4.7GHz |
73+
| Maximum Frequency | 4.8GHz | 4.8GHz |
74+
| NUMA Nodes | 1 | 1 |
75+
| Prefetchers | L2 HW: Enabled, L2 Adj.: Enabled, DCU HW: Enabled, DCU IP: Enabled | L2 HW: Enabled, L2 Adj.: Enabled, DCU HW: Enabled, DCU IP: Enabled |
76+
| PPINs | - | - |
77+
| Accelerators | DLB, DSA, IAA, QAT | DLB, DSA, IAA, QAT |
78+
| Installed Memory | 32GB (8x4GB LPDDR4 7400 MT/s [5200 MT/s]) | 32GB (8x4GB LPDDR4 7400 MT/s [5200 MT/s]) |
79+
| Hugepagesize | 2048kb | 2048kb |
80+
| Transparent Huge Pages | madvise | madvise |
81+
| Automatic NUMA Balancing | Disabled | Disabled |
82+
| NIC | "1. Raptor Lake PCH CNVi WiFi 2. Intel Corporation" | "1. Raptor Lake PCH CNVi WiFi 2. Intel Corporation" |
83+
| Disk | Micron MTFDKBA512TFH 500G | Micron MTFDKBA512TFH 500G |
84+
| BIOS | LBCN19WW | LBCN19WW |
85+
| Microcode | 0x411c | 0x411c |
86+
| OS | Windows 11 Desktop | Ubuntu 23.10 |
87+
| Kernel | 6.5.0-27-generic | 6.5.0-27-generic |
88+
| TDP | 200 watts | 200 watts |
89+
| Power & Perf Policy | Normal Powersave (7) | Normal Powersave (7) |
90+
| Frequency Governor | powersave | powersave |
91+
| Frequency Driver | intel_pstate | intel_pstate |
92+
| Max C-State | 9 | 9 |

0 commit comments

Comments
 (0)