vllm: [Performance]: Prefill is not using cuda graph and become very slow when LORA enabled

Proposal to improve performance

No response

Report of performance regression

No response

Misc discussion on performance

I noticed that the captured cuda graph is not used in prefill stage: https://github.com/vllm-project/vllm/blob/e51719ae72dd1dcdf55436a99ac8bed245b51422/vllm/worker/model_runner.py#L1644

And thus when the lora enabled, the prefill become a bottleneck of first token latency.

e.g. Simply profile with llama2 base, the prefill stage take about ~25ms

llm = LLM(model="/home/zhn/g/Llama-2-7b-hf")
llm.start_profile()
sampling_params = SamplingParams(
    top_p=0.9,
    temperature=0.7,
    max_tokens=10,
    stop=["[/assistant]"]
)
for i in range(2):
    outputs_1 = llm.generate(
        prompts,
        sampling_params
    )
llm.stop_profile()

image

Now apply the lora, the lora model is same as https://docs.vllm.ai/en/latest/usage/lora.html, the prefill stage take about 105ms?

llm = LLM(model="/home/zhn/g/Llama-2-7b-hf", enable_lora=True)
llm.start_profile()
sampling_params = SamplingParams(
    top_p=0.9,
    temperature=0.7,
    max_tokens=10,
    stop=["[/assistant]"]
)
for i in range(2):
    outputs_1 = llm.generate(
        prompts,
        sampling_params,
        lora_request=LoRARequest("sql_adapter", 1, '/home/zhn/g/llama-2-7b-sql-lora-test')
    )
llm.stop_profile()

image

Detail trace can be found in attached *.gz

So is there anything I can do to mitigate the perf issue? Can I force to use the captured cuda graph(If I will pad to the specific length), and will it help?

llama_lora.gz llama_base.gz

Your current environment (if you think it is necessary)

Warning: Your installation of OpenCV appears to be broken: module 'cv2.dnn' has no attribute 'DictValue'.Please follow the instructions at https://github.com/opencv/opencv-python/issues/884 to correct your environment. The import of cv2 has been skipped.
WARNING 12-23 15:14:05 cuda.py:32] You are using a deprecated `pynvml` package. Please install `nvidia-ml-py` instead, and make sure to uninstall `pynvml`. When both of them are installed, `pynvml` will take precedence and cause errors. See https://pypi.org/project/pynvml for more information.
Collecting environment information...
PyTorch version: 2.5.1+cu124
Is debug build: False
CUDA used to build PyTorch: 12.4
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.29.2
Libc version: glibc-2.35

Python version: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-6.8.0-1017-azure-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.4.131
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA A100 80GB PCIe
Nvidia driver version: 555.42.06
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.1.0
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:                        48 bits physical, 48 bits virtual
Byte Order:                           Little Endian
CPU(s):                               24
On-line CPU(s) list:                  0-23
Vendor ID:                            AuthenticAMD
Model name:                           AMD EPYC 7V13 64-Core Processor
CPU family:                           25
Model:                                1
Thread(s) per core:                   1
Core(s) per socket:                   24
Socket(s):                            1
Stepping:                             1
BogoMIPS:                             4890.87
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl tsc_reliable nonstop_tsc cpuid extd_apicid aperfmperf pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw topoext perfctr_core vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves user_shstk clzero xsaveerptr rdpru arat umip vaes vpclmulqdq rdpid fsrm
Hypervisor vendor:                    Microsoft
Virtualization type:                  full
L1d cache:                            768 KiB (24 instances)
L1i cache:                            768 KiB (24 instances)
L2 cache:                             12 MiB (24 instances)
L3 cache:                             96 MiB (3 instances)
NUMA node(s):                         1
NUMA node0 CPU(s):                    0-23
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 Reg file data sampling: Not affected
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   Vulnerable: Safe RET, no microcode
Vulnerability Spec store bypass:      Vulnerable
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Retpolines; STIBP disabled; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] numpy==1.26.4
[pip3] nvidia-cublas-cu12==12.4.5.8
[pip3] nvidia-cuda-cupti-cu12==12.4.127
[pip3] nvidia-cuda-nvrtc-cu12==12.4.127
[pip3] nvidia-cuda-runtime-cu12==12.4.127
[pip3] nvidia-cudnn-cu12==9.1.0.70
[pip3] nvidia-cudnn-frontend==1.3.0
[pip3] nvidia-cufft-cu12==11.2.1.3
[pip3] nvidia-curand-cu12==10.3.5.147
[pip3] nvidia-cusolver-cu12==11.6.1.9
[pip3] nvidia-cusparse-cu12==12.3.1.170
[pip3] nvidia-dali-cuda120==1.37.1
[pip3] nvidia-ml-py==12.560.30
[pip3] nvidia-nccl-cu12==2.21.5
[pip3] nvidia-nvimgcodec-cu12==0.2.0.7
[pip3] nvidia-nvjitlink-cu12==12.4.127
[pip3] nvidia-nvtx-cu12==12.4.127
[pip3] nvidia-pyindex==1.0.9
[pip3] onnx==1.16.0
[pip3] optree==0.11.0
[pip3] pynvml==11.4.1
[pip3] pytorch-quantization==2.1.2
[pip3] pytorch-triton==3.0.0+989adb9a2
[pip3] pyzmq==26.0.3
[pip3] torch==2.5.1
[pip3] torch-tensorrt==2.4.0a0
[pip3] torchvision==0.20.1
[pip3] transformers==4.47.1
[pip3] triton==3.1.0
[conda] Could not collect
ROCM Version: Could not collect
Neuron SDK Version: N/A
vLLM Version: 0.6.5
vLLM Build Flags:
CUDA Archs: 5.2 6.0 6.1 7.0 7.2 7.5 8.0 8.6 8.7 9.0+PTX; ROCm: Disabled; Neuron: Disabled
GPU Topology:
GPU0    NIC0    CPU Affinity    NUMA Affinity   GPU NUMA ID
GPU0     X      SYS     0-23    0               N/A
NIC0    SYS      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

NVIDIA_VISIBLE_DEVICES=all
CUBLAS_VERSION=12.4.5.8
NVIDIA_REQUIRE_CUDA=cuda>=9.0
CUDA_CACHE_DISABLE=1
TORCH_CUDA_ARCH_LIST=5.2 6.0 6.1 7.0 7.2 7.5 8.0 8.6 8.7 9.0+PTX
NCCL_VERSION=2.21.5
NVIDIA_DRIVER_CAPABILITIES=compute,utility,video
NVIDIA_PRODUCT_NAME=PyTorch
CUDA_VERSION=12.4.1.003
PYTORCH_VERSION=2.4.0a0+07cecf4
PYTORCH_BUILD_NUMBER=0
CUDNN_VERSION=9.1.0.70
PYTORCH_HOME=/opt/pytorch/pytorch
LD_LIBRARY_PATH=/usr/local/lib/python3.10/dist-packages/cv2/../../lib64:/usr/local/lib/python3.10/dist-packages/torch/lib:/usr/local/lib/python3.10/dist-packages/torch_tensorrt/lib:/usr/local/cuda/compat/lib:/usr/local/nvidia/lib:/usr/local/nvidia/lib64
NVIDIA_BUILD_ID=91431255
CUDA_DRIVER_VERSION=550.54.15
PYTORCH_BUILD_VERSION=2.4.0a0+07cecf4
CUDA_HOME=/usr/local/cuda
CUDA_HOME=/usr/local/cuda
CUDA_MODULE_LOADING=LAZY
NVIDIA_REQUIRE_JETPACK_HOST_MOUNTS=
NVIDIA_PYTORCH_VERSION=24.05
TORCH_ALLOW_TF32_CUBLAS_OVERRIDE=1

Before submitting a new issue…

  • 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.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (1 by maintainers)

Most upvoted comments

Hello, I noticed that CUDA graph is very useful, but why hasn’t it been used in the prefill stage? Is it feasible to implement it? @youkaichao

prefill attention is not compatible with cudagraph. in v1 code, maybe we can enable piecewise cudagraph for prefill as well. cc @jeejeelee if you think this is meaningful. right now we don’t consider torch.compile for lora.

Not sure if the prefill lora supports cuda graph - I’ll spend some time investigating this further.

The main issue is that triton’s runtime overhead is quite significant. We’re working on optimizing this.

Hello, I noticed that CUDA graph is very useful, but why hasn’t it been used in the prefill stage? Is it feasible to implement it? @youkaichao

We’ve noticed this issue and are actively working on optimizations. We welcome contributions to help address it. There’s currently a WIP PR, see: #11234. The functionality in this PR is complete - feel free to test it out if you’re interested.

Thanks for quick response. I saw you are trying to fuse kernel to speed up. Can capture prefill cuda graph be another solution? If input length is an issue, we can consider make it together with chunk prefill

Have you tested this PR?

i test, about 15%+ prefill time optimize,but the time is till large with no lora model, and #11234 make diff

We will continue trying to optimize this

We’ve noticed this issue and are actively working on optimizations. We welcome contributions to help address it. There’s currently a WIP PR, see: #11234. The functionality in this PR is complete - feel free to test it out if you’re interested.

Thanks for quick response. I saw you are trying to fuse kernel to speed up. Can capture prefill cuda graph be another solution? If input length is an issue, we can consider make it together with chunk prefill

have you try use cudagraph with chunk prefill in prefill? i think cudagraph will be very useful for lora prefill, triton overhead and other cpu overhead is very heavy, although we can cache the triton kernel,the overall overhead is still heavy

Yes, I tried but seems the attention was corrupt. The predict token is different after few steps. I am using the vllm to accelerate fish tts model, which the decode stage have a little different with prefill stage. Currently I am not sure the issue comes from the model difference or the vllm runtime (I do see some codes are assuming the prefill stage is not using cuda graph, I am not sure I have modified them correctly)