File size: 7,047 Bytes
fca4fc0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
#!/usr/bin/env python3
"""
Debug wrapper for DeepSpeed training
This script allows debugging the training process step by step
"""
import os
import sys
import subprocess
import argparse
from pathlib import Path
def setup_environment():
"""Setup environment variables for debugging"""
env_vars = {
'RANK': '1',
'MASTER_PORT': '29571',
'LOCAL_BATCH_SIZE': '2',
'GRADIENT_ACCUMULATION_STEPS': '4',
'TRANSFORMERS_OFFLINE': '1',
'WANDB_PROJECT': 'vtimellm',
'MODEL_VERSION': 'vicuna-v1-5-7b',
'OUTPUT_DIR': './outputs/',
'STAGE4': './outputs/vtimellm-vicuna-v1-5-7b-activitynet-stage4',
'PYTHONPATH': f"{os.getcwd()}:{os.environ.get('PYTHONPATH', '')}",
'CUDA_VISIBLE_DEVICES': '1',
'TORCH_USE_CUDA_DSA': '1',
'TRANSFORMERS_VERBOSITY': 'info',
'TOKENIZERS_PARALLELISM': 'false'
}
for key, value in env_vars.items():
os.environ[key] = value
return env_vars
def check_required_files():
"""Check if all required files exist"""
required_files = [
"./checkpoints/vicuna-7b-v1.5",
"./data/activitynet/mdpo-train.json",
"./data/activitynet/videos/train",
"./data/activitynet/clipvitl14-vtimellm.pth",
"./checkpoints/vtimellm-vicuna-v1-5-7b-stage1/mm_projector.bin",
"./checkpoints/vtimellm-vicuna-v1-5-7b-stage2",
"./checkpoints/vtimellm-vicuna-v1-5-7b-stage3",
"./checkpoints/vtimellm-vicuna-v1-5-7b-activitynet-stage4",
"./scripts/zero2.json"
]
missing_files = []
for file_path in required_files:
if not Path(file_path).exists():
missing_files.append(file_path)
else:
print(f"✓ Found: {file_path}")
if missing_files:
print("✗ Missing files:")
for file_path in missing_files:
print(f" {file_path}")
return False
return True
def check_gpu():
"""Check GPU availability"""
try:
result = subprocess.run(['nvidia-smi', '--query-gpu=name,memory.total,memory.free', '--format=csv,noheader,nounits'],
capture_output=True, text=True)
if result.returncode == 0:
print("=== GPU Information ===")
print(result.stdout)
print("========================")
return True
else:
print("Warning: nvidia-smi not available or no GPU found")
return False
except FileNotFoundError:
print("Warning: nvidia-smi not found")
return False
def create_output_dir():
"""Create output directory"""
output_dir = "./outputs/vtimellm-vicuna-v1-5-7b-activitynet-stage5"
Path(output_dir).mkdir(parents=True, exist_ok=True)
print(f"Created output directory: {output_dir}")
return output_dir
def run_training():
"""Run the training with DeepSpeed"""
env_vars = setup_environment()
print("=== Debug Environment Setup ===")
for key, value in env_vars.items():
print(f"{key}: {value}")
print("================================")
print("=== Checking Required Files ===")
if not check_required_files():
print("Error: Missing required files. Please check the paths.")
return False
print("=== Checking GPU ===")
check_gpu()
print("=== Creating Output Directory ===")
create_output_dir()
# DeepSpeed command
cmd = [
"deepspeed",
"--include", f"localhost:{env_vars['RANK']}",
"--master_port", env_vars['MASTER_PORT'],
"vtimellm/train/train_dpo_mem.py",
"--deepspeed", "./scripts/zero2.json",
"--lora_enable", "True",
"--lora_r", "8",
"--lora_alpha", "128",
"--training_stage", "3",
"--finetuning", "True",
"--model_name_or_path", "./checkpoints/vicuna-7b-v1.5",
"--version", "v1",
"--data_path", "./data/activitynet/mdpo-train.json",
"--data_folder", "./data/activitynet/videos/train",
"--feat_folder", "./data/activitynet/clipvitl14-vtimellm.pth",
"--pretrain_mm_mlp_adapter", "./checkpoints/vtimellm-vicuna-v1-5-7b-stage1/mm_projector.bin",
"--stage2_path", "./checkpoints/vtimellm-vicuna-v1-5-7b-stage2",
"--stage3_path", "./checkpoints/vtimellm-vicuna-v1-5-7b-stage3",
"--stage4_path", "checkpoints/vtimellm-vicuna-v1-5-7b-activitynet-stage4",
"--output_dir", "./outputs/vtimellm-vicuna-v1-5-7b-activitynet-stage5",
"--bf16", "True",
"--max_steps", "100",
"--per_device_train_batch_size", env_vars['LOCAL_BATCH_SIZE'],
"--gradient_accumulation_steps", env_vars['GRADIENT_ACCUMULATION_STEPS'],
"--evaluation_strategy", "no",
"--save_strategy", "no",
"--save_steps", "50000",
"--save_total_limit", "10",
"--learning_rate", "1e-6",
"--freeze_mm_mlp_adapter", "True",
"--weight_decay", "0.",
"--warmup_ratio", "0.1",
"--lr_scheduler_type", "cosine",
"--logging_steps", "1",
"--tf32", "True",
"--model_max_length", "2048",
"--gradient_checkpointing", "True",
"--dataloader_num_workers", "4",
"--lazy_preprocess", "True",
"--report_to", "none",
"--run_name", "vtimellm-vicuna-v1-5-7b-activitynet-stage5",
"--gamma", "0.0",
"--beta", "0.5",
"--dpo_alpha", "1.0",
"--train4dpo"
]
print("=== Starting Debug Training ===")
print(f"Command: {' '.join(cmd)}")
print("================================")
try:
# Run the command
result = subprocess.run(cmd, check=True)
print("=== Training Completed Successfully ===")
return True
except subprocess.CalledProcessError as e:
print(f"=== Training Failed with Error Code: {e.returncode} ===")
return False
except KeyboardInterrupt:
print("=== Training Interrupted by User ===")
return False
def main():
parser = argparse.ArgumentParser(description="Debug wrapper for MDPO training")
parser.add_argument("--check-only", action="store_true", help="Only check environment and files")
parser.add_argument("--dry-run", action="store_true", help="Show command without executing")
args = parser.parse_args()
if args.check_only:
setup_environment()
check_required_files()
check_gpu()
create_output_dir()
return
if args.dry_run:
env_vars = setup_environment()
cmd = [
"deepspeed",
"--include", f"localhost:{env_vars['RANK']}",
"--master_port", env_vars['MASTER_PORT'],
"vtimellm/train/train_dpo_mem.py",
# ... rest of arguments
]
print("Command that would be executed:")
print(" ".join(cmd))
return
success = run_training()
sys.exit(0 if success else 1)
if __name__ == "__main__":
main()
|