Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Unsloth bitsandbytes quantized model cannot be run due to: KeyError: 'layers.42.mlp.down_proj.weight.absmax #10710

Open
1 task done
kerem-coemert opened this issue Nov 27, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@kerem-coemert
Copy link

Your current environment

The output of `python collect_env.py`
Collecting environment information...
PyTorch version: 2.5.1+cu124
Is debug build: False
CUDA used to build PyTorch: 12.4
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: version 3.29.2
Libc version: glibc-2.35

Python version: 3.11.7 (main, Dec 15 2023, 18:12:31) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-6.5.0-35-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: NVIDIA RTX A6000
GPU 1: NVIDIA RTX A6000

Nvidia driver version: 525.147.05
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
Address sizes:                      48 bits physical, 48 bits virtual
Byte Order:                         Little Endian
CPU(s):                             64
On-line CPU(s) list:                0-63
Vendor ID:                          AuthenticAMD
Model name:                         AMD Ryzen Threadripper PRO 5975WX 32-Cores
CPU family:                         25
Model:                              8
Thread(s) per core:                 2
Core(s) per socket:                 32
Socket(s):                          1
Stepping:                           2
Frequency boost:                    enabled
CPU max MHz:                        7006.6401
CPU min MHz:                        1800.0000
BogoMIPS:                           7187.24
Flags:                              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 invpcid_single hw_pstate ssbd mba ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin brs arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip pku ospke vaes vpclmulqdq rdpid overflow_recov succor smca fsrm
Virtualization:                     AMD-V
L1d cache:                          1 MiB (32 instances)
L1i cache:                          1 MiB (32 instances)
L2 cache:                           16 MiB (32 instances)
L3 cache:                           128 MiB (4 instances)
NUMA node(s):                       1
NUMA node0 CPU(s):                  0-63
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: Vulnerable: Safe RET, no microcode
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 always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Not affected

Versions of relevant libraries:
[pip3] mypy==1.8.0
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.26.4
[pip3] nvidia-cublas-cu12==12.4.5.8
[pip3] nvidia-cuda-cupti-cu12==12.4.127
[pip3] nvidia-cuda-nvrtc-cu12==12.4.127
[pip3] nvidia-cuda-runtime-cu12==12.4.127
[pip3] nvidia-cudnn-cu12==9.1.0.70
[pip3] nvidia-cufft-cu12==11.2.1.3
[pip3] nvidia-curand-cu12==10.3.5.147
[pip3] nvidia-cusolver-cu12==11.6.1.9
[pip3] nvidia-cusparse-cu12==12.3.1.170
[pip3] nvidia-ml-py==12.560.30
[pip3] nvidia-nccl-cu12==2.21.5
[pip3] nvidia-nvjitlink-cu12==12.4.127
[pip3] nvidia-nvtx-cu12==12.4.127
[pip3] pyzmq==26.2.0
[pip3] torch==2.5.1
[pip3] torchvision==0.20.1
[pip3] transformers==4.46.3
[pip3] transformers-stream-generator==0.0.5
[pip3] triton==3.1.0
[pip3] vllm-nccl-cu12==2.18.1.0.4.0
[conda] numpy                     1.26.4                   pypi_0    pypi
[conda] nvidia-cublas-cu12        12.4.5.8                 pypi_0    pypi
[conda] nvidia-cuda-cupti-cu12    12.4.127                 pypi_0    pypi
[conda] nvidia-cuda-nvrtc-cu12    12.4.127                 pypi_0    pypi
[conda] nvidia-cuda-runtime-cu12  12.4.127                 pypi_0    pypi
[conda] nvidia-cudnn-cu12         9.1.0.70                 pypi_0    pypi
[conda] nvidia-cufft-cu12         11.2.1.3                 pypi_0    pypi
[conda] nvidia-curand-cu12        10.3.5.147               pypi_0    pypi
[conda] nvidia-cusolver-cu12      11.6.1.9                 pypi_0    pypi
[conda] nvidia-cusparse-cu12      12.3.1.170               pypi_0    pypi
[conda] nvidia-ml-py              12.560.30                pypi_0    pypi
[conda] nvidia-nccl-cu12          2.21.5                   pypi_0    pypi
[conda] nvidia-nvjitlink-cu12     12.4.127                 pypi_0    pypi
[conda] nvidia-nvtx-cu12          12.4.127                 pypi_0    pypi
[conda] pyzmq                     26.2.0                   pypi_0    pypi
[conda] torch                     2.5.1                    pypi_0    pypi
[conda] torchvision               0.20.1                   pypi_0    pypi
[conda] transformers              4.46.3                   pypi_0    pypi
[conda] transformers-stream-generator 0.0.5                    pypi_0    pypi
[conda] triton                    3.1.0                    pypi_0    pypi
[conda] vllm-nccl-cu12            2.18.1.0.4.0             pypi_0    pypi
ROCM Version: Could not collect
Neuron SDK Version: N/A
vLLM Version: 0.6.4.post1
vLLM Build Flags:
CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled
GPU Topology:
GPU0    GPU1    CPU Affinity    NUMA Affinity
GPU0     X      SYS     0-63            N/A
GPU1    SYS      X      0-63            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/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/cv2/../../lib64:
CUDA_MODULE_LOADING=LAZY

