vllm-project / vllm

A high-throughput and memory-efficient inference and serving engine for LLMs
https://docs.vllm.ai
Apache License 2.0
27.07k stars 3.98k forks source link

[Bug]: The FP8 models and FP8 KV-Cache-Scales loaded together failed on the latest 0.5.3 #6738

Closed wanzhenchn closed 1 month ago

wanzhenchn commented 1 month ago

Your current environment

Collecting environment information...
PyTorch version: 2.3.1+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.27.6
Libc version: glibc-2.35

Python version: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-5.15.0-125.006-shopee-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.2.140
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.90.07
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.9.5
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.9.5
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.9.5
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.9.5
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.9.5
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.9.5
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.9.5
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 8468
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 avx512_fp16 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:                           210 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] numpy==1.22.2
[pip3] nvidia-nccl-cu12==2.20.5
[pip3] onnx==1.14.0
[pip3] pytorch-quantization==2.1.2
[pip3] torch==2.3.1
[pip3] torch-tensorrt==0.0.0
[pip3] torchdata==0.7.0a0
[pip3] torchtext==0.16.0a0
[pip3] torchvision==0.18.1
[pip3] transformers==4.42.4
[pip3] triton==2.3.1
[conda] Could not collect
ROCM Version: Could not collect
Neuron SDK Version: N/A
vLLM Version: 0.5.3
vLLM Build Flags:
CUDA Archs: 7.0 7.5 8.0 8.6 8.9 9.0+PTX; ROCm: Disabled; Neuron: Disabled
GPU Topology:
GPU0    GPU1    GPU2    GPU3    GPU4    GPU5    GPU6    GPU7    NIC0    NIC1    NIC2    NIC3    NIC4    CPU Affinity    NUMA Affinity   GPU NUMA ID
GPU0     X  NV18    NV18    NV18    NV18    NV18    NV18    NV18    PIX NODE    SYS SYS NODE    0-47,96-143 0       N/A
GPU1    NV18     X  NV18    NV18    NV18    NV18    NV18    NV18    PXB NODE    SYS SYS NODE    0-47,96-143 0       N/A
GPU2    NV18    NV18     X  NV18    NV18    NV18    NV18    NV18    NODE    PXB SYS SYS NODE    0-47,96-143 0       N/A
GPU3    NV18    NV18    NV18     X  NV18    NV18    NV18    NV18    NODE    PIX SYS SYS NODE    0-47,96-143 0       N/A
GPU4    NV18    NV18    NV18    NV18     X  NV18    NV18    NV18    SYS SYS PXB NODE    SYS 48-95,144-191   1       N/A
GPU5    NV18    NV18    NV18    NV18    NV18     X  NV18    NV18    SYS SYS PIX NODE    SYS 48-95,144-191   1       N/A
GPU6    NV18    NV18    NV18    NV18    NV18    NV18     X  NV18    SYS SYS NODE    PXB SYS 48-95,144-191   1       N/A
GPU7    NV18    NV18    NV18    NV18    NV18    NV18    NV18     X  SYS SYS NODE    PIX SYS 48-95,144-191   1       N/A
NIC0    PIX PXB NODE    NODE    SYS SYS SYS SYS  X  NODE    SYS SYS NODE                
NIC1    NODE    NODE    PXB PIX SYS SYS SYS SYS NODE     X  SYS SYS NODE                
NIC2    SYS SYS SYS SYS PXB PIX NODE    NODE    SYS SYS  X  NODE    SYS             
NIC3    SYS SYS SYS SYS NODE    NODE    PXB PIX SYS SYS NODE     X  SYS             
NIC4    NODE    NODE    NODE    NODE    SYS SYS SYS SYS NODE    NODE    SYS 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
  NIC1: mlx5_1
  NIC2: mlx5_4
  NIC3: mlx5_5
  NIC4: mlx5_bond_0

🐛 Describe the bug

