Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/transformers/modeling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,12 @@ def __init__(self, config: PreTrainedConfig, *inputs, **kwargs):
f"`model = {self.__class__.__name__}.from_pretrained(PRETRAINED_MODEL_NAME)`"
)
self.config = config
quant_config = getattr(config, "quantization_config", None)
if quant_config is not None:
raise NotImplementedError(
"Quantization via `from_config()` is not supported. "
"Quantized models must be created via `from_pretrained()` with an appropriate backend."
)

# Check the attention implementation is supported, or set it if not yet set (on the internal attr, to avoid
# setting it recursively)
Expand Down
Empty file.
14 changes: 14 additions & 0 deletions tests/quantization/config/test_from_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest

from transformers import AutoConfig, AutoModel


def test_quantization_from_config_raises():
config = AutoConfig.from_pretrained("gpt2")
config.quantization_config = {"quant_method": "fp8"}

with pytest.raises(
NotImplementedError,
match="Quantization via",
):
AutoModel.from_config(config)