fix: remove broken quantization_config before loading
This commit is contained in:
@@ -34,7 +34,11 @@ def train(config_path):
|
|||||||
|
|
||||||
# Load model (skip broken quantization config)
|
# Load model (skip broken quantization config)
|
||||||
print(f"Loading model: {config['base_model']}")
|
print(f"Loading model: {config['base_model']}")
|
||||||
from transformers import BitsAndBytesConfig
|
from transformers import BitsAndBytesConfig, AutoConfig
|
||||||
|
|
||||||
|
# Remove broken quantization config
|
||||||
|
model_config = AutoConfig.from_pretrained(config["base_model"])
|
||||||
|
model_config.quantization_config = None
|
||||||
|
|
||||||
bnb_config = BitsAndBytesConfig(
|
bnb_config = BitsAndBytesConfig(
|
||||||
load_in_4bit=True,
|
load_in_4bit=True,
|
||||||
@@ -43,17 +47,15 @@ def train(config_path):
|
|||||||
bnb_4bit_use_double_quant=True,
|
bnb_4bit_use_double_quant=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Load without quantization config, then apply BnB
|
# Load with fresh BnB config
|
||||||
model = AutoModelForCausalLM.from_pretrained(
|
model = AutoModelForCausalLM.from_pretrained(
|
||||||
config["base_model"],
|
config["base_model"],
|
||||||
|
quantization_config=bnb_config,
|
||||||
torch_dtype=torch.bfloat16,
|
torch_dtype=torch.bfloat16,
|
||||||
device_map="auto",
|
device_map="auto",
|
||||||
trust_remote_code=True,
|
trust_remote_code=True,
|
||||||
)
|
)
|
||||||
# Apply 4-bit quantization after loading
|
print("Model loaded with QLoRA (4-bit).")
|
||||||
from peft import prepare_model_for_kbit_training
|
|
||||||
model = prepare_model_for_kbit_training(model, use_gradient_checkpointing=True)
|
|
||||||
print("Model loaded and quantized.")
|
|
||||||
|
|
||||||
# Prepare model for k-bit training
|
# Prepare model for k-bit training
|
||||||
from peft import prepare_model_for_kbit_training
|
from peft import prepare_model_for_kbit_training
|
||||||
|
|||||||
Reference in New Issue
Block a user