I followed the docs (https://github.com/vllm-project/vllm/blob/main/docs/source/quantization/fp8.rst and https://github.com/vllm-project/vllm/tree/main/examples/fp8) to quantize vicuna-13b-v1.5 with fp8 precision on 1*H100, and got the fp8 models and kv_cache_scales.json file successfully using following commands:

Credit to: https://github.com/vllm-project/vllm/blob/main/docs/source/quantization/fp8.rst

class AutoFP8: def init(self, model_path: str, saved_path: str, calib_size: int = 512, activation_scheme: str = "static"): self.saved_path = saved_path self.calib_size = calib_size

    self.quantize_config = BaseQuantizeConfig(
        quant_method="fp8", activation_scheme=activation_scheme)

    self.tokenizer = AutoTokenizer.from_pretrained(
        model_path, use_fast=True)
    self.tokenizer.pad_token = self.tokenizer.eos_token

    self.model = AutoFP8ForCausalLM.from_pretrained(model_path,
                                                    self.quantize_config)

def apply_fp8(self):
    # Load and tokenize 512 dataset samples for calibration of activation scales
    ds = load_dataset("mgoin/ultrachat_2k", split="train_sft").select(
        range(self.calib_size))
    examples = [self.tokenizer.apply_chat_template(
        batch["messages"], tokenize=False) for batch in ds]
    examples = self.tokenizer(examples, padding=True, truncation=True,
                              return_tensors="pt").to("cuda")

    # quantize, and save checkpoint
    self.model.quantize(examples)
    self.model.save_quantized(self.saved_path)

def main(model_path: str, saved_path: str, calib_size: int = 512, ): fp8_helper = AutoFP8(model_path, saved_path, calib_size) fp8_helper.apply_fp8()

if name == "main": fire.Fire(main)

- FP8 KV Cache scales
```bash
set -euxo pipefail

# https://github.com/vllm-project/vllm/tree/main/examples/fp8

if [ $# = 4 ]; then
  model_path=$1
  output_model_path=$2
  output_kv_cache_path=$3
  device_id=$4

  gpu_num=$(echo "$device_id" |grep -o "[0-9]" |grep -c "")
  export CUDA_VISIBLE_DEVICES=$device_id

  output_model_path+="-tp${gpu_num}"
  output_name="kv_cache_fp8_scales_tp${gpu_num}.json"

  if [ "$(pip list | grep nvidia-ammo | wc -l)" -eq "0" ]; then
    pip install --no-cache-dir --extra-index-url https://pypi.nvidia.com nvidia-ammo==0.7.1
  fi

  # 1. Convert HF model into a quantized HF model.
  if [ ! -d ${output_model_path} ]; then
    python fp8/quantizer/quantize.py \
      --model-dir ${model_path} \
      --dtype float16 \
      --qformat fp8 \
      --kv-cache-dtype fp8 \
      --calib-size 512 \
      --tp-size ${gpu_num} \
      --output-dir ${output_model_path}
  else
    echo "The quantized hf model already exits in ${output_model_path}"
  fi

  # 2. Extract KV Cache Scaling Factors from quantized HF model.
  python3 fp8/extract_scales.py \
    --quantized-model ${output_model_path} \
    --tp-size ${gpu_num} \
    --output-name ${output_name} \
    --output-dir $output_kv_cache_path

else
  echo "Usage: $0 hf_model_path quantized_hf_model_path kv_cache_path device_id(0,1)"
  exit
fi

However, when I launched openai server with --quantization fp8, --kv-cache-dtype fp8 and --quantization-param-path ${output_kv_cache_scales_file}, problems occurred below:

image

But if we only pass --quantization fp8 when launching server, everything works well.

I think that there are some gaps between nvidia-ammo (called modelopt now )tool and the lastest vllm, the docs for FP8 KV Cache need to be updated promptly.

w013nad commented 1 month ago

I had the same issue on my machine. Seems to be an issue with 0.5.3(and .post1). This worked on 0.5.2.

QwertyJack commented 1 month ago

In addition, kv8 fails with other quant like GPTQ or AWQ.

mgoin commented 1 month ago

Thank you for reporting @wanzhenchn @w013nad @QwertyJack . This unfortunately was a simple issue that didn't have testing. This will be resolved in the attached PR

wanzhenchn commented 1 month ago

Thank you for reporting @wanzhenchn @w013nad @QwertyJack . This unfortunately was a simple issue that didn't have testing. This will be resolved in the attached PR

Many thanks for your response.

I noticed that when passing--quantization fp8 --kv-cache-dtype fp8 --quantization-param-path kv_cache_scales.json , the k/v scale is set to 1.0.

https://github.com/vllm-project/vllm/blob/eda606ede95bee8abd46af4c290daddb64e7852e/vllm/model_executor/layers/quantization/kv_cache.py#L42-L63

What is the rationale behind this? Why aren't the k/v scales read from the JSON file? the is_hip() is False on NV GPU.

https://github.com/vllm-project/vllm/blob/eda606ede95bee8abd46af4c290daddb64e7852e/vllm/worker/model_runner.py#L763-L788

@mgoin

wanzhenchn commented 1 month ago

I had the same issue on my machine. Seems to be an issue with 0.5.3(and .post1). This worked on 0.5.2.

Yeah, I also noticed that.