Skip to content

Commit ce39cbb

Browse files
authored
Raise on quantization_config + already-instantiated model in DPOTrainer/ KTOTrainer (#6312)
1 parent 70f95f3 commit ce39cbb

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

trl/trainer/dpo_trainer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,10 @@ def __init__(
573573
"The `model_init_kwargs` will be ignored."
574574
)
575575
if quantization_config is not None:
576-
logger.warning(
577-
"You passed `quantization_config` to the trainer, but your model is already instantiated. The "
578-
"`quantization_config` will be ignored."
576+
raise ValueError(
577+
"You passed `quantization_config` to the trainer, but your model is already instantiated. "
578+
"Quantization can only be applied when the model is loaded from a model identifier (`str`). "
579+
"Either pass the model as a model identifier, or omit `quantization_config`."
579580
)
580581
# Non-quantized models do not have the `is_loaded_in_{8,4}bit` attributes, whereas quantized models do
581582
_is_quantized_model = getattr(model, "is_loaded_in_4bit", False) or getattr(model, "is_loaded_in_8bit", False)

trl/trainer/kto_trainer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,9 +624,10 @@ def __init__(
624624
"The `model_init_kwargs` will be ignored."
625625
)
626626
if quantization_config is not None:
627-
logger.warning(
628-
"You passed `quantization_config` to the trainer, but your model is already instantiated. The "
629-
"`quantization_config` will be ignored."
627+
raise ValueError(
628+
"You passed `quantization_config` to the trainer, but your model is already instantiated. "
629+
"Quantization can only be applied when the model is loaded from a model identifier (`str`). "
630+
"Either pass the model as a model identifier, or omit `quantization_config`."
630631
)
631632
# Non-quantized models do not have the `is_loaded_in_{8,4}bit` attributes, whereas quantized models do
632633
_is_quantized_model = getattr(model, "is_loaded_in_4bit", False) or getattr(model, "is_loaded_in_8bit", False)

0 commit comments

Comments
 (0)