unslothai / unsloth

Finetune Llama 3.2, Mistral, Phi, Qwen 2.5 & Gemma LLMs 2-5x faster with 80% less memory
https://unsloth.ai
Apache License 2.0
18.06k stars 1.26k forks source link

cannot load some models via vllm #1268

Open yananchen1989 opened 4 days ago

yananchen1989 commented 4 days ago

here is the summary: unsloth/mistral-7b-v0.3-bnb-4bit with error : KeyError: 'layers.0.mlp.down_proj.weight' unsloth/Qwen2.5-7B-Instruct-bnb-4bit with error: KeyError: 'layers.0.mlp.down_proj.weight' unsloth/Llama-3.2-1B-Instruct-bnb-4bit with error: KeyError: 'layers.0.mlp.down_proj.weight'

here is the code:

from vllm import LLM, SamplingParams

  llm = LLM(model= args.llm_name, 
              dtype='float16', 
              #max_model_len = max_len, 
              tensor_parallel_size= torch.cuda.device_count(),
              gpu_memory_utilization= args.gpu_memory_utilization, 
              #seed=None,
              trust_remote_code=True,
              quantization=None, 
              load_format="auto", 
              enforce_eager=True, 
              enable_lora=True if args.sft_path else False,
              tokenizer_mode= "mistral" if args.llm_name.startswith('mistralai') else 'auto'
          )  

here is the environment info:

WARNING 11-08 15:57:45 _custom_ops.py:19] Failed to import from vllm._C with ModuleNotFoundError("No module named 'vllm._C'")
/home/yanan/vllm/vllm/connections.py:8: RuntimeWarning: Failed to read commit hash:
No module named 'vllm._version'
  from vllm.version import __version__ as VLLM_VERSION
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.5 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.35

Python version: 3.11.10 (main, Oct  3 2024, 07:29:13) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-6.8.0-48-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 11.5.119
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: Quadro RTX 4000
GPU 1: Quadro RTX 4000
GPU 2: Quadro RTX 4000
GPU 3: Quadro RTX 4000

Nvidia driver version: 535.183.01
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:                        46 bits physical, 48 bits virtual
字节序:                              Little Endian
CPU:                                  32
在线 CPU 列表:                       0-31
厂商 ID:                             GenuineIntel
型号名称:                            Intel(R) Xeon(R) Silver 4208 CPU @ 2.10GHz
CPU 系列:                            6
型号:                                85
每个核的线程数:                      2
每个座的核数:                        8
座:                                  2
步进:                                7
CPU 最大 MHz:                        3200.0000
CPU 最小 MHz:                        800.0000
BogoMIPS:                            4200.00
标记:                                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 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 cdp_l3 intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req vnmi pku ospke avx512_vnni md_clear flush_l1d arch_capabilities
虚拟化:                              VT-x
L1d 缓存:                            512 KiB (16 instances)
L1i 缓存:                            512 KiB (16 instances)
L2 缓存:                             16 MiB (16 instances)
L3 缓存:                             22 MiB (2 instances)
NUMA 节点:                           2
NUMA 节点0 CPU:                      0-7,16-23
NUMA 节点1 CPU:                      8-15,24-31
Vulnerability Gather data sampling:   Mitigation; Microcode
Vulnerability Itlb multihit:          KVM: Mitigation: VMX disabled
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Mitigation; Enhanced IBRS
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 SW loop, KVM SW loop
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Mitigation; TSX disabled

