Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AOTI] Using AOTI_TORCH_CHECK will cause performance drop on several models compared with using TORCH_CHECK #126665

Open
chunyuan-w opened this issue May 20, 2024 · 3 comments
Assignees
Labels
module: aotinductor aot inductor oncall: pt2 triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@chunyuan-w
Copy link
Collaborator

chunyuan-w commented May 20, 2024

馃悰 Describe the bug

#119220 replaced TORCH_CHECK with AOTI_TORCH_CHECK. We found that this change caused performance drop on several models when we were working on #124350.

The support of freezing #124350 is not landed yet so the below reproducer doesn't turn on the freezing flag.

Steps to reproduce:

# cd path_to_pytorch

# install transformers
pip install transformers==4.38.1

# install intel-openmp and jemalloc for performance benchmark
pip install intel-openmp
conda install -c conda-forge jemalloc

export LD_PRELOAD=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}/lib/libiomp5.so:${CONDA_PREFIX:-"$(dirname $(which conda))/../"}/lib/libjemalloc.so
export MALLOC_CONF="oversize_threshold:1,background_thread:true,metadata_thp:auto,dirty_decay_ms:-1,muzzy_decay_ms:-1"
export KMP_AFFINITY=granularity=fine,compact,1,0
export KMP_BLOCKTIME=1

CORES=$(lscpu | grep Core | awk '{print $4}')
export OMP_NUM_THREADS=$CORES
end_core=$(expr $CORES - 1)

# GCC 11 is used during runtime
model_name=T5Small # change to other model names here to benchmark them
numactl -C 0-${end_core} --membind=0 python benchmarks/dynamo/huggingface.py --performance --amp -dcpu -n50 --no-skip --dashboard --only $model_name --inference --timeout 9000 --export-aot-inductor --output=inductor_single_test_mt.csv && \
cat inductor_single_test_mt.csv && rm inductor_single_test_mt.csv

To get the performance using TORCH_CHECK in AOTI, you need to manually change this line to return "TORCH_CHECK".

Model AOTI abs_latency using TORCH_CHECK AOTI abs_latency using AOTI_TORCH_CHECK speedup TORCH_CHECK over AOTI_TORCH_CHECK
T5Small 136.277395 147.259659 8.0%
T5ForConditionalGeneration 135.935610 147.132520 8.2%

Update (2024-5-31): hf_T5_base and hf_T5_large in the torchbench suite also meet this issue.

Versions

PyTorch version: 2.4.0a0+git314ba13
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: CentOS Stream 8 (x86_64)
GCC version: (GCC) 8.5.0 20210514 (Red Hat 8.5.0-3)
Clang version: Could not collect
CMake version: version 3.26.4
Libc version: glibc-2.28

Python version: 3.9.18 (main, Sep 11 2023, 13:41:44) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.16.0-x86_64-with-glibc2.28
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 240
On-line CPU(s) list: 0-239
Thread(s) per core: 2
Core(s) per socket: 60
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 143
Model name: Intel(R) Xeon(R) Platinum 8490H
Stepping: 8
CPU MHz: 1900.000
CPU max MHz: 3500.0000
CPU min MHz: 800.0000
BogoMIPS: 3800.00
Virtualization: VT-x
L1d cache: 48K
L1i cache: 32K
L2 cache: 2048K
L3 cache: 115200K
NUMA node0 CPU(s): 0-59,120-179
NUMA node1 CPU(s): 60-119,180-239
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cat_l2 cdp_l3 invpcid_single intel_ppin cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr avx512_fp16 amx_tile flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] flake8==6.1.0
[pip3] flake8-bugbear==23.3.23
[pip3] flake8-comprehensions==3.12.0
[pip3] flake8-executable==2.1.3
[pip3] flake8-logging-format==0.9.0
[pip3] flake8-pyi==23.3.1
[pip3] flake8-simplify==0.19.3
[pip3] mypy==1.9.0
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.26.0
[pip3] optree==0.11.0
[pip3] torch==2.4.0a0+git314ba13
[pip3] torchvision==0.19.0a0+5181a85
[pip3] vit-pytorch==0.40.2
[conda] blas 1.0 mkl
[conda] mkl 2023.1.0 h213fc3f_46343
[conda] mkl-include 2023.2.0 pypi_0 pypi
[conda] mkl-service 2.4.0 py39h5eee18b_1
[conda] mkl-static 2023.2.0 pypi_0 pypi
[conda] mkl_fft 1.3.8 py39h5eee18b_0
[conda] mkl_random 1.2.4 py39hdb19cb5_0
[conda] numpy 1.26.0 pypi_0 pypi
[conda] numpy-base 1.26.4 py39hb5e798b_0
[conda] optree 0.11.0 pypi_0 pypi
[conda] torch 2.4.0a0+git314ba13 dev_0
[conda] torchfix 0.4.0 pypi_0 pypi
[conda] torchvision 0.19.0a0+5181a85 dev_0
[conda] vit-pytorch 0.40.2 dev_0

cc @ezyang @msaroufim @bdhirsh @anijain2305 @chauhang @desertfire @chenyang78

@xmfan xmfan added module: aotinductor aot inductor triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels May 20, 2024
@ezyang
Copy link
Contributor

ezyang commented May 21, 2024

Something that might help is to move the boolean condition back inline

@desertfire
Copy link
Contributor

cc @chenyang78

@chenyang78
Copy link
Contributor

Will take a look. Thanks.

@chenyang78 chenyang78 self-assigned this May 21, 2024
chenyang78 added a commit that referenced this issue Jun 11, 2024
We introduced AOTI_TORCH_CHECK in #119220 to resolve slow-compilation
time issues. Unfortunately, it caused perf regressions for CPU
, as described in issue #126665. After some investigation, it turned
out the slow compilation was caused by the use of the builtin
function __builtin_expect provided by gcc/clang. Moreover,
nuking __builtin_expect doesn't seem to cause any performance penalty,
even though its purpose is to improve performance by providing the
compiler with branch prediction information.

abs latency numbers using the script shared by #126665:

                            before the fix      after the fix
T5Small                     1019.055694         917.875027
T5ForConditionalGeneration  1009.825196         916.369239

[ghstack-poisoned]
chenyang78 added a commit that referenced this issue Jun 11, 2024
We introduced AOTI_TORCH_CHECK in #119220 to resolve slow-compilation
time issues. Unfortunately, it caused perf regressions for CPU
, as described in issue #126665. After some investigation, it turned
out the slow compilation was caused by the use of the builtin
function __builtin_expect provided by gcc/clang. Moreover,
nuking __builtin_expect doesn't seem to cause any performance penalty,
even though its purpose is to improve performance by providing the
compiler with branch prediction information.

abs latency numbers using the script shared by #126665:

                            before the fix      after the fix
T5Small                     1019.055694         917.875027
T5ForConditionalGeneration  1009.825196         916.369239

ghstack-source-id: 24977184a55ed6986561fcaf63fd11adbd44fb34
Pull Request resolved: #128402
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: aotinductor aot inductor oncall: pt2 triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

6 participants