From e442ff22aa5dd4bf48b919a45843f83af0ea1e0e Mon Sep 17 00:00:00 2001 From: Wing Lian Date: Wed, 6 Aug 2025 14:28:52 -0400 Subject: [PATCH] fix keyerror on load_in_8bit/load_in_4bit access in _set_quantization_config (#3023) * set load_in_8bit/load_in_4bit in _set_quantization_config to prevent keyerror * use dict.get instead --- src/axolotl/loaders/model.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/axolotl/loaders/model.py b/src/axolotl/loaders/model.py index 7c9e2d2bc..7061e1ff3 100644 --- a/src/axolotl/loaders/model.py +++ b/src/axolotl/loaders/model.py @@ -612,7 +612,9 @@ class ModelLoader: self.model_kwargs["quantization_config"] = BitsAndBytesConfig( **self.model_config.quantization_config ) - elif self.cfg.adapter == "qlora" and self.model_kwargs["load_in_4bit"]: + elif self.cfg.adapter == "qlora" and self.model_kwargs.get( + "load_in_4bit", False + ): bnb_config = { "load_in_4bit": True, "llm_int8_threshold": 6.0, @@ -638,7 +640,9 @@ class ModelLoader: self.model_kwargs["quantization_config"] = BitsAndBytesConfig( **bnb_config, ) - elif self.cfg.adapter == "lora" and self.model_kwargs["load_in_8bit"]: + elif self.cfg.adapter == "lora" and self.model_kwargs.get( + "load_in_8bit", False + ): bnb_config = { "load_in_8bit": True, }