Versions of relevant libraries:
[pip3] flashinfer==0.1.6+cu121torch2.4
[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.77
[pip3] nvidia-nvtx-cu12==12.1.105
[pip3] pyzmq==26.2.0
[pip3] torch==2.4.0
[pip3] torchvision==0.19.0
[pip3] transformers==4.46.1
[pip3] triton==3.0.0
[conda] flashinfer                0.1.6+cu121torch2.4          pypi_0    pypi
[conda] numpy                     1.26.4                   pypi_0    pypi
[conda] nvidia-cublas-cu12        12.1.3.1                 pypi_0    pypi
[conda] nvidia-cuda-cupti-cu12    12.1.105                 pypi_0    pypi
[conda] nvidia-cuda-nvrtc-cu12    12.1.105                 pypi_0    pypi
[conda] nvidia-cuda-runtime-cu12  12.1.105                 pypi_0    pypi
[conda] nvidia-cudnn-cu12         9.1.0.70                 pypi_0    pypi
[conda] nvidia-cufft-cu12         11.0.2.54                pypi_0    pypi
[conda] nvidia-curand-cu12        10.3.2.106               pypi_0    pypi
[conda] nvidia-cusolver-cu12      11.4.5.107               pypi_0    pypi
[conda] nvidia-cusparse-cu12      12.1.0.106               pypi_0    pypi
[conda] nvidia-ml-py              12.560.30                pypi_0    pypi
[conda] nvidia-nccl-cu12          2.20.5                   pypi_0    pypi
[conda] nvidia-nvjitlink-cu12     12.6.77                  pypi_0    pypi
[conda] nvidia-nvtx-cu12          12.1.105                 pypi_0    pypi
[conda] pyzmq                     26.2.0                   pypi_0    pypi
[conda] torch                     2.4.0                    pypi_0    pypi
[conda] torchvision               0.19.0                   pypi_0    pypi
[conda] transformers              4.46.1                   pypi_0    pypi
[conda] triton                    3.0.0                    pypi_0    pypi
ROCM Version: Could not collect
Neuron SDK Version: N/A
vLLM Version: N/A (dev)
vLLM Build Flags:
CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled
GPU Topology:
GPU0    GPU1    GPU2    GPU3    CPU Affinity    NUMA Affinity   GPU NUMA ID
GPU0     X      NODE    SYS     SYS     0-7,16-23       0               N/A
GPU1    NODE     X      SYS     SYS     0-7,16-23       0               N/A
GPU2    SYS     SYS      X      NODE    8-15,24-31      1               N/A
GPU3    SYS     SYS     NODE     X      8-15,24-31      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

LD_LIBRARY_PATH=/home/yanan/anaconda3/envs/vllm/lib/python3.11/site-packages/cv2/../../lib64:
CUDA_MODULE_LOADING=LAZY
yananchen1989 commented 4 days ago

models such as unsloth/Qwen2.5-7B-Instruct which does not have -bnb-4bit seems works fine. may I know the reason ?

yananchen1989 commented 4 days ago

i do see vllm support bitsandbytes for unsloth/tinyllama-bnb-4bit as shown here https://docs.vllm.ai/en/stable/quantization/bnb.html

JJEccles commented 2 days ago

I have also encountered this issue. As I'm trying to run the Lora adapter plus base model (unsloth/Qwen2.5-7B-bnb-4bit) but it seems to not work. I was led to believe vLLM was the way to go for multi Lora on small models.

yananchen1989 commented 2 days ago

should I always set quantization="bitsandbytes", load_format="bitsandbytes" when loading bnb-4bit models ? as suggested in https://docs.vllm.ai/en/stable/quantization/bnb.html ?

danielhanchen commented 2 days ago

Yes for bitsandbytes models, use

from vllm import LLM
import torch
# unsloth/tinyllama-bnb-4bit is a pre-quantized checkpoint.
model_id = "unsloth/tinyllama-bnb-4bit"
llm = LLM(model=model_id, dtype=torch.bfloat16, \
quantization="bitsandbytes", load_format="bitsandbytes")
yananchen1989 commented 1 day ago

@danielhanchen hi , i have to reopen this issue. llms such as unsloth/Phi-3.5-mini-instruct-bnb-4bit unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit unsloth/Llama-3.2-3B-Instruct-bnb-4bit works fine.

but unsloth/Qwen2.5-7B-Instruct-bnb-4bit does not work with the same code. the error message: ''' [rank0]: AttributeError: Model Qwen2ForCausalLM does not support BitsAndBytes quantization yet. '''

could you take a look at it ? thank.s

yananchen1989 commented 1 day ago
    from vllm import LLM, SamplingParams
    from vllm.lora.request import LoRARequest
    llm = LLM(model= args.llm_name, 
                dtype='float16', 
                max_model_len = args.sft_max_len if args.sft_max_len else None, 
                tensor_parallel_size= torch.cuda.device_count(),
                #pipeline_parallel_size = torch.cuda.device_count(),
                gpu_memory_utilization= args.gpu_memory_utilization, 
                #seed=None,
                trust_remote_code=True,
                quantization= "bitsandbytes" if args.quant or 'bnb-4bit' in args.llm_name else None, 
                load_format= "bitsandbytes" if args.quant or 'bnb-4bit' in args.llm_name else "auto", 
                enforce_eager=True, 
                enable_lora=True if args.sft_path else False,
                tokenizer_mode= "mistral" if args.llm_name.startswith('mistralai') else 'auto',
                cpu_offload_gb = 0 if args.quant or 'bnb-4bit' in args.llm_name else 16, 
                swap_space=16
            )  
JJEccles commented 1 day ago

Yes I always get this issue also on the Qwen models. It's also present on the unsloth/Qwen2.5-3B-bnb-4bit version as well as the 7B.

Can confirm the error across all the Qwen models when trying to run inference on vllm: "AttributeError: Model Qwen2ForCausalLM does not support BitsAndBytes quantization yet."

I'm assuming since I'm working from a fresh install of: "pip install vllm"

That I'm using the same version. Currently I've had to switch to the the "unsloth/Llama-3.2-3B-bnb-4bit" model as I couldn't find a fix. If anyone finds a way to get it to work please let me know! I'd love to be able to switch back to the fine tuned LORA on top of the 4bit Qwen 2.5 base model.

yananchen1989 commented 1 day ago

@JJEccles maybe you can use original model Qwen/Qwen2.5-7B-Instruct and set quantization='bitsandbytes', which should work fine, and perhaps it is equal to using unsloth/Qwen2.5-7B-Instruct

@danielhanchen correct me if i am wrong.

JJEccles commented 1 day ago

I will look into it, Thanks!