vllm
vllm copied to clipboard
[Performance]: FLASHINFER backend is slower than FLASH_ATTN on H100
Proposal to improve performance
No response
Report of performance regression
No response
Misc discussion on performance
TLDR: We are observing that FP8 throughput is significantly lower when using FLASHINFER backend vs. using the default backend (FLASH_ATTN) for llama3.1-8b on a single H100 using v0.6.4.dev22+g5b8a1fde.
Here is a simple repo script:
import vllm
import transformers
import time
import numpy as np
model = "neuralmagic/Meta-Llama-3.1-8B-Instruct-FP8"
input_size = 1024
output_size = 1024
batch_size = 64
llm = vllm.LLM(
model=model,
max_model_len=input_size+output_size,
use_v2_block_manager=True,
num_scheduler_steps=8,
)
# create random batch
np.random.seed(42)
tokenizer = transformers.AutoTokenizer.from_pretrained(model)
tokens = [ [] for _ in range(batch_size) ]
for b in range(batch_size):
for i in range(input_size):
tokens[b].append(np.random.randint(tokenizer.vocab_size))
sampling_params = vllm.SamplingParams(
max_tokens=output_size,
ignore_eos=True,
)
t0 = time.time()
llm.generate(
prompt_token_ids=tokens,
sampling_params=sampling_params,
use_tqdm=False
)
t_elap = time.time()-t0
tput = batch_size * output_size / t_elap
print("t_elap: %.2f seconds" % (t_elap))
print("throughput: %.2f tokens/second" % (tput))
Running using FLASH_ATTN backend:
t_elap: 10.92 seconds
throughput: 6003.16 tokens/second
whereas running using FLASHINFER backend:
t_elap: 13.06 seconds
throughput: 5019.79 tokens/second
From reading the FlashInfer blog, I don't think these results are expected. It is a shame because we would really like to use FlashInfer to pick up the FP8 KV cache feature.
Your current environment (if you think it is necessary)
Collecting environment information...
PyTorch version: 2.4.0+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A
OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.30.3
Libc version: glibc-2.35
Python version: 3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:36:13) [GCC 12.3.0] (64-bit runtime)
Python platform: Linux-5.15.0-101-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration:
GPU 0: NVIDIA H100 80GB HBM3
GPU 1: NVIDIA H100 80GB HBM3
GPU 2: NVIDIA H100 80GB HBM3
GPU 3: NVIDIA H100 80GB HBM3
GPU 4: NVIDIA H100 80GB HBM3
GPU 5: NVIDIA H100 80GB HBM3
GPU 6: NVIDIA H100 80GB HBM3
GPU 7: NVIDIA H100 80GB HBM3
Nvidia driver version: 550.54.15
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.9.7
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
Address sizes: 52 bits physical, 57 bits virtual
Byte Order: Little Endian
CPU(s): 192
On-line CPU(s) list: 0-191
Vendor ID: GenuineIntel
Model name: Intel(R) Xeon(R) Platinum 8474C
CPU family: 6
Model: 143
Thread(s) per core: 2
Core(s) per socket: 48
Socket(s): 2
Stepping: 8
CPU max MHz: 3800.0000
CPU min MHz: 800.0000
BogoMIPS: 4200.00
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 amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities
Virtualization: VT-x
L1d cache: 4.5 MiB (96 instances)
L1i cache: 3 MiB (96 instances)
L2 cache: 192 MiB (96 instances)
L3 cache: 195 MiB (2 instances)
NUMA node(s): 2
NUMA node0 CPU(s): 0-47,96-143
NUMA node1 CPU(s): 48-95,144-191
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
Versions of relevant libraries:
[pip3] flashinfer==0.1.6+cu124torch2.4
[pip3] numpy==1.26.4
[pip3] nvidia-cublas-cu12==12.1.3.1
[pip3] nvidia-cuda-cupti-cu12==12.1.105
[pip3] nvidia-cuda-nvrtc-cu12==12.1.105
[pip3] nvidia-cuda-runtime-cu12==12.1.105
[pip3] nvidia-cudnn-cu12==9.1.0.70
[pip3] nvidia-cufft-cu12==11.0.2.54
[pip3] nvidia-curand-cu12==10.3.2.106
[pip3] nvidia-cusolver-cu12==11.4.5.107
[pip3] nvidia-cusparse-cu12==12.1.0.106
[pip3] nvidia-ml-py==12.560.30
[pip3] nvidia-nccl-cu12==2.20.5
[pip3] nvidia-nvjitlink-cu12==12.6.68
[pip3] nvidia-nvtx-cu12==12.1.105
[pip3] pyzmq==26.2.0
[pip3] torch==2.4.0
[pip3] torchvision==0.19.0
[pip3] transformers==4.45.2
[pip3] triton==3.0.0
[conda] flashinfer 0.1.6+cu124torch2.4 pypi_0 pypi
[conda] numpy 1.26.4 pypi_0 pypi
[conda] nvidia-cublas-cu12 12.1.3.1 pypi_0 pypi
[conda] nvidia-cuda-cupti-cu12 12.1.105 pypi_0 pypi
[conda] nvidia-cuda-nvrtc-cu12 12.1.105 pypi_0 pypi
[conda] nvidia-cuda-runtime-cu12 12.1.105 pypi_0 pypi
[conda] nvidia-cudnn-cu12 9.1.0.70 pypi_0 pypi
[conda] nvidia-cufft-cu12 11.0.2.54 pypi_0 pypi
[conda] nvidia-curand-cu12 10.3.2.106 pypi_0 pypi
[conda] nvidia-cusolver-cu12 11.4.5.107 pypi_0 pypi
[conda] nvidia-cusparse-cu12 12.1.0.106 pypi_0 pypi
[conda] nvidia-ml-py 12.560.30 pypi_0 pypi
[conda] nvidia-nccl-cu12 2.20.5 pypi_0 pypi
[conda] nvidia-nvjitlink-cu12 12.6.68 pypi_0 pypi
[conda] nvidia-nvtx-cu12 12.1.105 pypi_0 pypi
[conda] pyzmq 26.2.0 pypi_0 pypi
[conda] torch 2.4.0 pypi_0 pypi
[conda] torchvision 0.19.0 pypi_0 pypi
[conda] transformers 4.45.2 pypi_0 pypi
[conda] triton 3.0.0 pypi_0 pypi
ROCM Version: Could not collect
Neuron SDK Version: N/A
vLLM Version: 0.6.4.dev22+g5b8a1fde
vLLM Build Flags:
CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled
GPU Topology:
GPU0 GPU1 GPU2 GPU3 GPU4 GPU5 GPU6 GPU7 NIC0 NIC1 NIC2 NIC3 NIC4 NIC5 NIC6 NIC7 NIC8 NIC9 NIC10 NIC11 NIC12 NIC13 NIC14 NIC15 CPU Affinity NUMA Affinity GPU NUMA ID
GPU0 X SYS SYS SYS SYS SYS SYS SYS PIX PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS 0-47,96-143 0 N/A
GPU1 SYS X SYS SYS SYS SYS SYS SYS SYS SYS PIX PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS 0-47,96-143 0 N/A
GPU2 SYS SYS X SYS SYS SYS SYS SYS SYS SYS SYS SYS PIX PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS 0-47,96-143 0 N/A
GPU3 SYS SYS SYS X SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS PIX PIX SYS SYS SYS SYS SYS SYS SYS SYS 0-47,96-143 0 N/A
GPU4 SYS SYS SYS SYS X SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS PIX PIX SYS SYS SYS SYS SYS SYS 48-95,144-191 1 N/A
GPU5 SYS SYS SYS SYS SYS X SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS PIX PIX SYS SYS SYS SYS 48-95,144-191 1 N/A
GPU6 SYS SYS SYS SYS SYS SYS X SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS PIX PIX SYS SYS 48-95,144-191 1 N/A
GPU7 SYS SYS SYS SYS SYS SYS SYS X SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS PIX PIX 48-95,144-191 1 N/A
NIC0 PIX SYS SYS SYS SYS SYS SYS SYS X PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS
NIC1 PIX SYS SYS SYS SYS SYS SYS SYS PIX X SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS
NIC2 SYS PIX SYS SYS SYS SYS SYS SYS SYS SYS X PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS
NIC3 SYS PIX SYS SYS SYS SYS SYS SYS SYS SYS PIX X SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS
NIC4 SYS SYS PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS X PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS
NIC5 SYS SYS PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS PIX X SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS
NIC6 SYS SYS SYS PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS X PIX SYS SYS SYS SYS SYS SYS SYS SYS
NIC7 SYS SYS SYS PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS PIX X SYS SYS SYS SYS SYS SYS SYS SYS
NIC8 SYS SYS SYS SYS PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS X PIX SYS SYS SYS SYS SYS SYS
NIC9 SYS SYS SYS SYS PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS PIX X SYS SYS SYS SYS SYS SYS
NIC10 SYS SYS SYS SYS SYS PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS X PIX SYS SYS SYS SYS
NIC11 SYS SYS SYS SYS SYS PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS PIX X SYS SYS SYS SYS
NIC12 SYS SYS SYS SYS SYS SYS PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS X PIX SYS SYS
NIC13 SYS SYS SYS SYS SYS SYS PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS PIX X SYS SYS
NIC14 SYS SYS SYS SYS SYS SYS SYS PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS X PIX
NIC15 SYS SYS SYS SYS SYS SYS SYS PIX SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS PIX X
Legend:
X = Self
SYS = Connection traversing PCIe as well as the SMP interconnect between NUMA nodes (e.g., QPI/UPI)
NODE = Connection traversing PCIe as well as the interconnect between PCIe Host Bridges within a NUMA node
PHB = Connection traversing PCIe as well as a PCIe Host Bridge (typically the CPU)
PXB = Connection traversing multiple PCIe bridges (without traversing the PCIe Host Bridge)
PIX = Connection traversing at most a single PCIe bridge
NV# = Connection traversing a bonded set of # NVLinks
NIC Legend:
NIC0: mlx5_0
NIC1: mlx5_1
NIC2: mlx5_2
NIC3: mlx5_3
NIC4: mlx5_4
NIC5: mlx5_5
NIC6: mlx5_6
NIC7: mlx5_7
NIC8: mlx5_8
NIC9: mlx5_9
NIC10: mlx5_10
NIC11: mlx5_11
NIC12: mlx5_12
NIC13: mlx5_13
NIC14: mlx5_14
NIC15: mlx5_15
Before submitting a new issue...
- [X] Make sure you already searched for relevant issues, and asked the chatbot living at the bottom right corner of the documentation page, which can answer lots of frequently asked questions.
Since the attention computation is still in FP16, could you benchmark with the original BF16 data type and see if there's still a gap? This could help locate the problem more precisely.
Maybe useful info: https://github.com/flashinfer-ai/flashinfer/issues/521
Thanks @jeejeelee but that issue related to prefill performance. A quick look using torch profiler indicates that the majority of time is spent in decode kernel for both backends:
using FLASH_ATTN:
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------
void flash_fwd_splitkv_kernel<Flash_fwd_kernel_trait... 0.00% 0.000us 0.00% 0.000us 0.000us 4.548s 43.56% 4.548s 138.797us 32768
void cutlass::device_kernel<(anonymous namespace)::c... 0.00% 0.000us 0.00% 0.000us 0.000us 3.026s 28.98% 3.026s 23.090us 131072
_C::cutlass_scaled_mm 0.22% 19.784ms 0.57% 50.497ms 12.328us 685.692ms 6.57% 685.739ms 167.417us 4096
void cutlass::device_kernel<(anonymous namespace)::c... 0.00% 0.000us 0.00% 0.000us 0.000us 685.692ms 6.57% 685.692ms 167.405us 4096
void vllm::scaled_fp8_quant_kernel<c10::BFloat16>(c1... 0.00% 0.000us 0.00% 0.000us 0.000us 453.434ms 4.34% 453.434ms 3.355us 135168
void vllm::act_and_mul_kernel<c10::BFloat16, &(c10::... 0.00% 0.000us 0.00% 0.000us 0.000us 387.954ms 3.72% 387.954ms 11.481us 33792
aten::linear 0.04% 3.608ms 0.89% 78.460ms 74.299us 0.000us 0.00% 382.781ms 362.482us 1056
aten::matmul 0.03% 2.210ms 0.78% 68.454ms 64.824us 0.000us 0.00% 382.781ms 362.482us 1056
aten::mm 0.52% 46.250ms 0.75% 66.244ms 62.731us 382.781ms 3.67% 382.781ms 362.482us 1056
sm90_xmma_gemm_bf16bf16_bf16f32_f32_tn_n_tilesize128... 0.00% 0.000us 0.00% 0.000us 0.000us 370.537ms 3.55% 370.537ms 361.852us 1024
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------
using FLASHINFER:
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------
Name Self CPU % Self CPU CPU total % CPU total CPU time avg Self CUDA Self CUDA % CUDA total CUDA time avg # of Calls
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------
void flashinfer::BatchDecodeWithPagedKVCacheKernel<(... 0.00% 0.000us 0.00% 0.000us 0.000us 6.172s 49.95% 6.172s 188.351us 32768
void cutlass::device_kernel<(anonymous namespace)::c... 0.00% 0.000us 0.00% 0.000us 0.000us 3.033s 24.55% 3.033s 23.140us 131072
_C::cutlass_scaled_mm 0.18% 19.947ms 0.46% 51.879ms 12.666us 682.428ms 5.52% 682.428ms 166.608us 4096
void cutlass::device_kernel<(anonymous namespace)::c... 0.00% 0.000us 0.00% 0.000us 0.000us 682.428ms 5.52% 682.428ms 166.608us 4096
void vllm::scaled_fp8_quant_kernel<c10::BFloat16>(c1... 0.00% 0.000us 0.00% 0.000us 0.000us 449.241ms 3.64% 449.241ms 3.324us 135168
void vllm::act_and_mul_kernel<c10::BFloat16, &(c10::... 0.00% 0.000us 0.00% 0.000us 0.000us 387.014ms 3.13% 387.014ms 11.453us 33792
aten::linear 0.04% 3.965ms 0.72% 81.374ms 77.059us 0.000us 0.00% 382.844ms 362.542us 1056
aten::matmul 0.02% 2.199ms 0.61% 69.100ms 65.436us 0.000us 0.00% 382.844ms 362.542us 1056
aten::mm 0.41% 46.417ms 0.59% 66.901ms 63.353us 382.844ms 3.10% 382.844ms 362.542us 1056
sm90_xmma_gemm_bf16bf16_bf16f32_f32_tn_n_tilesize128... 0.00% 0.000us 0.00% 0.000us 0.000us 370.651ms 3.00% 370.651ms 361.964us 1024
------------------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------ ------------
So it really seems like the Flashinfer decode kernel is slower than FA equivalent.
@comaniac Sure, here are the bf16 results, as well as some other datapoints we have collected:
The column FORCE_TENSOR_CORES relates to enabling the changes from this PR: https://github.com/vllm-project/vllm/pull/9497
It looks like the heuristic to determine when to enable the tensor cores isn't working well for this model: https://github.com/vllm-project/vllm/blob/1ffc8a73628ee8e3f6ad5aab54782d64050d17ea/vllm/attention/backends/flashinfer.py#L127
Kudos to my colleague @cyang49 for discovering this!
This issue seems relevant: https://github.com/flashinfer-ai/flashinfer/issues/520
It sounds like setting use_tensor_cores=True actually invokes the prefill kernel, so the issue that @jeejeelee linked above may indeed be very relevant.
@tdoublep @jeejeelee @cyang49 Thank you all for the investigation, and yes I do think the original heuristics doesn't work for fp8.
Closed via #9497