-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Description
🐛 Describe the bug
The performance is much worse when batch size = 1 compared to batch size > 1
Profile when batch size = 1 (500ms)
Profile when batch size = 4 (60ms)
Command:
export OMP_NUM_THREADS=56
export TORCHINDUCTOR_FREEZING=1
numactl -C 0-55 --membind 0 python xxx
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
from torch._inductor import config
import os
os.environ["TOKENIZERS_PARALLELISM"] = "false" # To prevent long warnings :)
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-chat-hf")
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-chat-hf", torch_dtype=torch.bfloat16)
model.generation_config.cache_implementation = "static"
torch._inductor.config.cpp_wrapper = True
torch._inductor.config.profiler_mark_wrapper_call = True
torch._inductor.config.cpp.enable_kernel_profile = True
model.forward = torch.compile(model.forward, mode="reduce-overhead", fullgraph=True)
batch_size = 1
input_text = ["The theory of special relativity states "] * batch_size
print(input_text)
print(f"batch size is {len(input_text)}")
tokenizer.pad_token = tokenizer.eos_token
input_ids = tokenizer(input_text, return_tensors="pt", padding=True)
input_shape = input_ids["input_ids"].shape
print(F"input ids shape is {input_shape}")
generation_kwargs = {"do_sample": False, "num_beams": 1, "max_new_tokens": 32, "min_new_tokens": 32}
outputs = model.generate(**input_ids, **generation_kwargs)
outputs = model.generate(**input_ids, **generation_kwargs)
outputs = model.generate(**input_ids, **generation_kwargs)
outputs = model.generate(**input_ids, **generation_kwargs)
outputs = model.generate(**input_ids, **generation_kwargs)
outputs = model.generate(**input_ids, **generation_kwargs)
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
Versions
Collecting environment information... PyTorch version: 2.5.0.dev20240722+cpu Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A
OS: Rocky Linux release 8.10 (Green Obsidian) (x86_64)
GCC version: (GCC) 12.2.0
Clang version: Could not collect
CMake version: version 3.27.9
Libc version: glibc-2.28
Python version: 3.8.19 | packaged by conda-forge | (default, Mar 20 2024, 12:47:35) [GCC 12.3.0] (64-bit runtime)
Python platform: Linux-4.18.0-553.5.1.el8_10.x86_64-x86_64-with-glibc2.10
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): 224
On-line CPU(s) list: 0-223
Thread(s) per core: 2
Core(s) per socket: 56
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 143
Model name: Intel(R) Xeon(R) Platinum 8480L
Stepping: 7
CPU MHz: 2000.000
CPU max MHz: 3800.0000
CPU min MHz: 800.0000
BogoMIPS: 4000.00
L1d cache: 48K
L1i cache: 32K
L2 cache: 2048K
L3 cache: 107520K
NUMA node0 CPU(s): 0-55,112-167
NUMA node1 CPU(s): 56-111,168-223
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 re
p_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes x
save 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 fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cq
m 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 a
vx_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 amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities
Versions of relevant libraries:
[pip3] numpy==1.24.4
[pip3] torch==2.5.0.dev20240722+cpu
[conda] mkl 2024.2.0 ha957f24_665 conda-forge
[conda] mkl-include 2024.2.0 ha957f24_665 conda-forge
[conda] numpy 1.24.4 pypi_0 pypi
[conda] torch 2.5.0.dev20240722+cpu pypi_0 pypi