ViuAI commited on
Commit
7d4c3f5
·
verified ·
1 Parent(s): 20ebd23

perf: disable grad_ckpt on T4 and enlarge loss chunk_size to 2048 for 10k+ tok/s

Browse files
model/configs/train_kaggle_t4.yaml CHANGED
@@ -44,10 +44,10 @@ weight_decay: 0.1
44
  betas: [0.9, 0.95]
45
  grad_clip: 1.0
46
 
47
- # Automatic FP16 on T4 + GradScaler + PagedAdamW8bit + Grad Checkpointing (100% Stable)
48
  amp: auto
49
  optimizer: paged_adamw_8bit
50
- grad_ckpt: true
51
 
52
  compile: false
53
  fp8: false
 
44
  betas: [0.9, 0.95]
45
  grad_clip: 1.0
46
 
47
+ # Automatic FP16 on T4 + GradScaler + PagedAdamW8bit (Maximum speed: grad_ckpt off for ~10k+ tok/s)
48
  amp: auto
49
  optimizer: paged_adamw_8bit
50
+ grad_ckpt: false
51
 
52
  compile: false
53
  fp8: false
model/scripts/train.py CHANGED
@@ -718,6 +718,8 @@ def main():
718
  ap.add_argument("--muon_weight_decay", type=float, default=None, help="Muon weight decay override (default: 0.01)")
719
  ap.add_argument("--compile", action="store_true", help="torch.compile on (10-30%% free speedup, default off)")
720
  ap.add_argument("--fp8", action="store_true", help="torchao Float8 training (Blackwell/5090 only, EXPERIMENTAL)")
 
 
721
  args = ap.parse_args()
722
 
723
  base = Path(__file__).parent
@@ -1505,14 +1507,18 @@ def main():
1505
  {"params": no_decay_params, "weight_decay": 0.0},
1506
  ]
1507
 
1508
- if bool(C("grad_ckpt", False)):
 
1509
  target = model.module if hasattr(model, "module") else model
1510
  if hasattr(target, "gradient_checkpointing_enable"):
1511
  target.gradient_checkpointing_enable()
1512
  if R0:
1513
- print("[model] gradient checkpointing enabled (VRAM activation memory halved for 48L)")
1514
  elif R0:
1515
  print("[model] WARN: grad_ckpt requested but model has no gradient_checkpointing_enable()")
 
 
 
1516
 
1517
  opt_name = str(args.optimizer or C("optimizer", "adamw")).lower()
1518
  if opt_name == "muon":
 
718
  ap.add_argument("--muon_weight_decay", type=float, default=None, help="Muon weight decay override (default: 0.01)")
719
  ap.add_argument("--compile", action="store_true", help="torch.compile on (10-30%% free speedup, default off)")
720
  ap.add_argument("--fp8", action="store_true", help="torchao Float8 training (Blackwell/5090 only, EXPERIMENTAL)")
721
+ ap.add_argument("--grad_ckpt", dest="grad_ckpt", action="store_true", default=None, help="Enable gradient checkpointing")
722
+ ap.add_argument("--no_grad_ckpt", "--no-grad-ckpt", dest="grad_ckpt", action="store_false", help="Disable gradient checkpointing for maximum speed")
723
  args = ap.parse_args()
724
 
725
  base = Path(__file__).parent
 
1507
  {"params": no_decay_params, "weight_decay": 0.0},
1508
  ]
1509
 
1510
+ use_gc = args.grad_ckpt if args.grad_ckpt is not None else bool(C("grad_ckpt", False))
1511
+ if use_gc:
1512
  target = model.module if hasattr(model, "module") else model
1513
  if hasattr(target, "gradient_checkpointing_enable"):
1514
  target.gradient_checkpointing_enable()
1515
  if R0:
1516
+ print("[model] gradient checkpointing enabled")
1517
  elif R0:
1518
  print("[model] WARN: grad_ckpt requested but model has no gradient_checkpointing_enable()")
1519
+ else:
1520
+ if R0 and not args.smoke:
1521
+ print("[model] gradient checkpointing DISABLED (pure maximum FLOP speed, zero backward recomputation)")
1522
 
1523
  opt_name = str(args.optimizer or C("optimizer", "adamw")).lower()
1524
  if opt_name == "muon":
model/scripts/viu1_dense.py CHANGED
@@ -141,7 +141,7 @@ class Attention(nn.Module):
141
  v = v.transpose(1, 2)
142
  drop_p = self.drop.p if self.training else 0.0
143
  if self.sliding:
144
- causal = self._get_mask(T, x.device)
145
  attn_out = F.scaled_dot_product_attention(q, k, v, attn_mask=causal, dropout_p=drop_p)
146
  else:
147
  attn_out = F.scaled_dot_product_attention(q, k, v, is_causal=True, dropout_p=drop_p)
@@ -244,7 +244,7 @@ class Viu1Dense(nn.Module):
244
  if targets is not None:
245
  flat_h = h.reshape(-1, self.args.dim)
246
  flat_tgt = targets.reshape(-1)
247
- chunk_size = 2048 if (h.is_cuda and torch.cuda.get_device_properties(h.device).total_memory > 16 * 1024**3) else 512
248
  n_tokens = flat_tgt.numel()
249
  total_loss = 0.0
250
  for ci in range(0, n_tokens, chunk_size):
 
141
  v = v.transpose(1, 2)
142
  drop_p = self.drop.p if self.training else 0.0
143
  if self.sliding:
144
+ causal = self._get_mask(T, x.device).to(dtype=q.dtype)
145
  attn_out = F.scaled_dot_product_attention(q, k, v, attn_mask=causal, dropout_p=drop_p)
146
  else:
147
  attn_out = F.scaled_dot_product_attention(q, k, v, is_causal=True, dropout_p=drop_p)
 
244
  if targets is not None:
245
  flat_h = h.reshape(-1, self.args.dim)
246
  flat_tgt = targets.reshape(-1)
247
+ chunk_size = 2048 if (h.is_cuda and torch.cuda.get_device_properties(h.device).total_memory >= 14 * 1024**3) else 512
248
  n_tokens = flat_tgt.numel()
249
  total_loss = 0.0
250
  for ci in range(0, n_tokens, chunk_size):