ViuAI commited on
Commit
4d548d5
Β·
verified Β·
1 Parent(s): 76cede9

Update Kaggle Dual T4 runner with DDP 4x32 batch sizing

Browse files
runners/KAGGLE_CONTINUATION_PRETRAIN_GPU.txt CHANGED
@@ -1,26 +1,30 @@
1
  # ==============================================================================
2
- # πŸš€ ViuAI Sarus-500M β€” Kaggle 2x T4 GPU Training Runner (Continuation V2)
3
  # ==============================================================================
4
  # Instructions for Kaggle:
5
- # 1. In Kaggle Notebook Settings:
6
  # β€’ Accelerator: Select "GPU T4 x2" (Dual GPU)
7
- # β€’ Internet: ON
8
- # 2. Paste this entire script into a single cell and click "Run All".
9
- # 3. It will:
10
- # β€’ Download base checkpoint (Step 40,000) from ViuAI/ViuAI-500M.
11
- # β€’ Stream the new 10B token shards from ViuAI/viuai-500m-data/shards_v2/.
12
- # β€’ Train on both T4 GPUs in parallel using PyTorch DDP.
13
- # β€’ Auto-save and upload updated ckpt_latest.pt back to Hugging Face.
 
 
14
  # ==============================================================================
15
 
16
- !pip install -q torch transformers datasets tokenizers huggingface_hub numpy
17
 
18
  import os, sys, shutil
 
19
  from huggingface_hub import HfApi, hf_hub_download
20
 
21
- # Ensure unbuffered real-time logs and memory fragmentation protection
22
  os.environ["PYTHONUNBUFFERED"] = "1"
23
  os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
 
24
 
25
  HF_TOKEN = os.environ.get("HF_TOKEN") or ''.join(['hf_','ssyCVhuny','XxjGdqKp','VLPpkmWK','FrrMOIFbg'])
26
  os.environ["HF_TOKEN"] = HF_TOKEN
@@ -29,25 +33,47 @@ REPO_ID = "ViuAI/ViuAI-500M"
29
  DATA_REPO = "ViuAI/viuai-500m-data"
30
 
31
  print("=" * 80)
32
- print("πŸš€ ViuAI Sarus-500M β€” Launching Dual T4 GPU Training (Continuation V2)")
33
  print("=" * 80)
34
 
35
- # Continuation Pretraining Hyperparameters
36
- os.environ["TOTAL_STEPS"] = "60000" # 20,000 continuation steps (~10B tokens)
 
 
 
 
 
 
 
 
 
 
 
37
  os.environ["MAX_LR"] = "1.0e-4" # Calibrated continuation LR to protect base weights
38
  os.environ["MIN_LR"] = "1.0e-5"
39
  os.environ["WARMUP_STEPS"] = "500"
40
- os.environ["SAVE_EVERY"] = "250" # Frequent checkpoint saves every ~20 mins for Kaggle safety
41
  os.environ["EVAL_EVERY"] = "250"
42
- os.environ["MICRO_BATCH"] = "4" # Perfectly sized for Kaggle Dual T4 (15GB VRAM)
 
 
 
 
43
  os.environ["GRAD_ACCUM"] = "32"
44
 
 
 
45
  # Fetch latest verified code and tokenizer directly from HF
46
  for f in ["code/config.py", "code/model.py", "code/train.py", "tokenizer/tokenizer.json"]:
47
  os.makedirs(os.path.dirname(f), exist_ok=True)
48
  print(f"πŸ“₯ Downloading latest {f}...")
49
  p = hf_hub_download(repo_id=REPO_ID, filename=f, token=HF_TOKEN, force_download=True)
50
  shutil.copy(p, f)
 
 
 
 
 
51
 
52
- # Launch 2x GPU Distributed Training
53
  !torchrun --nproc_per_node=2 code/train.py
 
1
  # ==============================================================================
2
+ # πŸš€ ViuAI Sarus-500M β€” Kaggle 2x T4 Dual-GPU Pretraining Runner (Continuation V2)
3
  # ==============================================================================
4
  # Instructions for Kaggle:
5
+ # 1. In Kaggle Notebook Settings (Right Panel):
6
  # β€’ Accelerator: Select "GPU T4 x2" (Dual GPU)
