InternLM / lmdeploy

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

[Bug] IntrenVL2-1B awq量化后推理异常问题 #2221

Closed Jeremy-J-J closed 2 months ago

Jeremy-J-J commented 3 months ago

Checklist

Describe the bug

InternVL2-1B awq 4bit量化后推理异常,推理耗时异常(A6000上不量化推理耗时1.2s,量化后推理耗时18s)且输出异常,输出一堆 """"""""

Reproduction

量化脚本

export HF_MODEL=/workspace/data/hf_models/hub/internvl/checkpointmerged
export WORK_DIR=/workspace/data/hf_models/hub/internvl/checkpoint-merged.int4

CUDA_VISIBLE_DEVICES=1 lmdeploy lite auto_awq \
   $HF_MODEL \
   --w-bits 4 \
   --work-dir $WORK_DIR

将量化完成后checkpoint-merged.int4下文件拷贝至internvl-1B-4bit

量化后推理脚本

from lmdeploy import pipeline, TurbomindEngineConfig, ChatTemplateConfig
from lmdeploy.vl import load_image
import time

#model = 'OpenGVLab/InternVL2-26B'
model = "/workspace/data/hf_models/hub/internvl/internvl-1B-4bit"
system_prompt = '我是书生·万象,英文名是InternVL,是由上海人工智能实验室及多家合作单位联合开发的多模态大语言模型。'
image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
chat_template_config = ChatTemplateConfig('internvl-internlm2')
chat_template_config.meta_instruction = system_prompt
pipe = pipeline(model, chat_template_config=chat_template_config,
                backend_config=TurbomindEngineConfig(session_len=8192))

for i in range(1):
    start = time.time()
    response = pipe(('describe this image', image))
    end = time.time()
    print("sigle infer time : ", end - start)

print(response.text)
# print(response)

Environment

A6000
lmdeploy check_env

sys.platform: linux
Python: 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0]
CUDA available: True
MUSA available: False
numpy_random_seed: 2147483648
GPU 0,1: NVIDIA RTX A6000
CUDA_HOME: /usr/local/cuda
NVCC: Cuda compilation tools, release 12.2, V12.2.140
GCC: x86_64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
PyTorch: 2.2.2+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.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.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.2, 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.2+cu121
LMDeploy: 0.5.2.post1+
transformers: 4.41.2
gradio: 4.40.0
fastapi: 0.111.1
pydantic: 2.8.2
triton: 2.2.0
NVIDIA Topology: 
        GPU0    GPU1    CPU Affinity    NUMA Affinity   GPU NUMA ID
GPU0     X      SYS     0-27,56-83      0               N/A
GPU1    SYS      X      28-55,84-111    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

### Error traceback

