vllm-project / vllm

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

[Bug]: VLLM doesn't support LoRa with config `modules_to_save` #9280

Open fahadh4ilyas opened 1 month ago

fahadh4ilyas commented 1 month ago

Your current environment

The output of `python collect_env.py` ```text 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: 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.5.0-41-generic-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 RTX A6000 Nvidia driver version: 535.183.01 cuDNN version: Probably one of the following: /usr/lib/x86_64-linux-gnu/libcudnn.so.8.9.7 /usr/lib/x86_64-linux-gnu/libcudnn.so.9.2.1 /usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.2.1 /usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.9.7 /usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.9.7 /usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.2.1 /usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.9.7 /usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.9.7 /usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.2.1 /usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.2.1 /usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.2.1 /usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.2.1 /usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.2.1 /usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.9.7 /usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.9.7 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: 46 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 48 On-line CPU(s) list: 0-47 Vendor ID: GenuineIntel Model name: Intel(R) Xeon(R) CPU E5-2697 v2 @ 2.70GHz CPU family: 6 Model: 62 Thread(s) per core: 2 Core(s) per socket: 12 Socket(s): 2 Stepping: 4 CPU max MHz: 3500,0000 CPU min MHz: 1200,0000 BogoMIPS: 5399.77 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 arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm cpuid_fault pti ssbd ibrs ibpb stibp tpr_shadow flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm ida arat pln pts vnmi md_clear flush_l1d Virtualization: VT-x L1d cache: 768 KiB (24 instances) L1i cache: 768 KiB (24 instances) L2 cache: 6 MiB (24 instances) L3 cache: 60 MiB (2 instances) NUMA node(s): 2 NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46 NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47 Vulnerability Gather data sampling: Not affected Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled Vulnerability L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable Vulnerability Mds: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Meltdown: Mitigation; PTI Vulnerability Mmio stale data: Unknown: No mitigations 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; Retpolines; IBPB conditional; IBRS_FW; STIBP conditional; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected Versions of relevant libraries: [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.45.2 [pip3] triton==3.0.0 [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.45.2 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 vLLM Build Flags: CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled GPU Topology: GPU0 NIC0 NIC1 CPU Affinity NUMA Affinity GPU NUMA ID GPU0 X PHB PHB 1,3,5,7,9,11 1 N/A NIC0 PHB X PIX NIC1 PHB PIX 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 ```

Model Input Dumps

No response

🐛 Describe the bug

I have a lora for Qwen with this adapter config:

{
  "alpha_pattern": {},
  "auto_mapping": {
    "base_model_class": "Qwen2ForCausalLM"
  },
  "base_model_name_or_path": "/models/Qwen2.5-3B-Instruct",
  "bias": "none",
  "fan_in_fan_out": false,
  "inference_mode": true,
  "init_lora_weights": true,
  "layer_replication": null,
  "layers_pattern": null,
  "layers_to_transform": null,
  "loftq_config": {},
  "lora_alpha": 32,
  "lora_dropout": 0.05,
  "megatron_config": null,
  "megatron_core": "megatron.core",
  "modules_to_save": [
    "embed_tokens",
    "lm_head"
  ],
  "peft_type": "LORA",
  "r": 32,
  "rank_pattern": {},
  "revision": null,
  "target_modules": [
    "gate_proj",
    "up_proj",
    "o_proj",
    "k_proj",
    "q_proj",
    "down_proj",
    "v_proj"
  ],
  "task_type": null,
  "use_dora": false,
  "use_rslora": false
}

There is clearly a parameter called modules_to_save which means that module is not frozen in peft when trained and saved inside adapter_model.safetensors as base_model.model.lm_head.weight and base_model.model.model.embed_tokens. But, vllm is not support it yet and I got this error when serving the model and lora

