feat: test with BnB 4-bit quantization to force proper loading

This commit is contained in:
Christian Medina
2026-07-02 12:23:34 -04:00
parent c5a3b87eed
commit 3892ea7fec

View File

@@ -24,6 +24,47 @@ def test_strategy_1():
)
print(" ✓ Model loaded successfully")
# Test 1b: Try with load_in_4bit=True (force quantization)
print("\n Testing with load_in_4bit=True (force quantization)...")
torch.cuda.empty_cache()
from transformers import BitsAndBytesConfig
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16,
)
model2 = AutoModelForCausalLM.from_pretrained(
"/data/models/Ornith-1.0-35B-4bit",
quantization_config=bnb_config,
device_map="auto",
trust_remote_code=True,
low_cpu_mem_usage=True,
)
print(" ✓ Model loaded with BnB 4-bit")
print("\n Memory with BnB 4-bit:")
for i in range(torch.cuda.device_count()):
mem = torch.cuda.memory_allocated(i) / 1e9
print(f" GPU {i}: {mem:.2f} GB")
gpu0_mem = torch.cuda.memory_allocated(0) / 1e9
gpu1_mem = torch.cuda.memory_allocated(1) / 1e9
print("\n Distribution Pattern:")
if abs(gpu0_mem - gpu1_mem) < 1.0:
if gpu0_mem < 10.0:
print(" ✓ DISTRIBUTED: Model split across both GPUs")
return True
else:
print(" ⚠ DUPLICATE: Same model on both GPUs")
print(f" Each GPU has ~{gpu0_mem:.2f}GB")
return False
else:
print(" ✗ NOT DISTRIBUTED: Model on one GPU only")
return False
# Check memory usage
print("\n Memory Usage:")
for i in range(torch.cuda.device_count()):