```Shell
量化后推理输出

Some weights of the model checkpoint at /workspace/data/hf_models/hub/internvl/internvl-1B-4bit were not used when initializing InternVLChatModel: ['language_model.model.layers.0.mlp.down_proj.qweight', 'language_model.model.layers.0.mlp.down_proj.qzeros', 'language_model.model.layers.0.mlp.down_proj.scales', 'language_model.model.layers.0.mlp.gate_proj.qweight', 'language_model.model.layers.0.mlp.gate_proj.qzeros', 'language_model.model.layers.0.mlp.gate_proj.scales', 'language_model.model.layers.0.mlp.up_proj.qweight', 'language_model.model.layers.0.mlp.up_proj.qzeros', 'language_model.model.layers.0.mlp.up_proj.scales', 'language_model.model.layers.0.self_attn.k_proj.qweight', 'language_model.model.layers.0.self_attn.k_proj.qzeros', 'language_model.model.layers.0.self_attn.k_proj.scales', 'language_model.model.layers.0.self_attn.o_proj.qweight', 'language_model.model.layers.0.self_attn.o_proj.qzeros', 'language_model.model.layers.0.self_attn.o_proj.scales', 'language_model.model.layers.0.self_attn.q_proj.qweight', 'language_model.model.layers.0.self_attn.q_proj.qzeros', 'language_model.model.layers.0.self_attn.q_proj.scales', 'language_model.model.layers.0.self_attn.v_proj.qweight', 'language_model.model.layers.0.self_attn.v_proj.qzeros', 'language_model.model.layers.0.self_attn.v_proj.scales', 'language_model.model.layers.1.mlp.down_proj.qweight', 'language_model.model.layers.1.mlp.down_proj.qzeros', 
...省略好多
'language_model.model.layers.1.mlp.down_proj.scales', 'language_model.model.layers.1.mlp.gate_proj.qweight', 'language_model.model.layers.1.mlp.gate_proj.qzeros', 'language_model.model.layers.1.mlp.gate_proj.scales', 'language_model.model.layers.1.mlp.up_proj.qweight', 'language_model.model.layers.1.mlp.up_proj.qzeros', 'language_model.model.layers.1.mlp.up_proj.scales', 'language_model.model.layers.1.self_attn.k_proj.qweight', 'language_model.model.layers.1.self_attn.k_proj.qzeros', 'language_model.model.layers.1.self_attn.k_proj.scales', 'language_model.model.layers.1.self_attn.o_proj.qweight', 'language_model.model.layers.1.self_attn.o_proj.qzeros', 'language_model.model.layers.1.self_attn.o_proj.scales', 'language_model.model.layers.1.self_attn.q_proj.qweight', 'language_model.model.layers.1.self_attn.q_proj.qzeros', 'language_model.model.layers.1.self_attn.q_proj.scales', 'language_model.model.layers.1.self_attn.v_proj.qweight', 'language_model.model.layers.1.self_attn.v_proj.qzeros', 'language_model.model.layers.1.self_attn.v_proj.scales', 'language_model.model.layers.10.mlp.down_proj.qweight', 'language_model.model.layers.10.mlp.down_proj.qzeros', 'language_model.model.layers.10.mlp.down_proj.scales', 'language_model.model.layers.10.mlp.gate_proj.qweight', 'language_model.model.layers.10.mlp.gate_proj.qzeros', 'language_model.model.layers.10.mlp.gate_proj.scales', 'language_model.model.layers.10.mlp.up_proj.qweight', 'language_model.model.layers.10.mlp.up_proj.qzeros', 'language_model.model.layers.10.mlp.up_proj.scales', 'language_model.model.layers.10.self_attn.k_proj.qweight', 'language_model.model.layers.10.self_attn.k_proj.qzeros', 'language_model.model.layers.10.self_attn.k_proj.scales', 'language_model.model.layers.10.self_attn.o_proj.qweight', 'language_model.model.layers.10.self_attn.o_proj.qzeros', 'language_model.model.layers.10.self_attn.o_proj.scales', 'language_model.model.layers.10.self_attn.q_proj.qweight', 'language_model.model.layers.10.self_attn.q_proj.qzeros', 'language_model.model.layers.10.self_attn.q_proj.scales', 'language_model.model.layers.10.self_attn.v_proj.qweight', 'language_model.model.layers.10.self_attn.v_proj.qzeros', 'language_model.model.layers.10.self_attn.v_proj.scales', 'language_model.model.layers.11.mlp.down_proj.qweight', 'language_model.model.layers.11.mlp.down_proj.qzeros', 'language_model.model.layers.11.mlp.down_proj.scales', 'language_model.model.layers.11.mlp.gate_proj.qweight', 'language_model.model.layers.11.mlp.gate_proj.qzeros', 'language_model.model.layers.11.mlp.gate_proj.scales', 'language_model.model.layers.11.mlp.up_proj.qweight', 'language_model.model.layers.11.mlp.up_proj.qzeros', 'language_model.model.layers.11.mlp.up_proj.scales', 'language_model.model.layers.11.self_attn.k_proj.qweight', 'language_model.model.layers.11.self_attn.k_proj.qzeros', 'language_model.model.layers.11.self_attn.k_proj.scales', 'language_model.model.layers.11.self_attn.o_proj.qweight', 'language_model.model.layers.11.self_attn.o_proj.qzeros', 'language_model.model.layers.11.self_attn.o_proj.scales', 'language_model.model.layers.11.self_attn.q_proj.qweight', 'language_model.model.layers.11.self_attn.q_proj.qzeros', 
'language_model.model.layers.9.self_attn.k_proj.weight', 'language_model.model.layers.9.self_attn.o_proj.weight', 'language_model.model.layers.9.self_attn.q_proj.weight', 'language_model.model.layers.9.self_attn.v_proj.weight']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
sigle infer time :  18.87239646911621
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
AllentDan commented 3 months ago

Please wait for the next release of LMDeploy. Or, you may build lmdeploy from source. The model was supported in https://github.com/InternLM/lmdeploy/pull/2207 lately.

Jeremy-J-J commented 3 months ago

Please wait for the next release of LMDeploy. Or, you may build lmdeploy from source. The model was supported in #2207 lately.请等待 LMDeploy 的下一个版本。或者,您可以从源代码构建 lmdeploy。该模型 #2207 最近得到了支持。

tks, I will try

lvhan028 commented 3 months ago

v0.5.3 is released. May give it a try.

github-actions[bot] commented 2 months ago

This issue is marked as stale because it has been marked as invalid or awaiting response for 7 days without any further response. It will be closed in 5 days if the stale label is not removed or if there is no further response.

github-actions[bot] commented 2 months ago

This issue is closed because it has been stale for 5 days. Please open a new issue if you have similar issues or you have any new updates now.

Mrgengli commented 1 month ago

您好,我在使用0.5.3的lmdeploy对internvl2-4B进行awq量化的时候,最后保存模型的遇到了下面的问题,我想请问一下是怎么回事呢,麻烦大佬了。 image

Mrgengli commented 1 month ago

我在对 IntrenVL2-1B awq量化的时候遇到了相同的问题,请问是怎么回事呢? image

lvhan028 commented 1 month ago

@AllentDan

AllentDan commented 1 month ago

Downgrade transformers version please.