fix: use FSDP for 2-GPU training, reduce batch size
This commit is contained in:
@@ -31,8 +31,8 @@ dataset:
|
||||
# Training Parameters
|
||||
train_params:
|
||||
num_train_epochs: 3
|
||||
per_device_train_batch_size: 4
|
||||
gradient_accumulation_steps: 4
|
||||
per_device_train_batch_size: 1
|
||||
gradient_accumulation_steps: 8
|
||||
learning_rate: 2e-4
|
||||
lr_scheduler_type: cosine
|
||||
weight_decay: 0.01
|
||||
@@ -46,6 +46,13 @@ train_params:
|
||||
# Precision
|
||||
mixed_precision: bf16
|
||||
|
||||
# Distributed training (2x RTX 5090)
|
||||
fsdp: full_shard
|
||||
fsdp_config:
|
||||
limit_all_gathers: true
|
||||
offload_optimizer: true
|
||||
offload_model: false
|
||||
|
||||
# Evaluation
|
||||
eval_strategy: steps
|
||||
eval_steps: 100
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user