fix: use FSDP for 2-GPU training, reduce batch size

This commit is contained in:
Christian Medina
2026-06-30 18:23:34 -04:00
parent 3d87f0b8b3
commit cd58ffd31e
2 changed files with 25 additions and 5 deletions

View File

@@ -34,12 +34,16 @@ def train(config_path):
print(f"Loading model: {config['base_model']}")
# Load model - let the model's own quantization config handle it
# (Ornith uses CompressedTensors, not BitsAndBytes)
# Load model with distributed training support
# Use FSDP for multi-GPU training
from accelerate import Accelerator
accelerator = Accelerator()
# Load model on CPU first, then distribute
model = AutoModelForCausalLM.from_pretrained(
config["base_model"],
device_map="auto",
torch_dtype=torch.bfloat16,
device_map="cpu", # Load on CPU first
)
# Add LoRA
@@ -89,6 +93,12 @@ def train(config_path):
gradient_checkpointing=config.get("gradient_checkpointing", True),
)
# Use FSDP for multi-GPU training
from trl import SFTTrainer
# Prepare model for FSDP
model = accelerator.prepare(model)
# SFT Trainer
trainer = SFTTrainer(
model=model,
@@ -99,6 +109,9 @@ def train(config_path):
max_seq_length=config["train_params"]["max_seq_length"],
)
# Prepare trainer for distributed training
trainer = accelerator.prepare(trainer)
# Train
print("Starting training...")
trainer.train()