InternLM / lmdeploy

LMDeploy is a toolkit for compressing, deploying, and serving LLMs.
https://lmdeploy.readthedocs.io/en/latest/
Apache License 2.0
4.4k stars 394 forks source link

[Bug] Mini-InternVL-Chat-2B-V1-5 AWQ量化后推理速度比量化前慢 #2148

Open hezeli123 opened 2 months ago

hezeli123 commented 2 months ago

Checklist

Describe the bug

在A10上 ,Mini-InternVL-Chat-2B-V1-5 AWQ量化后推理速度比量化前慢. 从压测效果上看,量化没有提升推理性能,反而会降低一些性能。 同样的测试集推理效果对比:

Reproduction

lmdeploy lite auto_awq Mini-InternVL-Chat-2B-V1-5 --calib-dataset 'ptb' --calib-samples 128 --calib-seqlen 2048 --w-bits 4 --w-group-size 128 --batch-size 1 --search-scale False --work-dir ./Mini-InternVL-Chat-2B-V1-5-awq

lmdeploy serve api_server Mini-InternVL-Chat-2B-V1-5-awq/ --server-port 8000 --model-format awq

Environment

sys.platform: linux
Python: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
CUDA available: True
MUSA available: False
numpy_random_seed: 2147483648
GPU 0: NVIDIA A10
CUDA_HOME: /usr/local/cuda
NVCC: Cuda compilation tools, release 12.3, V12.3.107
GCC: x86_64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
PyTorch: 2.2.1+cu121
PyTorch compiling details: PyTorch built with:
  - GCC 9.3
  - C++ Version: 201703
  - Intel(R) oneAPI Math Kernel Library Version 2022.2-Product Build 20220804 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v3.3.2 (Git Hash 2dc95a2ad0841e29db8b22fbccaf3e5da7992b01)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: AVX512
  - CUDA Runtime 12.3
  - Built with CUDA Runtime 12.1
  - NVCC architecture flags: -gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86;-gencode;arch=compute_90,code=sm_90
  - CuDNN 8.9.7  (built against CUDA 12.2)
    - Built with CuDNN 8.9.2
  - Magma 2.6.1
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=12.1, CUDNN_VERSION=8.9.2, CXX_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/c++, CXX_FLAGS= -D_GLIBCXX_USE_CXX11_ABI=0 -fabi-version=11 -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOROCTRACER -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-stringop-overflow -Wsuggest-override -Wno-psabi -Wno-error=pedantic -Wno-error=old-style-cast -Wno-missing-braces -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=2.2.1, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=1, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, USE_ROCM_KERNEL_ASSERT=OFF, 

TorchVision: 0.17.1+cu121
LMDeploy: 0.5.1+
transformers: 4.37.2
gradio: 3.50.2
fastapi: 0.110.0
pydantic: 2.7.1
triton: 2.2.0
NVIDIA Topology: 
        GPU0    CPU Affinity    NUMA Affinity   GPU NUMA ID
GPU0     X      0-31,64-95      0               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

Error traceback

No response

hezeli123 commented 2 months ago

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">

并发数 | norm tokens/s | awq  tokens/s -- | -- | -- 1 | 40.93 | 42.06 2 | 62 | 60.52 4 | 79.08 | 73.32 8 | 94.4 | 80.8 16 | 94.4 | 98.88 32 | 100 | 101.44 64 | 123.52 | 119.68

lvhan028 commented 2 months ago

Could you share the benchmark scripts?

hezeli123 commented 2 months ago

Could you share the benchmark scripts?

脚本很简单,主要方式是 一批外网的url(如:http://img1.baidu.com/it/u=3682444617,1983875605&fm=253&app=138&f=JPEG?w=1067&h=800),采样同步轮询调用openai接口,统计的瓶颈吞吐

@lvhan028 你也可以使用你们内部的方式看下性能情况,感觉针对规模较小的模型,量化加速效果不好。

lvhan028 commented 2 months ago

We didn't benchmark the VLM models but the LLM models. AWQ outperforms Half when batch_size < 256. The smaller the batch size, the faster AWQ is. The test script benchmark/profile_throughput.py

Howe-Young commented 1 month ago

We didn't benchmark the VLM models but the LLM models. AWQ outperforms Half when batch_size < 256. The smaller the batch size, the faster AWQ is. The test script benchmark/profile_throughput.py

我也遇到了这个问题,用的batch=1推理的,awq w4a16量化后比量化前稍慢一点,我的机器是A100-80G 通过nvidia-smi简单来看利用率,还挺高的(经常98%,偶尔跳下来六七十)