Model Input Dumps

No response

🐛 Describe the bug

Hello,

I would like to run unsloth/Meta-Llama-3.1-70B-bnb-4bit using the AsyncLLMEngine in the following way:

return AsyncLLMEngineWithLoRA(
            async_llm_engine=AsyncLLMEngine.from_engine_args(
                AsyncEngineArgs(
                    model=base_model_config.model_name,
                    enable_lora=finetuned_model_config is not None,
                    max_loras=1,
                    device=device,
                    trust_remote_code=True,
                    # max_model_len=121296
                )
            ),
            lora_request=lora_request,
        )

Please note that lora_request is None and enable_lora is False in this case. I get:

ank0]: Traceback (most recent call last):
[rank0]:   File "<frozen runpy>", line 198, in _run_module_as_main
[rank0]:   File "<frozen runpy>", line 88, in _run_code
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/uvicorn/__main__.py", line 4, in <module>
[rank0]:     uvicorn.main()
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
[rank0]:     return self.main(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/click/core.py", line 1078, in main
[rank0]:     rv = self.invoke(ctx)
[rank0]:          ^^^^^^^^^^^^^^^^
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
[rank0]:     return ctx.invoke(self.callback, **ctx.params)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/click/core.py", line 783, in invoke
[rank0]:     return __callback(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/uvicorn/main.py", line 418, in main
[rank0]:     run(
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/uvicorn/main.py", line 587, in run
[rank0]:     server.run()
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/uvicorn/server.py", line 62, in run
[rank0]:     return asyncio.run(self.serve(sockets=sockets))
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/asyncio/runners.py", line 190, in run
[rank0]:     return runner.run(main)
[rank0]:            ^^^^^^^^^^^^^^^^
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/asyncio/runners.py", line 118, in run
[rank0]:     return self._loop.run_until_complete(task)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/uvicorn/server.py", line 69, in serve
[rank0]:     config.load()
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/uvicorn/config.py", line 458, in load
[rank0]:     self.loaded_app = import_from_string(self.app)
[rank0]:                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/uvicorn/importer.py", line 21, in import_from_string
[rank0]:     module = importlib.import_module(module_str)
[rank0]:              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/importlib/__init__.py", line 126, in import_module
[rank0]:     return _bootstrap._gcd_import(name[level:], package, level)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
[rank0]:   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
[rank0]:   File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
[rank0]:   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
[rank0]:   File "<frozen importlib._bootstrap_external>", line 940, in exec_module
[rank0]:   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
[rank0]:   File "/home/kerem/ai.webservice.local-llm-inference/src/main.py", line 2, in <module>
[rank0]:     from local_llm_inference.router import ROUTER
[rank0]:   File "/home/kerem/ai.webservice.local-llm-inference/src/local_llm_inference/router.py", line 92, in <module>
[rank0]:     LLM: InferenceModel | AsyncLLMEngineWithLoRA = init_llm(
[rank0]:                                                    ^^^^^^^^^
[rank0]:   File "/home/kerem/ai.webservice.local-llm-inference/src/local_llm_inference/infer.py", line 91, in init_llm
[rank0]:     async_llm_engine=AsyncLLMEngine.from_engine_args(
[rank0]:                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/vllm/engine/async_llm_engine.py", line 691, in from_engine_args
[rank0]:     engine = cls(
[rank0]:              ^^^^
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/vllm/engine/async_llm_engine.py", line 578, in __init__
[rank0]:     self.engine = self._engine_class(*args, **kwargs)
[rank0]:                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/vllm/engine/async_llm_engine.py", line 264, in __init__
[rank0]:     super().__init__(*args, **kwargs)
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/vllm/engine/llm_engine.py", line 347, in __init__
[rank0]:     self.model_executor = executor_class(vllm_config=vllm_config, )
[rank0]:                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/vllm/executor/executor_base.py", line 36, in __init__
[rank0]:     self._init_executor()
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/vllm/executor/gpu_executor.py", line 40, in _init_executor
[rank0]:     self.driver_worker.load_model()
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/vllm/worker/worker.py", line 152, in load_model
[rank0]:     self.model_runner.load_model()
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/vllm/worker/model_runner.py", line 1074, in load_model
[rank0]:     self.model = get_model(vllm_config=self.vllm_config)
[rank0]:                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/vllm/model_executor/model_loader/__init__.py", line 12, in get_model
[rank0]:     return loader.load_model(vllm_config=vllm_config)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/vllm/model_executor/model_loader/loader.py", line 334, in load_model
[rank0]:     model.load_weights(self._get_all_weights(model_config, model))
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/vllm/model_executor/models/llama.py", line 586, in load_weights
[rank0]:     loader.load_weights(
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/vllm/model_executor/models/utils.py", line 229, in load_weights
[rank0]:     autoloaded_weights = list(self._load_module("", self.module, weights))
[rank0]:                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/vllm/model_executor/models/utils.py", line 190, in _load_module
[rank0]:     yield from self._load_module(prefix,
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/vllm/model_executor/models/utils.py", line 175, in _load_module
[rank0]:     module_load_weights(weights)
[rank0]:   File "/home/kerem/miniconda3/envs/webservice-local-llm-inference/lib/python3.11/site-packages/vllm/model_executor/models/llama.py", line 407, in load_weights
[rank0]:     param = params_dict[name]
[rank0]:             ~~~~~~~~~~~^^^^^^
[rank0]: KeyError: 'layers.42.mlp.down_proj.weight.absmax'

although I was under the impression that with the newer vllm versions bnb quantized models are supported.

Could it be something like what I do in the following function, which requires manual patching to the weights in some cases for the PEFTModels:

def remove_base_layer_weights(finetuned_model_path: Path, logger: Logger) -> None:
    """
    This is necessary because when loading the LoRA weights for a PEFT-finetuned model,
    we get:
    lib/python3.11/site-packages/vllm/lora/utils.py", line 33, in parse_fine_tuned_lora_name
    assert parts[-2] == "lora_A" or parts[-2] == "lora_B"
                                    ^^^^^^^^^^^^^^^^^^^^^
    AssertionError

    See: https://github.com/vllm-project/vllm/issues/3404#issuecomment-2007431273
    """
    import safetensors.torch
    from torch import Tensor

    adapter_model_path: Path = finetuned_model_path.joinpath(
        "adapter_model.safetensors"
    )
    tensors: dict[str, Tensor] = safetensors.torch.load_file(
        filename=adapter_model_path
    )
    nonlora_keys = []
    for k in list(tensors.keys()):
        if "lora" not in k:
            nonlora_keys.append(k)
    logger.info(
        f"Deleting {nonlora_keys=}. See: https://github.com/vllm-project/vllm/issues/3404#issuecomment-2007431273"
    )
    for k in nonlora_keys:
        del tensors[k]
    safetensors.torch.save_file(tensors, adapter_model_path)

Thanks in advance!

Before submitting a new issue...

  • Make sure you already searched for relevant issues, and asked the chatbot living at the bottom right corner of the documentation page, which can answer lots of frequently asked questions.
@kerem-coemert kerem-coemert added the bug Something isn't working label Nov 27, 2024
@kerem-coemert kerem-coemert changed the title [Bug]: Unsloth bitsna [Bug]: Unsloth bitsandbytes quantized model cannot be run due to: KeyError: 'layers.42.mlp.down_proj.weight.absmax Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant