feat: use DeepSpeed ZeRO-3 for optimal 2-GPU training
This commit is contained in:
@@ -34,16 +34,12 @@ def train(config_path):
|
||||
|
||||
print(f"Loading model: {config['base_model']}")
|
||||
|
||||
# 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
|
||||
# Load model - let the model's own quantization config handle it
|
||||
# (Ornith uses CompressedTensors, not BitsAndBytes)
|
||||
model = AutoModelForCausalLM.from_pretrained(
|
||||
config["base_model"],
|
||||
torch_dtype=torch.bfloat16,
|
||||
device_map="cpu", # Load on CPU first
|
||||
device_map="auto", # Let transformers distribute across GPUs
|
||||
)
|
||||
|
||||
# Add LoRA
|
||||
@@ -93,13 +89,9 @@ def train(config_path):
|
||||
gradient_checkpointing=config.get("gradient_checkpointing", True),
|
||||
)
|
||||
|
||||
# Use FSDP for multi-GPU training
|
||||
# SFT Trainer (DeepSpeed handles distributed training via config)
|
||||
from trl import SFTTrainer
|
||||
|
||||
# Prepare model for FSDP
|
||||
model = accelerator.prepare(model)
|
||||
|
||||
# SFT Trainer
|
||||
trainer = SFTTrainer(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
@@ -109,9 +101,6 @@ 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()
|
||||
|
||||
Reference in New Issue
Block a user