ipex-llm icon indicating copy to clipboard operation
ipex-llm copied to clipboard

Qwen1.5-GPTQ-Int4 inference error

Open foricee opened this issue 2 years ago • 4 comments

Model: https://huggingface.co/Qwen/Qwen1.5-14B-Chat-GPTQ-Int4

cd ipex-llm/python/llm/example/CPU/HF-Transformers-AutoModels/Advanced-Quantizations/GPTQ
python ./generate.py --repo-id-or-model-path /root/project/model_files/Qwen1.5-14B-Chat-GPTQ-Int4 --prompt 'hi' --n-predict 40
2024-06-24 15:55:40,675 - INFO - PyTorch version 2.3.0+cpu available.
2024-06-24 15:55:41,126 - WARNING - CUDA extension not installed.
2024-06-24 15:55:41,126 - WARNING - CUDA extension not installed.
/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/transformers/quantizers/auto.py:167: UserWarning: You passed `quantization_config` or equivalent parameters to `from_pretrained` but the model you're loading already has a `quantization_config` attribute. The `quantization_config` from the model will be used.However, loading attributes (e.g. ['use_cuda_fp16', 'use_exllama', 'max_input_length', 'exllama_config', 'disable_exllama']) will be overwritten with the one you passed to `from_pretrained`. The rest will be ignored.
  warnings.warn(warning_msg)
/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/transformers/modeling_utils.py:4481: FutureWarning: `_is_quantized_training_enabled` is going to be deprecated in transformers 4.39.0. Please use `model.hf_quantizer.is_trainable` instead
  warnings.warn(
Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00,  4.22it/s]
2024-06-24 15:55:42,421 - INFO - Converting the current model to asym_int4 format......
Traceback (most recent call last):
  File "/root/project/ipex-llm/python/llm/example/CPU/HF-Transformers-AutoModels/Advanced-Quantizations/GPTQ/./generate.py", line 47, in <module>
    model = AutoModelForCausalLM.from_pretrained(model_path,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/unittest/mock.py", line 1378, in patched
    return func(*newargs, **newkeywargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/ipex_llm/transformers/model.py", line 351, in from_pretrained
    model = cls.load_convert(q_k, optimize_model, *args, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/ipex_llm/transformers/model.py", line 503, in load_convert
    model = ggml_convert_low_bit(model, qtype, optimize_model,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/ipex_llm/transformers/convert.py", line 788, in ggml_convert_low_bit
    model = _optimize_pre(model)
            ^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/ipex_llm/transformers/convert.py", line 737, in _optimize_pre
    model.apply(merge_qkv)
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/torch/nn/modules/module.py", line 894, in apply
    module.apply(fn)
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/torch/nn/modules/module.py", line 894, in apply
    module.apply(fn)
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/torch/nn/modules/module.py", line 894, in apply
    module.apply(fn)
  [Previous line repeated 1 more time]
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/torch/nn/modules/module.py", line 895, in apply
    fn(self)
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/ipex_llm/transformers/models/qwen2.py", line 271, in merge_qkv
    module.q_proj.weight.data,
    ^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1709, in __getattr__
    raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
AttributeError: 'QuantLinear' object has no attribute 'weight'. Did you mean: 'qweight'?

modify code, comment load_in_4bit=True

    model = AutoModelForCausalLM.from_pretrained(model_path,
                                                 # load_in_4bit=True,
                                                 torch_dtype="auto",
                                                 trust_remote_code=True,)

error changed

2024-06-24 16:25:40,745 - INFO - PyTorch version 2.3.0+cpu available.
2024-06-24 16:25:41,202 - WARNING - CUDA extension not installed.
2024-06-24 16:25:41,203 - WARNING - CUDA extension not installed.
`low_cpu_mem_usage` was None, now set to True since model is quantized.
/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/transformers/modeling_utils.py:4481: FutureWarning: `_is_quantized_training_enabled` is going to be deprecated in transformers 4.39.0. Please use `model.hf_quantizer.is_trainable` instead
  warnings.warn(
Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 11.02it/s]
Traceback (most recent call last):
  File "/root/project/ipex-llm/python/llm/example/CPU/HF-Transformers-AutoModels/Advanced-Quantizations/GPTQ/./generate.py", line 47, in <module>
    model = AutoModelForCausalLM.from_pretrained(model_path,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/unittest/mock.py", line 1378, in patched
    return func(*newargs, **newkeywargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/ipex_llm/transformers/model.py", line 386, in from_pretrained
    model = cls.HF_Model.from_pretrained(*args, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/transformers/models/auto/auto_factory.py", line 563, in from_pretrained
    return model_class.from_pretrained(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/transformers/modeling_utils.py", line 3823, in from_pretrained
    hf_quantizer.postprocess_model(model)
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/transformers/quantizers/base.py", line 195, in postprocess_model
    return self._process_model_after_weight_loading(model, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/transformers/quantizers/quantizer_gptq.py", line 80, in _process_model_after_weight_loading
    model = self.optimum_quantizer.post_init_model(model)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/ipex-vllm/lib/python3.11/site-packages/optimum/gptq/quantizer.py", line 545, in post_init_model
    raise ValueError(
ValueError: Found modules on cpu/disk. Using Exllama or Exllamav2 backend requires all the modules to be on GPU.You can deactivate exllama backend by setting `disable_exllama=True` in the quantization config object

foricee avatar Jun 24 '24 08:06 foricee

Will try to reproduce the issue and get back to you.

liu-shaojun avatar Jun 25 '24 02:06 liu-shaojun

We've reproduced the issue and are currently working on a fix.

liu-shaojun avatar Jun 26 '24 02:06 liu-shaojun

The issue has been resolved. Please try using the latest version of ipex-llm[all].

liu-shaojun avatar Jun 26 '24 15:06 liu-shaojun

Test ok! Thanks!

foricee avatar Jun 27 '24 02:06 foricee