ERROR 10-11 16:03:09 engine.py:157] RuntimeError('Error in model execution: Loading lora /home/fahadh/models/Qwen2.5-3B-adapter_otas failed')
ERROR 10-11 16:03:09 engine.py:157] Traceback (most recent call last):                                                                                      ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/lora/worker_manager.py", line 94, in _load_adapter
ERROR 10-11 16:03:09 engine.py:157]     lora = self._lora_model_cls.from_local_checkpoint(
ERROR 10-11 16:03:09 engine.py:157]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/lora/models.py", line 218, in from_local_checkpoint
ERROR 10-11 16:03:09 engine.py:157]     module_name, _ = parse_fine_tuned_lora_name(lora_module)
ERROR 10-11 16:03:09 engine.py:157]                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/lora/utils.py", line 113, in parse_fine_tuned_lora_name
ERROR 10-11 16:03:09 engine.py:157]     raise ValueError(f"{name} is unsupported LoRA weight")
ERROR 10-11 16:03:09 engine.py:157] ValueError: base_model.model.lm_head.weight is unsupported LoRA weight
ERROR 10-11 16:03:09 engine.py:157]                                                                                                                         ERROR 10-11 16:03:09 engine.py:157] The above exception was the direct cause of the following exception:
ERROR 10-11 16:03:09 engine.py:157]                                                                                                                         ERROR 10-11 16:03:09 engine.py:157] Traceback (most recent call last):
ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/worker/model_runner_base.py", line 116, in _wrapper
ERROR 10-11 16:03:09 engine.py:157]     return func(*args, **kwargs)
ERROR 10-11 16:03:09 engine.py:157]            ^^^^^^^^^^^^^^^^^^^^^                                                                                        ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/worker/model_runner.py", line 1608, in execute_model
ERROR 10-11 16:03:09 engine.py:157]     self.set_active_loras(model_input.lora_requests,
ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/worker/model_runner.py", line 1304, in set_active_loras                                  ERROR 10-11 16:03:09 engine.py:157]     self.lora_manager.set_active_adapters(lora_requests, lora_mapping)                                                  ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/lora/worker_manager.py", line 136, in set_active_adapters                                ERROR 10-11 16:03:09 engine.py:157]     set_active_adapters_worker(requests, mapping, self._apply_adapters,                                                 ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/adapter_commons/utils.py", line 52, in set_active_adapters_worker
ERROR 10-11 16:03:09 engine.py:157]     apply_adapters_func(requests)
ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/lora/worker_manager.py", line 195, in _apply_adapters
ERROR 10-11 16:03:09 engine.py:157]     self.add_adapter(lora)
ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/lora/worker_manager.py", line 204, in add_adapter                                        ERROR 10-11 16:03:09 engine.py:157]     lora = self._load_adapter(lora_request)
ERROR 10-11 16:03:09 engine.py:157]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/lora/worker_manager.py", line 107, in _load_adapter
ERROR 10-11 16:03:09 engine.py:157]     raise RuntimeError(f"Loading lora {lora_path} failed") from e
ERROR 10-11 16:03:09 engine.py:157] RuntimeError: Loading lora /home/fahadh/models/Qwen2.5-3B-adapter_otas failed
ERROR 10-11 16:03:09 engine.py:157]
ERROR 10-11 16:03:09 engine.py:157] The above exception was the direct cause of the following exception:
ERROR 10-11 16:03:09 engine.py:157]
ERROR 10-11 16:03:09 engine.py:157] Traceback (most recent call last):
ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/engine/multiprocessing/engine.py", line 155, in start
ERROR 10-11 16:03:09 engine.py:157]     self.run_engine_loop()
ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/engine/multiprocessing/engine.py", line 218, in run_engine_loop
ERROR 10-11 16:03:09 engine.py:157]     request_outputs = self.engine_step()
ERROR 10-11 16:03:09 engine.py:157]                       ^^^^^^^^^^^^^^^^^^
ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/engine/multiprocessing/engine.py", line 236, in engine_step
ERROR 10-11 16:03:09 engine.py:157]     raise e
ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/engine/multiprocessing/engine.py", line 227, in engine_step
ERROR 10-11 16:03:09 engine.py:157]     return self.engine.step()
ERROR 10-11 16:03:09 engine.py:157]            ^^^^^^^^^^^^^^^^^^
ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/engine/llm_engine.py", line 1407, in step
ERROR 10-11 16:03:09 engine.py:157]     outputs = self.model_executor.execute_model(
ERROR 10-11 16:03:09 engine.py:157]               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/executor/gpu_executor.py", line 130, in execute_model
ERROR 10-11 16:03:09 engine.py:157]     output = self.driver_worker.execute_model(execute_model_req)
ERROR 10-11 16:03:09 engine.py:157]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/worker/worker_base.py", line 327, in execute_model
ERROR 10-11 16:03:09 engine.py:157]     output = self.model_runner.execute_model(
ERROR 10-11 16:03:09 engine.py:157]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/anaconda3/envs/vllm/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context                                                                                                                                                    ERROR 10-11 16:03:09 engine.py:157]     return func(*args, **kwargs)                                                                                        ERROR 10-11 16:03:09 engine.py:157]            ^^^^^^^^^^^^^^^^^^^^^                                                                                        ERROR 10-11 16:03:09 engine.py:157]   File "/home/fahadh/vllm/vllm/worker/model_runner_base.py", line 146, in _wrapper                                      ERROR 10-11 16:03:09 engine.py:157]     raise type(err)(f"Error in model execution: "                                                                       ERROR 10-11 16:03:09 engine.py:157] RuntimeError: Error in model execution: Loading lora /home/fahadh/models/Qwen2.5-3B-adapter_otas failed

Before submitting a new issue...

jeejeelee commented 1 month ago

If you set modules_to_save, why not directly merge the LoRA weights into the base model. Beacause you won't be able to utilize multi-LoRA.

fahadh4ilyas commented 1 month ago

If you set modules_to_save, why not directly merge the LoRA weights into the base model. Beacause you won't be able to utilize multi-LoRA.

what do you mean by won't be able to utilize multi-LoRA? Can we just load multiple lora in one serve and different user can call different lora at the same time? If you mean by multi-LoRA is one user use multiple lora in one call, I never use it.

jeejeelee commented 1 month ago

Can we just load multiple lora in one serve and different user can call different lora at the same time?

Yes, we can.

fahadh4ilyas commented 1 month ago

Then, I still need the modules_to_save parameter without merging the model because that parameter is specific to one task of my lora and that's why I don't want to merge it and instead load it besides other lora.

SWEENEYHE commented 1 month ago

I met the same question, there are some same issues: no more than 5 extra embeddings just merge it