vllm: [Bug]: Using fp8 cutlass scaled_mm causes wrong output

Your current environment

The output of `python collect_env.py`
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.0
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-5.4.119-19.0009.40-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.5.82
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA L20
GPU 1: NVIDIA L20
GPU 2: NVIDIA L20
GPU 3: NVIDIA L20
GPU 4: NVIDIA L20
GPU 5: NVIDIA L20
GPU 6: NVIDIA L20
GPU 7: NVIDIA L20

Nvidia driver version: 535.161.07
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.2.1
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.2.1
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.2.1
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.2.1
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.2.1
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.2.1
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.2.1
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.2.1
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, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          384
On-line CPU(s) list:             0-383
Vendor ID:                       AuthenticAMD
Model name:                      AMD EPYC 9K84 96-Core Processor
CPU family:                      25
Model:                           17
Thread(s) per core:              2
Core(s) per socket:              96
Socket(s):                       2
Stepping:                        0
BogoMIPS:                        5200.05
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 nonstop_tsc cpuid extd_apicid amd_dcm tsc_known_freq pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw topoext perfctr_core invpcid_single ibpb vmmcall fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 avx512_bf16 clzero xsaveerptr wbnoinvd arat avx512vbmi umip avx512_vbmi2 vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid fsrm
Hypervisor vendor:               KVM
Virtualization type:             full
L1d cache:                       6 MiB (192 instances)
L1i cache:                       6 MiB (192 instances)
L2 cache:                        192 MiB (192 instances)
L3 cache:                        768 MiB (24 instances)
NUMA node(s):                    2
NUMA node0 CPU(s):               0-191
NUMA node1 CPU(s):               192-383
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Spec store bypass: Vulnerable
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Full AMD retpoline, IBPB conditional, STIBP disabled, RSB filling
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] numpy==1.24.4
[pip3] nvidia-nccl-cu12==2.20.5
[pip3] onnx==1.16.0
[pip3] optree==0.12.1
[pip3] pytorch-triton==3.0.0+989adb9a2
[pip3] pyzmq==26.0.3
[pip3] torch==2.4.0
[pip3] torch-tensorrt==2.5.0a0
[pip3] torchvision==0.19.0
[pip3] transformers==4.44.1
[pip3] triton==3.0.0
[conda] Could not collect
ROCM Version: Could not collect
Neuron SDK Version: N/A
vLLM Version: 0.5.4
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	GPU1	GPU2	GPU3	GPU4	GPU5	GPU6	GPU7	CPU Affinity	NUMA Affinity	GPU NUMA ID
GPU0	 X 	NODE	NODE	NODE	SYS	SYS	SYS	SYS	0-191	0		N/A
GPU1	NODE	 X 	PIX	NODE	SYS	SYS	SYS	SYS	0-191	0		N/A
GPU2	NODE	PIX	 X 	NODE	SYS	SYS	SYS	SYS	0-191	0		N/A
GPU3	NODE	NODE	NODE	 X 	SYS	SYS	SYS	SYS	0-191	0		N/A
GPU4	SYS	SYS	SYS	SYS	 X 	NODE	NODE	NODE	192-383	1		N/A
GPU5	SYS	SYS	SYS	SYS	NODE	 X 	PIX	NODE	192-383	1		N/A
GPU6	SYS	SYS	SYS	SYS	NODE	PIX	 X 	NODE	192-383	1		N/A
GPU7	SYS	SYS	SYS	SYS	NODE	NODE	NODE	 X 	192-383	1		N/A

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

🐛 Describe the bug

