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

[side-effect] bring back quantization of qwen2-vl, glm4v and etc. #2954

Merged
merged 3 commits into from
Dec 26, 2024

Conversation

lvhan028
Copy link
Collaborator

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily receiving feedbacks. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Please describe the motivation of this PR and the goal you want to achieve through this PR.

Modification

Please briefly describe what modification is made in this PR.

BC-breaking (Optional)

Does the modification introduce changes that break the backward-compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness.
  3. If the modification has a dependency on downstream projects of a newer version, this PR should be tested with all supported versions of downstream projects.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@lvhan028 lvhan028 requested review from irexyc and AllentDan December 25, 2024 11:17
@lvhan028
Copy link
Collaborator Author

cc @zhulinJulia24

@zhulinJulia24
Copy link
Collaborator

@lvhan028 quantization of qwen2-vl works.

but glm4v failed

reproduce cmd is:
lmdeploy lite auto_awq /nvme/qa_test_models/Qwen/Qwen2-VL-7B-Instruct --batch-size 32

2024-12-26 10:38:50,406 - lmdeploy - INFO - builder.py:68 - matching vision model: Qwen2VLModel
`Qwen2VLRotaryEmbedding` can now be fully parameterized by passing the model config through the `config` argument. All other arguments will be removed in v4.46
Loading checkpoint shards: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:03<00:00,  1.53it/s]
Move visual to GPU.
Move model.embed_tokens to GPU.
Move model.layers.0 to CPU.
Move model.layers.1 to CPU.
Move model.layers.2 to CPU.
Move model.layers.3 to CPU.
Move model.layers.4 to CPU.
Move model.layers.5 to CPU.
Move model.layers.6 to CPU.
Move model.layers.7 to CPU.
Move model.layers.8 to CPU.
Move model.layers.9 to CPU.
Move model.layers.10 to CPU.
Move model.layers.11 to CPU.
Move model.layers.12 to CPU.
Move model.layers.13 to CPU.
Move model.layers.14 to CPU.
Move model.layers.15 to CPU.
Move model.layers.16 to CPU.
Move model.layers.17 to CPU.
Move model.layers.18 to CPU.
Move model.layers.19 to CPU.
Move model.layers.20 to CPU.
Move model.layers.21 to CPU.
Move model.layers.22 to CPU.
Move model.layers.23 to CPU.
Move model.layers.24 to CPU.
Move model.layers.25 to CPU.
Move model.layers.26 to CPU.
Move model.layers.27 to CPU.
Move model.norm to GPU.
Move model.rotary_emb to GPU.
Move lm_head to CPU.
Loading calibrate dataset ...
Token indices sequence length is longer than the specified maximum sequence length for this model (1104485 > 32768). Running this sequence through the model will result in indexing errors
model.layers.0, samples: 4, max gpu memory: 33.77 GB
model.layers.1, samples: 4, max gpu memory: 37.27 GB
model.layers.2, samples: 4, max gpu memory: 37.27 GB
model.layers.3, samples: 4, max gpu memory: 37.27 GB
model.layers.4, samples: 4, max gpu memory: 37.27 GB
model.layers.5, samples: 4, max gpu memory: 37.27 GB
model.layers.6, samples: 4, max gpu memory: 37.27 GB
model.layers.7, samples: 4, max gpu memory: 37.27 GB
model.layers.8, samples: 4, max gpu memory: 37.27 GB
model.layers.9, samples: 4, max gpu memory: 37.27 GB
model.layers.10, samples: 4, max gpu memory: 37.27 GB
model.layers.11, samples: 4, max gpu memory: 37.27 GB
model.layers.12, samples: 4, max gpu memory: 37.27 GB
model.layers.13, samples: 4, max gpu memory: 37.27 GB
model.layers.14, samples: 4, max gpu memory: 37.27 GB
model.layers.15, samples: 4, max gpu memory: 37.27 GB
model.layers.16, samples: 4, max gpu memory: 37.27 GB
model.layers.17, samples: 4, max gpu memory: 37.27 GB
model.layers.18, samples: 4, max gpu memory: 37.27 GB
model.layers.19, samples: 4, max gpu memory: 37.27 GB
model.layers.20, samples: 4, max gpu memory: 37.27 GB
model.layers.21, samples: 4, max gpu memory: 37.27 GB
model.layers.22, samples: 4, max gpu memory: 37.27 GB
model.layers.23, samples: 4, max gpu memory: 37.27 GB
model.layers.24, samples: 4, max gpu memory: 37.27 GB
model.layers.25, samples: 4, max gpu memory: 37.27 GB
model.layers.26, samples: 4, max gpu memory: 37.27 GB
model.layers.27, samples: 4, max gpu memory: 37.27 GB
model.layers.0 smooth weight done.
model.layers.1 smooth weight done.
model.layers.2 smooth weight done.
model.layers.3 smooth weight done.
model.layers.4 smooth weight done.
model.layers.5 smooth weight done.
model.layers.6 smooth weight done.
model.layers.7 smooth weight done.
model.layers.8 smooth weight done.
model.layers.9 smooth weight done.
model.layers.10 smooth weight done.
model.layers.11 smooth weight done.
model.layers.12 smooth weight done.
model.layers.13 smooth weight done.
model.layers.14 smooth weight done.
model.layers.15 smooth weight done.
model.layers.16 smooth weight done.
model.layers.17 smooth weight done.
model.layers.18 smooth weight done.
model.layers.19 smooth weight done.
model.layers.20 smooth weight done.
model.layers.21 smooth weight done.
model.layers.22 smooth weight done.
model.layers.23 smooth weight done.
model.layers.24 smooth weight done.
model.layers.25 smooth weight done.
model.layers.26 smooth weight done.
model.layers.27 smooth weight done.
model.layers.0.self_attn.q_proj weight packed.
model.layers.0.self_attn.k_proj weight packed.
model.layers.0.self_attn.v_proj weight packed.
model.layers.0.self_attn.o_proj weight packed.
model.layers.0.mlp.gate_proj weight packed.
model.layers.0.mlp.up_proj weight packed.
model.layers.0.mlp.down_proj weight packed.
model.layers.1.self_attn.q_proj weight packed.
model.layers.1.self_attn.k_proj weight packed.
model.layers.1.self_attn.v_proj weight packed.
model.layers.1.self_attn.o_proj weight packed.
model.layers.1.mlp.gate_proj weight packed.
model.layers.1.mlp.up_proj weight packed.
model.layers.1.mlp.down_proj weight packed.
model.layers.2.self_attn.q_proj weight packed.
model.layers.2.self_attn.k_proj weight packed.
model.layers.2.self_attn.v_proj weight packed.
model.layers.2.self_attn.o_proj weight packed.
model.layers.2.mlp.gate_proj weight packed.
model.layers.2.mlp.up_proj weight packed.
model.layers.2.mlp.down_proj weight packed.
model.layers.3.self_attn.q_proj weight packed.
model.layers.3.self_attn.k_proj weight packed.
model.layers.3.self_attn.v_proj weight packed.
model.layers.3.self_attn.o_proj weight packed.
model.layers.3.mlp.gate_proj weight packed.
model.layers.3.mlp.up_proj weight packed.
model.layers.3.mlp.down_proj weight packed.
model.layers.4.self_attn.q_proj weight packed.
model.layers.4.self_attn.k_proj weight packed.
model.layers.4.self_attn.v_proj weight packed.
model.layers.4.self_attn.o_proj weight packed.
model.layers.4.mlp.gate_proj weight packed.
model.layers.4.mlp.up_proj weight packed.
model.layers.4.mlp.down_proj weight packed.
model.layers.5.self_attn.q_proj weight packed.
model.layers.5.self_attn.k_proj weight packed.
model.layers.5.self_attn.v_proj weight packed.
model.layers.5.self_attn.o_proj weight packed.
model.layers.5.mlp.gate_proj weight packed.
model.layers.5.mlp.up_proj weight packed.
model.layers.5.mlp.down_proj weight packed.
model.layers.6.self_attn.q_proj weight packed.
model.layers.6.self_attn.k_proj weight packed.
model.layers.6.self_attn.v_proj weight packed.
model.layers.6.self_attn.o_proj weight packed.
model.layers.6.mlp.gate_proj weight packed.
model.layers.6.mlp.up_proj weight packed.
model.layers.6.mlp.down_proj weight packed.
model.layers.7.self_attn.q_proj weight packed.
model.layers.7.self_attn.k_proj weight packed.
model.layers.7.self_attn.v_proj weight packed.
model.layers.7.self_attn.o_proj weight packed.
model.layers.7.mlp.gate_proj weight packed.
model.layers.7.mlp.up_proj weight packed.
model.layers.7.mlp.down_proj weight packed.
model.layers.8.self_attn.q_proj weight packed.
model.layers.8.self_attn.k_proj weight packed.
model.layers.8.self_attn.v_proj weight packed.
model.layers.8.self_attn.o_proj weight packed.
model.layers.8.mlp.gate_proj weight packed.
model.layers.8.mlp.up_proj weight packed.
model.layers.8.mlp.down_proj weight packed.
model.layers.9.self_attn.q_proj weight packed.
model.layers.9.self_attn.k_proj weight packed.
model.layers.9.self_attn.v_proj weight packed.
model.layers.9.self_attn.o_proj weight packed.
model.layers.9.mlp.gate_proj weight packed.
model.layers.9.mlp.up_proj weight packed.
model.layers.9.mlp.down_proj weight packed.
model.layers.10.self_attn.q_proj weight packed.
model.layers.10.self_attn.k_proj weight packed.
model.layers.10.self_attn.v_proj weight packed.
model.layers.10.self_attn.o_proj weight packed.
model.layers.10.mlp.gate_proj weight packed.
model.layers.10.mlp.up_proj weight packed.
model.layers.10.mlp.down_proj weight packed.
model.layers.11.self_attn.q_proj weight packed.
model.layers.11.self_attn.k_proj weight packed.
model.layers.11.self_attn.v_proj weight packed.
model.layers.11.self_attn.o_proj weight packed.
model.layers.11.mlp.gate_proj weight packed.
model.layers.11.mlp.up_proj weight packed.
model.layers.11.mlp.down_proj weight packed.
model.layers.12.self_attn.q_proj weight packed.
model.layers.12.self_attn.k_proj weight packed.
model.layers.12.self_attn.v_proj weight packed.
model.layers.12.self_attn.o_proj weight packed.
model.layers.12.mlp.gate_proj weight packed.
model.layers.12.mlp.up_proj weight packed.
model.layers.12.mlp.down_proj weight packed.
model.layers.13.self_attn.q_proj weight packed.
model.layers.13.self_attn.k_proj weight packed.
model.layers.13.self_attn.v_proj weight packed.
model.layers.13.self_attn.o_proj weight packed.
model.layers.13.mlp.gate_proj weight packed.
model.layers.13.mlp.up_proj weight packed.
model.layers.13.mlp.down_proj weight packed.
model.layers.14.self_attn.q_proj weight packed.
model.layers.14.self_attn.k_proj weight packed.
model.layers.14.self_attn.v_proj weight packed.
model.layers.14.self_attn.o_proj weight packed.
model.layers.14.mlp.gate_proj weight packed.
model.layers.14.mlp.up_proj weight packed.
model.layers.14.mlp.down_proj weight packed.
model.layers.15.self_attn.q_proj weight packed.
model.layers.15.self_attn.k_proj weight packed.
model.layers.15.self_attn.v_proj weight packed.
model.layers.15.self_attn.o_proj weight packed.
model.layers.15.mlp.gate_proj weight packed.
model.layers.15.mlp.up_proj weight packed.
model.layers.15.mlp.down_proj weight packed.
model.layers.16.self_attn.q_proj weight packed.
model.layers.16.self_attn.k_proj weight packed.
model.layers.16.self_attn.v_proj weight packed.
model.layers.16.self_attn.o_proj weight packed.
model.layers.16.mlp.gate_proj weight packed.
model.layers.16.mlp.up_proj weight packed.
model.layers.16.mlp.down_proj weight packed.
model.layers.17.self_attn.q_proj weight packed.
model.layers.17.self_attn.k_proj weight packed.
model.layers.17.self_attn.v_proj weight packed.
model.layers.17.self_attn.o_proj weight packed.
model.layers.17.mlp.gate_proj weight packed.
model.layers.17.mlp.up_proj weight packed.
model.layers.17.mlp.down_proj weight packed.
model.layers.18.self_attn.q_proj weight packed.
model.layers.18.self_attn.k_proj weight packed.
model.layers.18.self_attn.v_proj weight packed.
model.layers.18.self_attn.o_proj weight packed.
model.layers.18.mlp.gate_proj weight packed.
model.layers.18.mlp.up_proj weight packed.
model.layers.18.mlp.down_proj weight packed.
model.layers.19.self_attn.q_proj weight packed.
model.layers.19.self_attn.k_proj weight packed.
model.layers.19.self_attn.v_proj weight packed.
model.layers.19.self_attn.o_proj weight packed.
model.layers.19.mlp.gate_proj weight packed.
model.layers.19.mlp.up_proj weight packed.
model.layers.19.mlp.down_proj weight packed.
model.layers.20.self_attn.q_proj weight packed.
model.layers.20.self_attn.k_proj weight packed.
model.layers.20.self_attn.v_proj weight packed.
model.layers.20.self_attn.o_proj weight packed.
model.layers.20.mlp.gate_proj weight packed.
model.layers.20.mlp.up_proj weight packed.
model.layers.20.mlp.down_proj weight packed.
model.layers.21.self_attn.q_proj weight packed.
model.layers.21.self_attn.k_proj weight packed.
model.layers.21.self_attn.v_proj weight packed.
model.layers.21.self_attn.o_proj weight packed.
model.layers.21.mlp.gate_proj weight packed.
model.layers.21.mlp.up_proj weight packed.
model.layers.21.mlp.down_proj weight packed.
model.layers.22.self_attn.q_proj weight packed.
model.layers.22.self_attn.k_proj weight packed.
model.layers.22.self_attn.v_proj weight packed.
model.layers.22.self_attn.o_proj weight packed.
model.layers.22.mlp.gate_proj weight packed.
model.layers.22.mlp.up_proj weight packed.
model.layers.22.mlp.down_proj weight packed.
model.layers.23.self_attn.q_proj weight packed.
model.layers.23.self_attn.k_proj weight packed.
model.layers.23.self_attn.v_proj weight packed.
model.layers.23.self_attn.o_proj weight packed.
model.layers.23.mlp.gate_proj weight packed.
model.layers.23.mlp.up_proj weight packed.
model.layers.23.mlp.down_proj weight packed.
model.layers.24.self_attn.q_proj weight packed.
model.layers.24.self_attn.k_proj weight packed.
model.layers.24.self_attn.v_proj weight packed.
model.layers.24.self_attn.o_proj weight packed.
model.layers.24.mlp.gate_proj weight packed.
model.layers.24.mlp.up_proj weight packed.
model.layers.24.mlp.down_proj weight packed.
model.layers.25.self_attn.q_proj weight packed.
model.layers.25.self_attn.k_proj weight packed.
model.layers.25.self_attn.v_proj weight packed.
model.layers.25.self_attn.o_proj weight packed.
model.layers.25.mlp.gate_proj weight packed.
model.layers.25.mlp.up_proj weight packed.
model.layers.25.mlp.down_proj weight packed.
model.layers.26.self_attn.q_proj weight packed.
model.layers.26.self_attn.k_proj weight packed.
model.layers.26.self_attn.v_proj weight packed.
model.layers.26.self_attn.o_proj weight packed.
model.layers.26.mlp.gate_proj weight packed.
model.layers.26.mlp.up_proj weight packed.
model.layers.26.mlp.down_proj weight packed.
model.layers.27.self_attn.q_proj weight packed.
model.layers.27.self_attn.k_proj weight packed.
model.layers.27.self_attn.v_proj weight packed.
model.layers.27.self_attn.o_proj weight packed.
model.layers.27.mlp.gate_proj weight packed.
model.layers.27.mlp.up_proj weight packed.
model.layers.27.mlp.down_proj weight packed.
(v62new) [zhulin1@SH-IDC1-10-140-0-187 ~]$ lmdeploy lite auto_awq /nvme/qa_test_models/THUDM/ --batch-size 32
chatglm2-6b/                     cogvlm2-llama3-chinese-chat-19B/ glm-4-9b-chat/                   
codegeex4-all-9b/                cogvlm-chat-hf/                  glm-4v-9b/                       
(v62new) [zhulin1@SH-IDC1-10-140-0-187 ~]$ lmdeploy lite auto_awq /nvme/qa_test_models/THUDM/ --batch-size 32
chatglm2-6b/                     cogvlm2-llama3-chinese-chat-19B/ glm-4-9b-chat/                   
codegeex4-all-9b/                cogvlm-chat-hf/                  glm-4v-9b/                       
(v62new) [zhulin1@SH-IDC1-10-140-0-187 ~]$ lmdeploy lite auto_awq /nvme/qa_test_models/THUDM/glm-4v-9b --batch-size 32
2024-12-26 10:47:18,339 - lmdeploy - INFO - builder.py:68 - matching vision model: GLM4VisionModel
Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 15/15 [00:19<00:00,  1.30s/it]
Move transformer.embedding to GPU.
Move transformer.rotary_pos_emb to GPU.
Move transformer.encoder.layers.0 to CPU.
Move transformer.encoder.layers.1 to CPU.
Move transformer.encoder.layers.2 to CPU.
Move transformer.encoder.layers.3 to CPU.
Move transformer.encoder.layers.4 to CPU.
Move transformer.encoder.layers.5 to CPU.
Move transformer.encoder.layers.6 to CPU.
Move transformer.encoder.layers.7 to CPU.
Move transformer.encoder.layers.8 to CPU.
Move transformer.encoder.layers.9 to CPU.
Move transformer.encoder.layers.10 to CPU.
Move transformer.encoder.layers.11 to CPU.
Move transformer.encoder.layers.12 to CPU.
Move transformer.encoder.layers.13 to CPU.
Move transformer.encoder.layers.14 to CPU.
Move transformer.encoder.layers.15 to CPU.
Move transformer.encoder.layers.16 to CPU.
Move transformer.encoder.layers.17 to CPU.
Move transformer.encoder.layers.18 to CPU.
Move transformer.encoder.layers.19 to CPU.
Move transformer.encoder.layers.20 to CPU.
Move transformer.encoder.layers.21 to CPU.
Move transformer.encoder.layers.22 to CPU.
Move transformer.encoder.layers.23 to CPU.
Move transformer.encoder.layers.24 to CPU.
Move transformer.encoder.layers.25 to CPU.
Move transformer.encoder.layers.26 to CPU.
Move transformer.encoder.layers.27 to CPU.
Move transformer.encoder.layers.28 to CPU.
Move transformer.encoder.layers.29 to CPU.
Move transformer.encoder.layers.30 to CPU.
Move transformer.encoder.layers.31 to CPU.
Move transformer.encoder.layers.32 to CPU.
Move transformer.encoder.layers.33 to CPU.
Move transformer.encoder.layers.34 to CPU.
Move transformer.encoder.layers.35 to CPU.
Move transformer.encoder.layers.36 to CPU.
Move transformer.encoder.layers.37 to CPU.
Move transformer.encoder.layers.38 to CPU.
Move transformer.encoder.layers.39 to CPU.
Move transformer.encoder.final_layernorm to GPU.
Move transformer.output_layer to CPU.
Move transformer.vision to GPU.
Loading calibrate dataset ...
Token indices sequence length is longer than the specified maximum sequence length for this model (1104488 > 8192). Running this sequence through the model will result in indexing errors
Traceback (most recent call last):
  File "/home/zhulin1/miniconda3/envs/v62new/bin/lmdeploy", line 8, in <module>
    sys.exit(run())
  File "/home/zhulin1/miniconda3/envs/v62new/lib/python3.10/site-packages/lmdeploy/cli/entrypoint.py", line 42, in run
    args.run(args)
  File "/home/zhulin1/miniconda3/envs/v62new/lib/python3.10/site-packages/lmdeploy/cli/lite.py", line 135, in auto_awq
    auto_awq(**kwargs)
  File "/home/zhulin1/miniconda3/envs/v62new/lib/python3.10/site-packages/lmdeploy/lite/apis/auto_awq.py", line 91, in auto_awq
    vl_model, model, tokenizer, work_dir = calibrate(model,
  File "/home/zhulin1/miniconda3/envs/v62new/lib/python3.10/site-packages/lmdeploy/lite/apis/calibrate.py", line 294, in calibrate
    calib_loader, _ = get_calib_loaders(calib_dataset,
  File "/home/zhulin1/miniconda3/envs/v62new/lib/python3.10/site-packages/lmdeploy/lite/utils/calib_dataloader.py", line 323, in get_calib_loaders
    return get_ptb(tokenizer, nsamples, seed, seqlen)
  File "/home/zhulin1/miniconda3/envs/v62new/lib/python3.10/site-packages/lmdeploy/lite/utils/calib_dataloader.py", line 73, in get_ptb
    trainenc = tokenizer('\n\n'.join(traindata['sentence']),
  File "/home/zhulin1/miniconda3/envs/v62new/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 3021, in __call__
    encodings = self._call_one(text=text, text_pair=text_pair, **all_kwargs)
  File "/home/zhulin1/miniconda3/envs/v62new/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 3131, in _call_one
    return self.encode_plus(
  File "/home/zhulin1/miniconda3/envs/v62new/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 3207, in encode_plus
    return self._encode_plus(
  File "/home/zhulin1/miniconda3/envs/v62new/lib/python3.10/site-packages/transformers/tokenization_utils.py", line 804, in _encode_plus
    return self.prepare_for_model(
  File "/home/zhulin1/miniconda3/envs/v62new/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 3703, in prepare_for_model
    encoded_inputs = self.pad(
  File "/home/zhulin1/miniconda3/envs/v62new/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 3505, in pad
    encoded_inputs = self._pad(
TypeError: ChatGLM4Tokenizer._pad() got an unexpected keyword argument 'padding_side'

@lvhan028
Copy link
Collaborator Author

The glm4v model should be quantized with transformers <4.45.0.

Copy link
Collaborator

@AllentDan AllentDan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lvhan028 lvhan028 merged commit 4e5cc16 into InternLM:main Dec 26, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants