feat: use DeepSpeed ZeRO-3 for optimal 2-GPU training
This commit is contained in:
@@ -46,12 +46,22 @@ train_params:
|
|||||||
# Precision
|
# Precision
|
||||||
mixed_precision: bf16
|
mixed_precision: bf16
|
||||||
|
|
||||||
# Distributed training (2x RTX 5090)
|
# Distributed training (2x RTX 5090) - DeepSpeed ZeRO-3
|
||||||
fsdp: full_shard
|
plugin: deepspeed
|
||||||
fsdp_config:
|
huggingface_hub:
|
||||||
limit_all_gathers: true
|
token: null
|
||||||
offload_optimizer: true
|
deeepspeed_config:
|
||||||
offload_model: false
|
zero_optimization:
|
||||||
|
stage: 3
|
||||||
|
offload_optimizer:
|
||||||
|
device: cpu
|
||||||
|
pin_memory: true
|
||||||
|
offload_param:
|
||||||
|
device: cpu
|
||||||
|
pin_memory: true
|
||||||
|
gradient_clipping: 1.0
|
||||||
|
train_batch_size: auto
|
||||||
|
train_micro_batch_size_per_gpu: auto
|
||||||
|
|
||||||
# Evaluation
|
# Evaluation
|
||||||
eval_strategy: steps
|
eval_strategy: steps
|
||||||
|
|||||||
@@ -34,16 +34,12 @@ def train(config_path):
|
|||||||
|
|
||||||
print(f"Loading model: {config['base_model']}")
|
print(f"Loading model: {config['base_model']}")
|
||||||
|
|
||||||
# Load model with distributed training support
|
# Load model - let the model's own quantization config handle it
|
||||||
# Use FSDP for multi-GPU training
|
# (Ornith uses CompressedTensors, not BitsAndBytes)
|
||||||
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"],
|
||||||
torch_dtype=torch.bfloat16,
|
torch_dtype=torch.bfloat16,
|
||||||
device_map="cpu", # Load on CPU first
|
device_map="auto", # Let transformers distribute across GPUs
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add LoRA
|
# Add LoRA
|
||||||
@@ -93,13 +89,9 @@ def train(config_path):
|
|||||||
gradient_checkpointing=config.get("gradient_checkpointing", True),
|
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
|
from trl import SFTTrainer
|
||||||
|
|
||||||
# Prepare model for FSDP
|
|
||||||
model = accelerator.prepare(model)
|
|
||||||
|
|
||||||
# SFT Trainer
|
|
||||||
trainer = SFTTrainer(
|
trainer = SFTTrainer(
|
||||||
model=model,
|
model=model,
|
||||||
tokenizer=tokenizer,
|
tokenizer=tokenizer,
|
||||||
@@ -109,9 +101,6 @@ 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