Using the new fp8 cutlass scaled_mm kernel (merged in https://github.com/vllm-project/vllm/pull/6677), I got some weird output like “ROUP!!!”. Token ids of the output are something like 18347, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0. I am using vllm 0.5.4, and a model finetuned from https://huggingface.co/deepseek-ai/deepseek-coder-6.7b-base @varun-sundar-rabindranath @mgoin

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 32 (13 by maintainers)

Most upvoted comments

Hi @xTayEx - Update: I checked the CUDA version, that my env is using to using to build the CUDA kernels - it is >12.4.

Although pytorch is built using CUDA 12.1, the cutlass kernels are built using 12.4.

My collect_env.py output says,

CUDA runtime version: Could not collect

as I did not have nvcc on my Path env var. The path was set as export CUDACXX=/usr/local/cuda-12.5/bin/nvcc in my bashrc, so cmake did not complain. After setting export PATH=$PATH:/usr/local/cuda-12.5/bin/, my collect_env.py reports the right CUDA version, as

CUDA runtime version: 12.5.82

which is the same as what you have in your env.

I am trying an L4 machine, with the the docker image nvcr.io/nvidia/pytorch:24.07-py3, and tag 0.5.4 to see if I can repro there. 🤞

Hi @varun-sundar-rabindranath, I tried to run the kernel in another docker image - nvcr.io/nvidia/cuda:12.5.1-cudnn-devel-ubuntu22.04 on the same L40 machine. All unit test in test_cutlass.py success. So I think this might be an environment issue. I’ll keep working on this and see what in nvcr.io/nvidia/pytorch:24.07-py3 causing the bug.

image

Hi @xTayEx - thanks for the updates. I don’t have a repro yet. The cuda version from the env that you pointed out makes sense. I’ll check it out.

Thanks for the bug report. I am looking into this.

Thanks @xTayEx - can you please check if the tests pass using nvcr.io/nvidia/cuda:12.5.1-cudnn-devel-ubuntu22.04 on the L20 machine ?

@Juelianqvq This PR #6677 has information about the cutlass FP8 speedup/regression. The cutlass kernels help in the small M cases, but not when M is large.

All tests pass on L20 using the nvcr.io/nvidia/cuda:12.5.1-cudnn-devel-ubuntu22.04 docker image. image

Update on this : I have a repro on a L4 machine. Thanks @xTayEx !

Some update of my debuging: on an L40 GPU, I find that cutlass_scaled_mm doesn’t write back to the output tensor. I modify the code in https://github.com/vllm-project/vllm/blob/d81abefd2ee8e1f4b46b3660ebdaf7b8e19c573a/vllm/_custom_ops.py#L247 as below. image And find that out_before and out_after are exactly the same.

@xTayEx - my collect_env.py outputs is,

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.3 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.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-5.15.0-94-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 L40S
GPU 1: NVIDIA L40S
GPU 2: NVIDIA L40S
GPU 3: NVIDIA L40S
GPU 4: NVIDIA L40S
GPU 5: NVIDIA L40S
GPU 6: NVIDIA L40S
GPU 7: NVIDIA L40S
GPU 8: NVIDIA L40S
GPU 9: NVIDIA L40S

Nvidia driver version: 555.42.06
cuDNN version: Could not collect
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:                      46 bits physical, 57 bits virtual
Byte Order:                         Little Endian
CPU(s):                             80
On-line CPU(s) list:                0-79
Vendor ID:                          AuthenticAMD
Model name:                         AMD EPYC 9254 24-Core Processor
CPU family:                         25
Model:                              17
Thread(s) per core:                 2
Core(s) per socket:                 4
Socket(s):                          10
Stepping:                           1
BogoMIPS:                           5799.99
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 nonstop_tsc cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy svm cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw topoext perfctr_core invpcid_single ssbd ibrs ibpb stibp vmmcall fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves avx512_bf16 clzero xsaveerptr wbnoinvd arat npt lbrv nrip_save tsc_scale vmcb_clean pausefilter pfthreshold v_vmsave_vmload vgif avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid fsrm flush_l1d arch_capabilities
Virtualization:                     AMD-V
Hypervisor vendor:                  KVM
Virtualization type:                full
L1d cache:                          1.3 MiB (40 instances)
L1i cache:                          1.3 MiB (40 instances)
L2 cache:                           40 MiB (40 instances)
L3 cache:                           160 MiB (5 instances)
NUMA node(s):                       2
NUMA node0 CPU(s):                  0-39
NUMA node1 CPU(s):                  40-79
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: Mitigation; safe RET
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; Retpolines, IBPB conditional, IBRS_FW, STIBP always-on, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Not affected

Versions of relevant libraries:
[pip3] mypy==1.11.1
[pip3] mypy-extensions==1.0.0
[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.20
[pip3] nvidia-nvtx-cu12==12.1.105
[pip3] pyzmq==26.2.0
[pip3] sentence-transformers==3.0.1
[pip3] torch==2.4.0
[pip3] torchvision==0.19.0
[pip3] transformers==4.44.1
[pip3] transformers-stream-generator==0.0.5
[pip3] triton==3.0.0
[conda] Could not collect
ROCM Version: Could not collect
Neuron SDK Version: N/A
vLLM Version: 0.5.4@9b73a2f498e8bf8e18305a8afea84536e9330088
vLLM Build Flags:
CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled
GPU Topology:
GPU0	GPU1	GPU2	GPU3	GPU4	GPU5	GPU6	GPU7	GPU8	GPU9	CPU Affinity	NUMA Affinity	GPU NUMA ID
GPU0	 X 	PHB	PHB	PHB	PHB	SYS	SYS	SYS	SYS	SYS	0-39	0		N/A
GPU1	PHB	 X 	PHB	PHB	PHB	SYS	SYS	SYS	SYS	SYS	0-39	0		N/A
GPU2	PHB	PHB	 X 	PHB	PHB	SYS	SYS	SYS	SYS	SYS	0-39	0		N/A
GPU3	PHB	PHB	PHB	 X 	PHB	SYS	SYS	SYS	SYS	SYS	0-39	0		N/A
GPU4	PHB	PHB	PHB	PHB	 X 	SYS	SYS	SYS	SYS	SYS	0-39	0		N/A
GPU5	SYS	SYS	SYS	SYS	SYS	 X 	PHB	PHB	PHB	PHB	40-79	1		N/A
GPU6	SYS	SYS	SYS	SYS	SYS	PHB	 X 	PHB	PHB	PHB	40-79	1		N/A
GPU7	SYS	SYS	SYS	SYS	SYS	PHB	PHB	 X 	PHB	PHB	40-79	1		N/A
GPU8	SYS	SYS	SYS	SYS	SYS	PHB	PHB	PHB	 X 	PHB	40-79	1		N/A
GPU9	SYS	SYS	SYS	SYS	SYS	PHB	PHB	PHB	PHB	 X 	40-79	1		N/A

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

@varun-sundar-rabindranath FYI, I built vllm from source, using the tag v0.5.4, in a nvcr.io/nvidia/pytorch:24.07-py3 docker image. My colleague installs v0.5.4 from pypi, and everything works well, the output looks perfect. Is there any difference between these two installation method?

@xTayEx Thanks for checking this. Ill try building in that docker image for a repro tomorrow. Also, I have been building from source off of the latest main. I’ll try using the tag as well.

It would be useful to have a direct minimal reproducible code example from your environment with a public model. Most of our CI in vLLM uses L4 GPUs, so we should have accuracy tests regularly running with these kernels.

Thank you for the reply! Below code should reproduce the bug:

from vllm import LLM, SamplingParams
import time
import os
import json

sampling_params = SamplingParams(max_tokens=32, temperature=0, top_p=0.8, top_k=40, ignore_eos=True)

# Create an LLM.
llm = LLM(model="/path/to/Qwen2-7B", max_num_seqs=1, tensor_parallel_size=1, 
          enforce_eager=True,
          quantization="fp8",
          distributed_executor_backend='mp')

prompts = ["Hello vllm! I am from"]
outputs = llm.generate(prompts, sampling_params)

print(outputs)

Output of the script on my machine is show below image

The model used is https://www.modelscope.cn/models/qwen/Qwen2-7B.

It would be useful to have a direct minimal reproducible code example from your environment with a public model. Most of our CI in vLLM uses L4 GPUs, so we should have accuracy tests regularly running with these kernels.