fix: load bf16 model directly with BnB 4-bit (single load)

This commit is contained in:
Christian Medina
2026-07-02 21:09:54 -04:00
parent 1f804c95cd
commit 04a95f362f
2 changed files with 4 additions and 21 deletions

View File

@@ -33,19 +33,8 @@ def train(config_path):
print(f"Loading model: {config['base_model']}")
# Load bf16 to CPU first
print(f"\n[INFO] Loading {config['base_model']} bf16 to CPU...")
model = AutoModelForCausalLM.from_pretrained(
config["base_model"],
device_map="cpu",
torch_dtype=torch.bfloat16,
trust_remote_code=True,
low_cpu_mem_usage=True,
)
print("✓ Model loaded to CPU (~70GB bf16)")
# Quantize with BnB on CPU
print(" Quantizing with BnB 4-bit on CPU...")
# Load bf16 to CPU with BnB 4-bit quantization
print(f"\n[INFO] Loading {config['base_model']} with BnB 4-bit to CPU...")
from transformers import BitsAndBytesConfig
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
@@ -53,12 +42,6 @@ def train(config_path):
bnb_4bit_compute_dtype=torch.float16,
)
# Reload with quantization
del model
import gc
gc.collect()
torch.cuda.empty_cache()
model = AutoModelForCausalLM.from_pretrained(
config["base_model"],
quantization_config=bnb_config,
@@ -67,7 +50,7 @@ def train(config_path):
trust_remote_code=True,
low_cpu_mem_usage=True,
)
print("✓ Model quantized to 4-bit on CPU")
print("✓ Model loaded to CPU with BnB 4-bit (~17.5GB)")
# Move to GPU
print(" Moving to GPU 0...")

View File

@@ -1,7 +1,7 @@
# LoRA Training Configuration for Ornith-1.0-35B
# Dataset: cyron_summary_lora_dataset (20k examples)
base_model: /data/models/Ornith-1.0-35B-bnb-4bit
base_model: /data/models/Ornith-1.0-35B
model_type: Qwen3_5MoeForCausalLM
tokenizer_type: AutoTokenizer