fix: use FSDP for 2-GPU training, reduce batch size
This commit is contained in:
@@ -31,8 +31,8 @@ dataset:
|
|||||||
# Training Parameters
|
# Training Parameters
|
||||||
train_params:
|
train_params:
|
||||||
num_train_epochs: 3
|
num_train_epochs: 3
|
||||||
per_device_train_batch_size: 4
|
per_device_train_batch_size: 1
|
||||||
gradient_accumulation_steps: 4
|
gradient_accumulation_steps: 8
|
||||||
learning_rate: 2e-4
|
learning_rate: 2e-4
|
||||||
lr_scheduler_type: cosine
|
lr_scheduler_type: cosine
|
||||||
weight_decay: 0.01
|
weight_decay: 0.01
|
||||||
@@ -46,6 +46,13 @@ train_params:
|
|||||||
# Precision
|
# Precision
|
||||||
mixed_precision: bf16
|
mixed_precision: bf16
|
||||||
|
|
||||||
|
# Distributed training (2x RTX 5090)
|
||||||
|
fsdp: full_shard
|
||||||
|
fsdp_config:
|
||||||
|
limit_all_gathers: true
|
||||||
|
offload_optimizer: true
|
||||||
|
offload_model: false
|
||||||
|
|
||||||
# Evaluation
|
# Evaluation
|
||||||
eval_strategy: steps
|
eval_strategy: steps
|
||||||
eval_steps: 100
|
eval_steps: 100
|
||||||
|
|||||||
@@ -34,12 +34,16 @@ def train(config_path):
|
|||||||
|
|
||||||
print(f"Loading model: {config['base_model']}")
|
print(f"Loading model: {config['base_model']}")
|
||||||
|
|
||||||
# Load model - let the model's own quantization config handle it
|
# Load model with distributed training support
|
||||||
# (Ornith uses CompressedTensors, not BitsAndBytes)
|
# Use FSDP for multi-GPU training
|
||||||
|
from accelerate import Accelerator
|
||||||
|
accelerator = Accelerator()
|
||||||
|
|
||||||
|
# Load model on CPU first, then distribute
|
||||||
model = AutoModelForCausalLM.from_pretrained(
|
model = AutoModelForCausalLM.from_pretrained(
|
||||||
config["base_model"],
|
config["base_model"],
|
||||||
device_map="auto",
|
|
||||||
torch_dtype=torch.bfloat16,
|
torch_dtype=torch.bfloat16,
|
||||||
|
device_map="cpu", # Load on CPU first
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add LoRA
|
# Add LoRA
|
||||||
@@ -89,6 +93,12 @@ def train(config_path):
|
|||||||
gradient_checkpointing=config.get("gradient_checkpointing", True),
|
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
|
# SFT Trainer
|
||||||
trainer = SFTTrainer(
|
trainer = SFTTrainer(
|
||||||
model=model,
|
model=model,
|
||||||
@@ -99,6 +109,9 @@ def train(config_path):
|
|||||||
max_seq_length=config["train_params"]["max_seq_length"],
|
max_seq_length=config["train_params"]["max_seq_length"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Prepare trainer for distributed training
|
||||||
|
trainer = accelerator.prepare(trainer)
|
||||||
|
|
||||||
# Train
|
# Train
|
||||||
print("Starting training...")
|
print("Starting training...")
|
||||||
trainer.train()
|
trainer.train()
|
||||||
|
|||||||
Reference in New Issue
Block a user