vllm-project / vllm

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

[Bug]: Lora refuses to load from disk without extremely weird manipulations with file paths #9063

Open Ouna-the-Dataweaver opened 1 month ago

Ouna-the-Dataweaver 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 20.04.3 LTS (x86_64) GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 Clang version: Could not collect CMake version: Could not collect Libc version: glibc-2.31 Python version: 3.12.6 | packaged by Anaconda, Inc. | (main, Oct 3 2024, 07:30:27) [GCC 11.2.0] (64-bit runtime) Python platform: Linux-5.4.0-84-generic-x86_64-with-glibc2.31 Is CUDA available: True CUDA runtime version: 12.1.66 CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4060 Ti GPU 1: NVIDIA GeForce RTX 4060 Ti Nvidia driver version: 560.28.03 cuDNN version: Could not collect 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 Byte Order: Little Endian Address sizes: 46 bits physical, 48 bits virtual CPU(s): 48 On-line CPU(s) list: 0-47 Thread(s) per core: 2 Core(s) per socket: 12 Socket(s): 2 NUMA node(s): 2 Vendor ID: GenuineIntel CPU family: 6 Model: 79 Model name: Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz Stepping: 1 CPU MHz: 1226.794 CPU max MHz: 2900.0000 CPU min MHz: 1200.0000 BogoMIPS: 4400.11 Virtualization: VT-x L1d cache: 768 KiB L1i cache: 768 KiB L2 cache: 6 MiB L3 cache: 60 MiB NUMA node0 CPU(s): 0-11,24-35 NUMA node1 CPU(s): 12-23,36-47 Vulnerability Itlb multihit: KVM: Mitigation: Split huge pages Vulnerability L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable Vulnerability Mds: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Meltdown: Mitigation; PTI Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Full generic retpoline, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Mitigation; Clear CPU buffers; SMT vulnerable 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 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 invpcid_single pti intel_ppin ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap intel_pt xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts md_clear flush_l1d 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.1 [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.1 pypi_0 pypi [conda] triton 3.0.0 pypi_0 pypi ROCM Version: Could not collect Neuron SDK Version: N/A vLLM Version: 0.6.1.dev238+ge2c6e0a82 vLLM Build Flags: CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled GPU Topology: GPU0 GPU1 NIC0 CPU Affinity NUMA Affinity GPU NUMA ID GPU0 X SYS SYS 0-11,24-35 0 N/A GPU1 SYS X PHB 12-23,36-47 1 N/A NIC0 SYS PHB 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 ```

Model Input Dumps

No response

🐛 Describe the bug

So, for me to load lora from disk you need to load it 4 times for some reason. This is clean env and vLLM installed from source. First I tested lora with fp8 and found that bug, but later I reproduced it with other model I can load without quantization. And in general it looks like loading issue first. I did all testing in jupyter notebook, but I can confirm that it works the same way in usual python, I managed to do the same loading process with 4 lora requests inside for loop with try/except and on 4th try it loaded correctly.

Reproducing steps. First we load and prepare prompt/parameters, verify that model loaded correctly.

from pathlib import Path
from vllm import LLM, SamplingParams
from vllm.lora.request import LoRARequest
from transformers import AutoTokenizer

llm_path = Path("/media/data/username/models/vicuna-7b-v1.5")
llm = LLM(model=llm_path, max_model_len=500, enable_lora=True, tokenizer_mode='slow')
tokenizer = AutoTokenizer.from_pretrained(llm_path, use_fast=False)
terminators = [tokenizer.eos_token_id]
sampling_params = SamplingParams(
            min_tokens=5,
            max_tokens=30,
            top_p=1.0, # 0.9
            repetition_penalty=1.0,
            length_penalty=1.0,
            temperature=0, # 1.0
            stop_token_ids=terminators
        )
prompt = "USER: 2+2 is ?\nASSISTANT:"
outputs = llm.generate(
            [prompt],
              sampling_params=sampling_params
        )
outputs[0].outputs[0].text
# ' 2+2 is 4.'

Lora load 1: giving path to directory. (You can repeat this step as many times, error stays the same)

lora_path = Path("/media/data/username/models/loras/v0_vicuna/")
lora_request_1 = LoRARequest(lora_name = "Test_1", lora_int_id = 1, lora_path = lora_path)
outputs = llm.generate(
            [prompt],
              sampling_params=sampling_params,
              lora_request=lora_request_1
        )
outputs[0].outputs[0].text
# ValueError: Unrecognized model in /media/data/username/models/loras/v0_vicuna. Should have a `model_type` key in its config.json, or con

Lora load 2: giving path to json config. Model now tries to load adapter_config as if I'm passing path to directory?

lora_path = Path("/media/data/username/models/loras/v0_vicuna/adapter_config.json")
lora_request_1 = LoRARequest(lora_name = "Test_1", lora_int_id = 1, lora_path = lora_path)
outputs = llm.generate(
            [prompt],
              sampling_params=sampling_params,
              lora_request=lora_request_1
        )
outputs[0].outputs[0].text
# NotADirectoryError: [Errno 20] Not a directory:
# '/media/data/username/models/loras/v0_vicuna/adapter_config.json/adapter_config.json'

Lora load 3: giving path to directory, again. Getting some weird assertion error.

lora_path = Path("/media/data/username/models/loras/v0_vicuna/")
lora_request_1 = LoRARequest(lora_name = "Test_1", lora_int_id = 1, lora_path = lora_path)
outputs = llm.generate(
            [prompt],
              sampling_params=sampling_params,
              lora_request=lora_request_1
        )
outputs[0].outputs[0].text
# -> 1034 assert len(running_scheduled.prefill_seq_groups) == 0
# AssertionError: 

Lora load 4: giving path to directory, yes, again. Now it works.

lora_path = Path("/media/data/username/models/loras/v0_vicuna/")
lora_request_1 = LoRARequest(lora_name = "Test_1", lora_int_id = 1, lora_path = lora_path)
outputs = llm.generate(
            [prompt],
              sampling_params=sampling_params,
              lora_request=lora_request_1
        )
outputs[0].outputs[0].text
' 2+2 is 4.'

As you can see, steps 1, 3, and 4 are exactly the same. I don't know why it refuses to load before you jiggle paths like that. Want to repeat, I can confirm that on load 4 it loads lora and it works, I tested it with audio LLM with passing embeddings before and with lora it worked correctly - it processed audio embeddings which base llm was not trained for. Well, almost, there were weird artifacts with tokenizer but I'm too tired to debug that now.

Also, wanna mention that it's extremely weird that vLLM do not allow to load lora and change parameters from within python, so if I want to change alpha and load lora with different alpha I have to make a directory on disc for each set of parameters despite them having same weights.

Before submitting a new issue...

vidhyat98 commented 1 month ago

Facing the same issue with llama 3.1 model adapters