7
+ # β€’ Internet: Always ON
8
+ # β€’ Environment: Always use latest environment
9
+ # 2. Paste this entire script into a single cell and click Run (Shift + Enter).
10
+ # 3. What it does automatically:
11
+ # β€’ Resumes seamlessly from latest HF checkpoint (Step 42,750+).
12
+ # β€’ Uses PyTorch DDP across both T4 GPUs in parallel (world_size=2).
13
+ # β€’ Effective Batch: MICRO_BATCH=4, GRAD_ACCUM=32 -> 524,288 tok/step.
14
+ # β€’ Streams 200 shards (10B tokens) from ViuAI/viuai-500m-data/shards_v2/.
15
+ # β€’ Background Checkpoint Uploader: Uploads ckpt_latest.pt every 250 steps to HF.
16
  # ==============================================================================
17
 
18
+ !pip install -q transformers datasets tokenizers huggingface_hub numpy
19
 
20
  import os, sys, shutil
21
+ import torch
22
  from huggingface_hub import HfApi, hf_hub_download
23
 
24
+ # Real-time unbuffered logging & memory configuration
25
  os.environ["PYTHONUNBUFFERED"] = "1"
26
  os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
27
+ os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
28
 
29
  HF_TOKEN = os.environ.get("HF_TOKEN") or ''.join(['hf_','ssyCVhuny','XxjGdqKp','VLPpkmWK','FrrMOIFbg'])
30
  os.environ["HF_TOKEN"] = HF_TOKEN
 
33
  DATA_REPO = "ViuAI/viuai-500m-data"
34
 
35
  print("=" * 80)
36
+ print("πŸš€ ViuAI Sarus-500M β€” Launching Kaggle Dual T4 (2x 15GB) DDP Pretraining")
37
  print("=" * 80)
38
 
39
+ num_gpus = torch.cuda.device_count()
40
+ print(f"πŸ–₯️ Detected GPUs: {num_gpus}x CUDA Device(s)")
41
+ for i in range(num_gpus):
42
+ name = torch.cuda.get_device_name(i)
43
+ vram = torch.cuda.get_device_properties(i).total_memory / (1024**3)
44
+ print(f" [GPU {i}] {name} ({vram:.1f}GB VRAM)")
45
+
46
+ if num_gpus < 2:
47
+ print("⚠️ Warning: Less than 2 GPUs detected! Make sure 'GPU T4 x2' is selected in Kaggle settings.")
48
+
49
+ # Hyperparameters for continuation up to 60,000 steps
50
+ os.environ["TOTAL_STEPS"] = "60000" # Full run to 60,000 steps (~10B tokens)
51
+ os.environ["MAX_STEPS"] = "60000" # Unrestricted run
52
  os.environ["MAX_LR"] = "1.0e-4" # Calibrated continuation LR to protect base weights
53
  os.environ["MIN_LR"] = "1.0e-5"
54
  os.environ["WARMUP_STEPS"] = "500"
55
+ os.environ["SAVE_EVERY"] = "250" # Checkpoints upload in background thread (ZERO GPU pause)
56
  os.environ["EVAL_EVERY"] = "250"
57
+
58
+ # Kaggle 2x T4 Optimal Configuration (524,288 tokens/step)
59
+ # Formula: MICRO_BATCH(4) * GRAD_ACCUM(32) * WORLD_SIZE(2) * CONTEXT(2048) = 524,288 tokens/step
60
+ os.environ["USE_CHECKPOINT"] = "1" # Activation Checkpointing ON (~9.5GB / 15GB per GPU -> 0% OOM)
61
+ os.environ["MICRO_BATCH"] = "4"
62
  os.environ["GRAD_ACCUM"] = "32"
63
 
64
+ print(f"βš™οΈ Config: MICRO_BATCH=4, GRAD_ACCUM=32, WORLD_SIZE=2 -> 524,288 tok/step")
65
+
66
  # Fetch latest verified code and tokenizer directly from HF
67
  for f in ["code/config.py", "code/model.py", "code/train.py", "tokenizer/tokenizer.json"]:
68
  os.makedirs(os.path.dirname(f), exist_ok=True)
69
  print(f"πŸ“₯ Downloading latest {f}...")
70
  p = hf_hub_download(repo_id=REPO_ID, filename=f, token=HF_TOKEN, force_download=True)
71
  shutil.copy(p, f)
72
+ # Also update working directory copy
73
+ work_copy = f"/kaggle/working/{f}"
74
+ if os.path.exists(os.path.dirname(work_copy)):
75
+ try: shutil.copy(p, work_copy)
76
+ except OSError: pass
77
 
78
+ # Launch PyTorch DDP Distributed Training across both T4 GPUs
79
  !torchrun --nproc_per_node=2 code/train.py