You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to Quantize Qwen2.5-VL on image calibration data #1781
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
},
{"type": "text", "text": "Describe this image."},
],
}
]
quantize_config = QuantizeConfig(
bits=4, # quantize model to 4-bit
group_size=128, # it is recommended to set the value to 128
)
# load un-quantized model, by default, the model will always be loaded into CPU memory
model = GPTQModel.load(pretrained_model_id, quantize_config)
# quantize model, the calibration_dataset should be list of dict whose keys can only be "input_ids" and "attention_mask"
model.quantize(messages)
# save quantized model
model.save(quantized_model_id)
@Qubitium I tried modifying the dataset, but I encountered the following error when running it. It seems that the device of grid_thw is CPU. Is this expected? My GPTQModel was compiled from the source code on the main branch, and the Transformers version is 4.56.1.
@Qubitium If the device of cu_seqlens is set to CUDA, quantization can proceed normally, but the following error occurs during execution.
The device appears to be “device(type='cuda')”
I'm not sure if there's an issue with my environment; could you please provide some troubleshooting suggestions?
@Qubitium If the device of cu_seqlens is set to CUDA, quantization can proceed normally, but the following error occurs during execution.
The device appears to be “device(type='cuda')”
I'm not sure if there's an issue with my environment; could you please provide some troubleshooting suggestions?
@Qubitium I only used one data sample for quantization, and then used the same sample for testing, but found that the results overflowed. Is this expected?
@Qubitium I only used one data sample for quantization, and then used the same sample for testing, but found that the results overflowed. Is this expected?
What do you mean overflowed? Please provide stack traces for every exception especially NaN type errors
That is not overflow..it is just bad output due to bad quantization likely due to you using one single input/calibration sample. Check the loss values during quant stage. The lower the better, usually.
@Zhiy-Zhang I am going to close this issue and the new threads are unrelated to the original issue. Please open a new issue if you have any other questions.
Activity
Qubitium commentedon Sep 10, 2025
@Zhiy-Zhang Please check our tests/models ci tests for per model sample usage.
Zhiy-Zhang commentedon Sep 10, 2025
@Qubitium
Thank you for your reply. I plan to use my own dataset for quantization, but I'm not entirely clear about the specific workflow. I'm referring to this test file “ test_qwen2_5_vl.py”,
After reading the source code:https://github.com/ModelCloud/GPTQModel/blob/main/tests/models/model_test.py#L205, I understand that following this workflow, can I achieve quantization by simply modifying this part to replace it with my own dataset?
Qubitium commentedon Sep 10, 2025
@Zhiy-Zhang You are correct. Follow the same workflow but tweak/inject your own dataset plus quant params and you are all good
Zhiy-Zhang commentedon Sep 11, 2025
@Qubitium Thank you for your reply.
Zhiy-Zhang commentedon Sep 11, 2025
@Qubitium I tried modifying the dataset, but I encountered the following error when running it. It seems that the device of grid_thw is CPU. Is this expected? My GPTQModel was compiled from the source code on the main branch, and the Transformers version is 4.56.1.
Zhiy-Zhang commentedon Sep 11, 2025
@Qubitium If the device of cu_seqlens is set to CUDA, quantization can proceed normally, but the following error occurs during execution.
The device appears to be “device(type='cuda')”
I'm not sure if there's an issue with my environment; could you please provide some troubleshooting suggestions?
Qubitium commentedon Sep 11, 2025
Please code to src and var usage of cu_seqlens.
Zhiy-Zhang commentedon Sep 11, 2025
@Qubitium
I modified two parts to make the entire training process run smoothly.
1、https://github.com/ModelCloud/GPTQModel/blob/main/gptqmodel/looper/module_looper.py#L125:
Qubitium commentedon Sep 11, 2025
@LRL-ModelCloud check this. By default we should pick the best GPU, Cuda for this user in this call. Something happened to cause this regress?
Zhiy-Zhang commentedon Sep 11, 2025
@Qubitium I only used one data sample for quantization, and then used the same sample for testing, but found that the results overflowed. Is this expected?
Qubitium commentedon Sep 11, 2025
@Zhiy-Zhang Previous device errors should be fixed in pr #1783
Qubitium commentedon Sep 11, 2025
What do you mean overflowed? Please provide stack traces for every exception especially NaN type errors
Zhiy-Zhang commentedon Sep 11, 2025
@Qubitium
my model:
https://github.com/bytedance/UI-TARS
Qubitium commentedon Sep 11, 2025
That is not overflow..it is just bad output due to bad quantization likely due to you using one single input/calibration sample. Check the loss values during quant stage. The lower the better, usually.
Qubitium commentedon Sep 12, 2025
@Zhiy-Zhang I am going to close this issue and the new threads are unrelated to the original issue. Please open a new issue if you have any other questions.