Repository navigation
Closed
Labels
bugSomething isn't working
Description
Describe the bug
Small model opt-125m not working after quantization.
GPU Info
Show output of:
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.54.15 Driver Version: 550.54.15 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 Tesla T4 Off | 00000000:00:04.0 Off | 0 |
| N/A 72C P0 35W / 70W | 326MiB / 15360MiB | 19% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
+-----------------------------------------------------------------------------------------+
Software Info
Operating System: Linux #1 SMP PREEMPT_DYNAMIC Thu Jun 27 21:05:47 UTC 2024 Python Version: 3.11.11
Name: gptqmodel
Version: 2.1.1.dev0
Summary: Production ready LLM model compression/quantization toolkit with hw accelerated inference support for both cpu/gpu via HF, vLLM, and SGLang.
Home-page: https://github.com/ModelCloud/GPTQModel
Author: ModelCloud
Author-email: [[email protected]](mailto:[email protected])
License: Apache 2.0
Location: /usr/local/lib/python3.11/dist-packages
Requires: accelerate, datasets, device-smi, hf-transfer, huggingface-hub, logbar, numpy, packaging, pillow, protobuf, random-word, safetensors, threadpoolctl, tokenicer, torch, transformers
Required-by:
---
Name: torch
Version: 2.6.0+cu124
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: [[email protected]](mailto:[email protected])
License: BSD-3-Clause
Location: /usr/local/lib/python3.11/dist-packages
Requires: filelock, fsspec, jinja2, networkx, nvidia-cublas-cu12, nvidia-cuda-cupti-cu12, nvidia-cuda-nvrtc-cu12, nvidia-cuda-runtime-cu12, nvidia-cudnn-cu12, nvidia-cufft-cu12, nvidia-curand-cu12, nvidia-cusolver-cu12, nvidia-cusparse-cu12, nvidia-cusparselt-cu12, nvidia-nccl-cu12, nvidia-nvjitlink-cu12, nvidia-nvtx-cu12, sympy, triton, typing-extensions
Required-by: accelerate, fastai, gptqmodel, peft, sentence-transformers, timm, torchaudio, torchvision
---
Name: transformers
Version: 4.50.0
Summary: State-of-the-art Machine Learning for JAX, PyTorch and TensorFlow
Home-page: https://github.com/huggingface/transformers
Author: The Hugging Face team (past and future) with the help of all our contributors (https://github.com/huggingface/transformers/graphs/contributors)
Author-email: [[email protected]](mailto:[email protected])
License: Apache 2.0 License
Location: /usr/local/lib/python3.11/dist-packages
Requires: filelock, huggingface-hub, numpy, packaging, pyyaml, regex, requests, safetensors, tokenizers, tqdm
Required-by: gptqmodel, peft, sentence-transformers, tokenicer
---
Name: accelerate
Version: 1.5.2
Summary: Accelerate
Home-page: https://github.com/huggingface/accelerate
Author: The HuggingFace team
Author-email: [[email protected]](mailto:[email protected])
License: Apache
Location: /usr/local/lib/python3.11/dist-packages
Requires: huggingface-hub, numpy, packaging, psutil, pyyaml, safetensors, torch
Required-by: gptqmodel, peft
---
Name: triton
Version: 3.2.0
Summary: A language and compiler for custom Deep Learning operations
Home-page: https://github.com/triton-lang/triton/
Author: Philippe Tillet
Author-email: [[email protected]](mailto:[email protected])
License:
Location: /usr/local/lib/python3.11/dist-packages
Requires:
Required-by: torch
config.json:
{
"_remove_final_layer_norm": false,
"activation_dropout": 0.0,
"activation_function": "relu",
"architectures": [
"OPTForCausalLM"
],
"attention_dropout": 0.0,
"bos_token_id": 2,
"do_layer_norm_before": true,
"dropout": 0.1,
"enable_bias": true,
"eos_token_id": 2,
"ffn_dim": 3072,
"hidden_size": 768,
"init_std": 0.02,
"layer_norm_elementwise_affine": true,
"layerdrop": 0.0,
"max_position_embeddings": 2048,
"model_type": "opt",
"num_attention_heads": 12,
"num_hidden_layers": 12,
"pad_token_id": 1,
"prefix": "</s>",
"quantization_config": {
"bits": 4,
"checkpoint_format": "gptq",
"desc_act": true,
"group_size": 128,
"lm_head": false,
"meta": {
"damp_auto_increment": 0.0025,
"damp_percent": 0.01,
"mse": 0.0,
"quantizer": [
"gptqmodel:2.1.1-dev"
],
"static_groups": false,
"true_sequential": true,
"uri": "https://github.com/modelcloud/gptqmodel"
},
"pack_dtype": "int32",
"quant_method": "gptq",
"sym": true
},
"torch_dtype": "float16",
"transformers_version": "4.50.0",
"use_cache": true,
"vocab_size": 50272,
"word_embed_proj_dim": 768
}
quantize_config.json
{
"bits": 4,
"group_size": 128,
"desc_act": true,
"sym": true,
"lm_head": false,
"quant_method": "gptq",
"checkpoint_format": "gptq",
"pack_dtype": "int32",
"meta": {
"quantizer": [
"gptqmodel:2.1.1-dev"
],
"uri": "https://github.com/modelcloud/gptqmodel",
"damp_percent": 0.01,
"damp_auto_increment": 0.0025,
"static_groups": false,
"true_sequential": true,
"mse": 0.0
}
}
To Reproduce
Quantize the model and run it, using the code from readme.md:
from datasets import load_dataset
from gptqmodel import GPTQModel, QuantizeConfig
model_id = "facebook/opt-125m"
quant_path = "opt-125m-GPTQ-4bit-g128"
calibration_dataset = load_dataset(
"allenai/c4",
data_files="en/c4-train.00001-of-01024.json.gz",
split="train"
).select(range(2048))["text"]
calibration_dataset=['\n'.join(i.split('\n')[:3]) for i in calibration_dataset]
# filter long contexts for small models so that they fit in n_tokens limit
quant_config = QuantizeConfig(bits=4, group_size=128)
model = GPTQModel.load(model_id, quant_config)
# increase `batch_size` to match gpu/vram specs to speed up quantization
model.quantize(calibration_dataset, batch_size=2)
model.save(quant_path)
# test post-quant inference
model = GPTQModel.load(quant_path)
result = model.generate("Uncovering deep insights")[0] # tokens
print(model.tokenizer.decode(result)) # string output
Generation produced by the model: </s>Uncovering deep insights,,,,,,,,,,,,,,,,,,,,
Expected behavior
The model generates some text.
Model/Datasets
The calibration dataset C4 is available on hf.
Additional info
I experienced the same when using the GPTQModel class for the models quantized with auto-gptq, such as iproskurina/opt-125m-GPTQ-4bit-g128
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
[-][BUG] Model Load[/-][+][BUG] OPT-125m not working after quantization [/+]Qubitium commentedon Mar 28, 2025
@upunaprosk Ok. Let's try to isolate. Can you use HF to load the quant
iproskurina/opt-125m-GPTQ-4bit-g128and check if output is same? I want to make sure this is not a HF regression for OPTupunaprosk commentedon Mar 29, 2025
Both models (quantized with
gptqmodelandauto-gptq) don't work withAutoModelForCausalLM(Transformers 4.50.0), regardless of decoding strategy and optimum version that it requires.However,
.generateworks fine withGPTQModelusinggptqmodel≤2.0.0.I’m not sure why it doesn't work for the latest version, as there are no version conflicts.
Since using
gptqmodel≤2.0.0 solves it, the issue can be closed.BUGBOY101 commentedon Mar 30, 2025
Hello, @upunaprosk. I would like to ask if you can load the model quantized with gptqmodel using AutoModelForCausalLM. I encountered an error when testing with model = AutoModelForCausalLM.from_pretrained(model_id_or_path):
Full code for loading the model:
Error message:
File "/root/data1/bjtu_wzx/zyq/fine_tuning/Simple_running/test/cot_generate.py", line 276, in <module> main(args) File "/root/data1/bjtu_wzx/zyq/fine_tuning/Simple_running/test/cot_generate.py", line 139, in main model = AutoModelForCausalLM.from_pretrained( File "/root/miniconda3/envs/llama/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py", line 573, in from_pretrained return model_class.from_pretrained( File "/root/miniconda3/envs/llama/lib/python3.10/site-packages/transformers/modeling_utils.py", line 272, in _wrapper return func(*args, **kwargs) File "/root/miniconda3/envs/llama/lib/python3.10/site-packages/transformers/modeling_utils.py", line 4455, in from_pretrained ) = cls._load_pretrained_model( File "/root/miniconda3/envs/llama/lib/python3.10/site-packages/transformers/modeling_utils.py", line 4884, in _load_pretrained_model disk_offload_index, cpu_offload_index = _load_state_dict_into_meta_model( File "/root/miniconda3/envs/llama/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context return func(*args, **kwargs) File "/root/miniconda3/envs/llama/lib/python3.10/site-packages/transformers/modeling_utils.py", line 852, in _load_state_dict_into_meta_model {param_type: param.to(param_device)}, RuntimeError: CUDA error: invalid device ordinal CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect. For debugging consider passing CUDA_LAUNCH_BLOCKING=1 Compile withTORCH_USE_CUDA_DSAto enable device-side assertions.Qubitium commentedon Mar 31, 2025
@BUGBOY101 Please stop using AI to generate your code. Read our readme on dead simple loading code.
Qubitium commentedon Apr 2, 2025
@upunaprosk I am not sure but it looks like OPT support in latest versions of
transformersis broken?upunaprosk commentedon Apr 3, 2025
@Qubitium Yes, I have the same error with the latest version 4.50.0
simlang commentedon Apr 9, 2025
Ran into the same issue on the same model, switching from a Tesla T4 to an A10 resolved the problem. Might be related to the GPU?
Qubitium commentedon Apr 9, 2025
@simlang I have no idea. I just tested on GPTQModel
mainwith latesttransformers4.51.1andoptis working again. I am using ourtests/models/test_opt.pyto test quant and post quant inference.simlang commentedon Apr 9, 2025
@Qubitium Did you try this on a T4?
Qubitium commentedon Apr 9, 2025
@simlang No. on a A100. GPTQ algorithm requires accurate fp32 math. Maybe T4 has bad or substandard fp32 accuracy vs later chips/A100? I see accuracy issue between 4090 and A100 so maybe the lower (guessing here) accuracy issues of the T4 is causing bad quantization alignment/calibration.
Qubitium commentedon Apr 13, 2025
Guys, I am closing this issue for now until we get more information on exactly what's wrong with T4 and OPT. Right now our
test_opt.pyin tests/model is passing.