vllm-project / vllm

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

[Bug]: run quantized model error #7580

Open soulzzz opened 3 weeks ago

soulzzz commented 3 weeks ago

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.2 Libc version: glibc-2.35 Python version: 3.10.14 (main, May 6 2024, 19:42:50) [GCC 11.2.0] (64-bit runtime) Python platform: Linux-6.5.0-45-generic-x86_64-with-glibc2.35 Is CUDA available: True CUDA runtime version: 12.4.99 CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3090 Nvidia driver version: 555.58.02 cuDNN version: Could not collect HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True CPU: 架构: x86_64 CPU 运行模式: 32-bit, 64-bit Address sizes: 39 bits physical, 48 bits virtual 字节序: Little Endian CPU: 20 在线 CPU 列表: 0-19 厂商 ID: GenuineIntel 型号名称: 12th Gen Intel(R) Core(TM) i7-12700KF CPU 系列: 6 型号: 151 每个核的线程数: 2 每个座的核数: 12 座: 1 步进: 2 CPU 最大 MHz: 5000.0000 CPU 最小 MHz: 800.0000 BogoMIPS: 7219.20 标记: 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 est tm2 ssse3 sdbg fma cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq rdpid movdiri movdir64b fsrm md_clear serialize arch_lbr ibt flush_l1d arch_capabilities 虚拟化: VT-x L1d 缓存: 512 KiB (12 instances) L1i 缓存: 512 KiB (12 instances) L2 缓存: 12 MiB (9 instances) L3 缓存: 25 MiB (1 instance) NUMA 节点: 1 NUMA 节点0 CPU: 0-19 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 Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected Versions of relevant libraries: [pip3] numpy==1.26.4 [pip3] nvidia-nccl-cu12==2.20.5 [pip3] onnxruntime==1.16.0 [pip3] pytorch-lightning==2.4.0 [pip3] pytorch-wpe==0.0.1 [pip3] pyzmq==26.1.0 [pip3] sentence-transformers==3.0.1 [pip3] torch==2.4.0 [pip3] torch-complex==0.4.4 [pip3] torchaudio==2.4.0 [pip3] torchmetrics==1.4.1 [pip3] torchvision==0.19.0 [pip3] transformers==4.43.4 [pip3] transformers-stream-generator==0.0.5 [pip3] triton==3.0.0 [pip3] vector-quantize-pytorch==1.15.6 [conda] numpy 1.26.4 pypi_0 pypi [conda] nvidia-nccl-cu12 2.20.5 pypi_0 pypi [conda] pytorch-lightning 2.4.0 pypi_0 pypi [conda] pytorch-wpe 0.0.1 pypi_0 pypi [conda] pyzmq 26.1.0 pypi_0 pypi [conda] sentence-transformers 3.0.1 pypi_0 pypi [conda] torch 2.4.0 pypi_0 pypi [conda] torch-complex 0.4.4 pypi_0 pypi [conda] torchaudio 2.4.0 pypi_0 pypi [conda] torchmetrics 1.4.1 pypi_0 pypi [conda] torchvision 0.19.0 pypi_0 pypi [conda] transformers 4.43.4 pypi_0 pypi [conda] transformers-stream-generator 0.0.5 pypi_0 pypi [conda] triton 3.0.0 pypi_0 pypi [conda] vector-quantize-pytorch 1.15.6 pypi_0 pypi ROCM Version: Could not collect Neuron SDK Version: N/A vLLM Version: 0.5.4@4db5176d9758b720b05460c50ace3c01026eb158 vLLM Build Flags: CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled GPU Topology: GPU0 CPU Affinity NUMA Affinity GPU NUMA ID GPU0 X 0-19 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 ```

🐛 Describe the bug

my codes:

from vllm import LLM, SamplingParams

# Sample prompts.
prompts = [
    "Hello, my name is",
    "The president of the United States is",
    "The capital of France is",
    "The future of AI is",
]
# Create a sampling params object.
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)

# Create an LLM.
llm = LLM(model="/home/sky/.xinference/cache/internlm2_5-7b-chat-4bit",trust_remote_code=True,max_model_len=2048)
# Generate texts from the prompts. The output is a list of RequestOutput objects
# that contain the prompt, generated text, and other information.
outputs = llm.generate(prompts, sampling_params)
# Print the outputs.
for output in outputs:
    prompt = output.prompt
    generated_text = output.outputs[0].text
    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")

and i got this error:

python test.py
INFO 08-16 13:29:04 awq_marlin.py:89] The model is convertible to awq_marlin during runtime. Using awq_marlin kernel.
INFO 08-16 13:29:04 llm_engine.py:174] Initializing an LLM engine (v0.5.4) with config: model='/home/sky/.xinference/cache/internlm2_5-7b-chat-4bit', speculative_config=None, tokenizer='/home/sky/.xinference/cache/internlm2_5-7b-chat-4bit', skip_tokenizer_init=False, tokenizer_mode=auto, revision=None, rope_scaling=None, rope_theta=None, tokenizer_revision=None, trust_remote_code=True, dtype=torch.float16, max_seq_len=2048, download_dir=None, load_format=LoadFormat.AUTO, tensor_parallel_size=1, pipeline_parallel_size=1, disable_custom_all_reduce=False, quantization=awq_marlin, enforce_eager=False, kv_cache_dtype=auto, quantization_param_path=None, device_config=cuda, decoding_config=DecodingConfig(guided_decoding_backend='outlines'), observability_config=ObservabilityConfig(otlp_traces_endpoint=None), seed=0, served_model_name=/home/sky/.xinference/cache/internlm2_5-7b-chat-4bit, use_v2_block_manager=False, enable_prefix_caching=False)
WARNING 08-16 13:29:04 tokenizer.py:129] Using a slow tokenizer. This might cause a significant slowdown. Consider using a fast tokenizer instead.
INFO 08-16 13:29:04 model_runner.py:720] Starting to load model /home/sky/.xinference/cache/internlm2_5-7b-chat-4bit...
Loading pt checkpoint shards:   0% Completed | 0/3 [00:00<?, ?it/s]
/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/model_executor/model_loader/weight_utils.py:405: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  state = torch.load(bin_file, map_location="cpu")
[rank0]: Traceback (most recent call last):
[rank0]:   File "/home/sky/Second/test.py", line 14, in <module>
[rank0]:     llm = LLM(model="/home/sky/.xinference/cache/internlm2_5-7b-chat-4bit",trust_remote_code=True,max_model_len=2048)
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/entrypoints/llm.py", line 158, in __init__
[rank0]:     self.llm_engine = LLMEngine.from_engine_args(
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/engine/llm_engine.py", line 445, in from_engine_args
[rank0]:     engine = cls(
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/engine/llm_engine.py", line 249, in __init__
[rank0]:     self.model_executor = executor_class(
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/executor/executor_base.py", line 47, in __init__
[rank0]:     self._init_executor()
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/executor/gpu_executor.py", line 36, in _init_executor
[rank0]:     self.driver_worker.load_model()
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/worker/worker.py", line 139, in load_model
[rank0]:     self.model_runner.load_model()
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/worker/model_runner.py", line 722, in load_model
[rank0]:     self.model = get_model(model_config=self.model_config,
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/model_executor/model_loader/__init__.py", line 21, in get_model
[rank0]:     return loader.load_model(model_config=model_config,
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/model_executor/model_loader/loader.py", line 327, in load_model
[rank0]:     model.load_weights(
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/model_executor/models/internlm2.py", line 327, in load_weights
[rank0]:     loaded_weight = loaded_weight.view(-1, 2 + kv_groups,
[rank0]: RuntimeError: shape '[-1, 6, 128, 768]' is invalid for input of size 3145728
Loading pt checkpoint shards:   0% Completed | 0/3 [00:00<?, ?it/s]

the mode i used : internlm2_5-7b-chat-4bit

mgoin commented 3 weeks ago

Hi @soulzzz looking at the model you shared, it says it is in the "MLX format" which I guess is different from the traditional HF compatible AWQ format. Could you try a model that isn't in MLX? This one seems like a good candidate internlm/internlm2_5-7b-chat-4bit

soulzzz commented 3 weeks ago

ok i changed the model to ModelCloud/internlm-2.5-7b-chat-gptq-4bit and my code:

from vllm import LLM, SamplingParams

# Sample prompts.
prompts = [
    "Hello, my name is",
    "The president of the United States is",
    "The capital of France is",
    "The future of AI is",
]
# Create a sampling params object.
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)

# Create an LLM.
llm = LLM(model="/home/sky/.xinference/cache/internlm2_5-chat-gptq-7b",trust_remote_code=True,max_model_len=2048)
# Generate texts from the prompts. The output is a list of RequestOutput objects
# that contain the prompt, generated text, and other information.
outputs = llm.generate(prompts, sampling_params)
# Print the outputs.
for output in outputs:
    prompt = output.prompt
    generated_text = output.outputs[0].text
    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")

and the output error:

INFO 08-16 23:44:28 gptq_marlin.py:98] The model is convertible to gptq_marlin during runtime. Using gptq_marlin kernel.
INFO 08-16 23:44:28 llm_engine.py:174] Initializing an LLM engine (v0.5.4) with config: model='/home/sky/.xinference/cache/internlm2_5-chat-gptq-7b', speculative_config=None, tokenizer='/home/sky/.xinference/cache/internlm2_5-chat-gptq-7b', skip_tokenizer_init=False, tokenizer_mode=auto, revision=None, rope_scaling=None, rope_theta=None, tokenizer_revision=None, trust_remote_code=True, dtype=torch.bfloat16, max_seq_len=2048, download_dir=None, load_format=LoadFormat.AUTO, tensor_parallel_size=1, pipeline_parallel_size=1, disable_custom_all_reduce=False, quantization=gptq_marlin, enforce_eager=False, kv_cache_dtype=auto, quantization_param_path=None, device_config=cuda, decoding_config=DecodingConfig(guided_decoding_backend='outlines'), observability_config=ObservabilityConfig(otlp_traces_endpoint=None), seed=0, served_model_name=/home/sky/.xinference/cache/internlm2_5-chat-gptq-7b, use_v2_block_manager=False, enable_prefix_caching=False)
INFO 08-16 23:44:28 model_runner.py:720] Starting to load model /home/sky/.xinference/cache/internlm2_5-chat-gptq-7b...
Loading safetensors checkpoint shards:   0% Completed | 0/1 [00:00<?, ?it/s]
[rank0]: Traceback (most recent call last):
[rank0]:   File "/home/sky/Second/test.py", line 14, in <module>
[rank0]:     llm = LLM(model="/home/sky/.xinference/cache/internlm2_5-chat-gptq-7b",trust_remote_code=True,max_model_len=2048)
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/entrypoints/llm.py", line 158, in __init__
[rank0]:     self.llm_engine = LLMEngine.from_engine_args(
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/engine/llm_engine.py", line 445, in from_engine_args
[rank0]:     engine = cls(
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/engine/llm_engine.py", line 249, in __init__
[rank0]:     self.model_executor = executor_class(
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/executor/executor_base.py", line 47, in __init__
[rank0]:     self._init_executor()
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/executor/gpu_executor.py", line 36, in _init_executor
[rank0]:     self.driver_worker.load_model()
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/worker/worker.py", line 139, in load_model
[rank0]:     self.model_runner.load_model()
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/worker/model_runner.py", line 722, in load_model
[rank0]:     self.model = get_model(model_config=self.model_config,
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/model_executor/model_loader/__init__.py", line 21, in get_model
[rank0]:     return loader.load_model(model_config=model_config,
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/model_executor/model_loader/loader.py", line 327, in load_model
[rank0]:     model.load_weights(
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/model_executor/models/internlm2.py", line 327, in load_weights
[rank0]:     loaded_weight = loaded_weight.view(-1, 2 + kv_groups,
[rank0]: RuntimeError: shape '[-1, 6, 128, 4096]' is invalid for input of size 4096
Loading safetensors checkpoint shards:   0% Completed | 0/1 [00:00<?, ?it/s]

next model internlm/internlm2_5-7b-chat-4bit: my code:

from vllm import LLM, SamplingParams

# Sample prompts.
prompts = [
    "Hello, my name is",
    "The president of the United States is",
    "The capital of France is",
    "The future of AI is",
]
# Create a sampling params object.
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)

# Create an LLM.
llm = LLM(model="/home/sky/.xinference/cache/internlm2_5-7b-chat-4bit",trust_remote_code=True,max_model_len=2048)
# Generate texts from the prompts. The output is a list of RequestOutput objects
# that contain the prompt, generated text, and other information.
outputs = llm.generate(prompts, sampling_params)
# Print the outputs.
for output in outputs:
    prompt = output.prompt
    generated_text = output.outputs[0].text
    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")

the error output:

INFO 08-17 00:04:33 awq_marlin.py:89] The model is convertible to awq_marlin during runtime. Using awq_marlin kernel.
INFO 08-17 00:04:33 llm_engine.py:174] Initializing an LLM engine (v0.5.4) with config: model='/home/sky/.xinference/cache/internlm2_5-7b-chat-4bit', speculative_config=None, tokenizer='/home/sky/.xinference/cache/internlm2_5-7b-chat-4bit', skip_tokenizer_init=False, tokenizer_mode=auto, revision=None, rope_scaling=None, rope_theta=None, tokenizer_revision=None, trust_remote_code=True, dtype=torch.float16, max_seq_len=2048, download_dir=None, load_format=LoadFormat.AUTO, tensor_parallel_size=1, pipeline_parallel_size=1, disable_custom_all_reduce=False, quantization=awq_marlin, enforce_eager=False, kv_cache_dtype=auto, quantization_param_path=None, device_config=cuda, decoding_config=DecodingConfig(guided_decoding_backend='outlines'), observability_config=ObservabilityConfig(otlp_traces_endpoint=None), seed=0, served_model_name=/home/sky/.xinference/cache/internlm2_5-7b-chat-4bit, use_v2_block_manager=False, enable_prefix_caching=False)
WARNING 08-17 00:04:33 tokenizer.py:129] Using a slow tokenizer. This might cause a significant slowdown. Consider using a fast tokenizer instead.
INFO 08-17 00:04:33 model_runner.py:720] Starting to load model /home/sky/.xinference/cache/internlm2_5-7b-chat-4bit...
Loading pt checkpoint shards:   0% Completed | 0/3 [00:00<?, ?it/s]
/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/model_executor/model_loader/weight_utils.py:405: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  state = torch.load(bin_file, map_location="cpu")
[rank0]: Traceback (most recent call last):
[rank0]:   File "/home/sky/Second/test.py", line 14, in <module>
[rank0]:     llm = LLM(model="/home/sky/.xinference/cache/internlm2_5-7b-chat-4bit",trust_remote_code=True,max_model_len=2048)
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/entrypoints/llm.py", line 158, in __init__
[rank0]:     self.llm_engine = LLMEngine.from_engine_args(
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/engine/llm_engine.py", line 445, in from_engine_args
[rank0]:     engine = cls(
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/engine/llm_engine.py", line 249, in __init__
[rank0]:     self.model_executor = executor_class(
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/executor/executor_base.py", line 47, in __init__
[rank0]:     self._init_executor()
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/executor/gpu_executor.py", line 36, in _init_executor
[rank0]:     self.driver_worker.load_model()
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/worker/worker.py", line 139, in load_model
[rank0]:     self.model_runner.load_model()
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/worker/model_runner.py", line 722, in load_model
[rank0]:     self.model = get_model(model_config=self.model_config,
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/model_executor/model_loader/__init__.py", line 21, in get_model
[rank0]:     return loader.load_model(model_config=model_config,
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/model_executor/model_loader/loader.py", line 327, in load_model
[rank0]:     model.load_weights(
[rank0]:   File "/home/sky/anaconda3/envs/Xinference/lib/python3.10/site-packages/vllm/model_executor/models/internlm2.py", line 327, in load_weights
[rank0]:     loaded_weight = loaded_weight.view(-1, 2 + kv_groups,
[rank0]: RuntimeError: shape '[-1, 6, 128, 768]' is invalid for input of size 3145728
Loading pt checkpoint shards:   0% Completed | 0/3 [00:00<?, ?it/s]
Flynn-Zh commented 3 weeks ago

is there any plan to fix the bug?