Cion-lab commited on
Commit
a477d8d
·
verified ·
1 Parent(s): 182a8d9

train: --grad-ckpt, and record attn/grad_ckpt in every result line

Browse files
Files changed (1) hide show
  1. train/train_ounce100m.py +14 -4
train/train_ounce100m.py CHANGED
@@ -178,6 +178,9 @@ def run_benchmark(args, model, dataset, steps, world, seqs_per_step):
178
  if world > 1 and not dist.is_initialized():
179
  dist.init_process_group("nccl")
180
  model = model.to(device)
 
 
 
181
  net = DDP(model, device_ids=[local_rank]) if world > 1 else model
182
 
183
  opt = torch.optim.AdamW(net.parameters(), lr=args.lr, betas=(0.9, 0.95),
@@ -214,7 +217,8 @@ def run_benchmark(args, model, dataset, steps, world, seqs_per_step):
214
  "seconds": round(sec, 1), "tokens": toks,
215
  "peak_gpu_gb": round(torch.cuda.max_memory_allocated() / 1e9, 2),
216
  "world": world, "seq_len": args.seq_len, "micro_batch": args.micro_batch,
217
- "attn": args.attn, "params": sum(p.numel() for p in model.parameters())}
 
218
  print("BENCH_JSON " + json.dumps(res, sort_keys=True), flush=True)
219
  if world > 1:
220
  dist.barrier()
@@ -230,8 +234,11 @@ def main():
230
  ap.add_argument("--hub-repo-type", default="dataset", choices=["dataset", "model"])
231
  ap.add_argument("--seq-len", type=int, default=2048)
232
  ap.add_argument("--attn", default="eager", choices=["eager", "sdpa", "flash_attention_2"],
233
- help="p0c measured eager beating SDPA on Turing; flash_attention_2 needs sm80+ and "
234
- "is not available on a T4")
 
 
 
235
  ap.add_argument("--layers", type=int, default=0)
236
  ap.add_argument("--hidden", type=int, default=0)
237
  ap.add_argument("--micro-batch", type=int, default=2)
@@ -386,7 +393,9 @@ def main():
386
  num_train_epochs=1,
387
  max_steps=0 if args.dry_run else steps_planned,
388
  fp16=True, bf16=False,
389
- gradient_checkpointing=False, # measure before needing it; docs/01-plan.md §6
 
 
390
  ddp_find_unused_parameters=False,
391
  dataloader_num_workers=2,
392
  dataloader_pin_memory=False,
@@ -496,6 +505,7 @@ def main():
496
  "micro_batch": args.micro_batch, "seq_len": args.seq_len,
497
  "accum": args.accum, "world": world,
498
  "params": pc["sum_numel"], "attn": args.attn,
 
499
  "effective_attn": eff_attn,
500
  "peak_gpu_gb": peak_gb()}, sort_keys=True))
501
 
 
178
  if world > 1 and not dist.is_initialized():
179
  dist.init_process_group("nccl")
180
  model = model.to(device)
181
+ if args.grad_ckpt:
182
+ model.gradient_checkpointing_enable()
183
+ model.config.use_cache = False
184
  net = DDP(model, device_ids=[local_rank]) if world > 1 else model
185
 
186
  opt = torch.optim.AdamW(net.parameters(), lr=args.lr, betas=(0.9, 0.95),
 
217
  "seconds": round(sec, 1), "tokens": toks,
218
  "peak_gpu_gb": round(torch.cuda.max_memory_allocated() / 1e9, 2),
219
  "world": world, "seq_len": args.seq_len, "micro_batch": args.micro_batch,
220
+ "attn": args.attn, "grad_ckpt": bool(args.grad_ckpt),
221
+ "params": sum(p.numel() for p in model.parameters())}
222
  print("BENCH_JSON " + json.dumps(res, sort_keys=True), flush=True)
223
  if world > 1:
224
  dist.barrier()
 
234
  ap.add_argument("--hub-repo-type", default="dataset", choices=["dataset", "model"])
235
  ap.add_argument("--seq-len", type=int, default=2048)
236
  ap.add_argument("--attn", default="eager", choices=["eager", "sdpa", "flash_attention_2"],
237
+ help="p0c measured eager beating SDPA on Turing; Gate 3 P2/A-B measured +52 % for "
238
+ "eager at seq 1024 and an OOM at 2048. flash_attention_2 needs sm80+ and is not "
239
+ "available on a T4")
240
+ ap.add_argument("--grad-ckpt", action="store_true",
241
+ help="trade ~30%% recompute for activation memory; the only route to eager at 2048")
242
  ap.add_argument("--layers", type=int, default=0)
243
  ap.add_argument("--hidden", type=int, default=0)
244
  ap.add_argument("--micro-batch", type=int, default=2)
 
393
  num_train_epochs=1,
394
  max_steps=0 if args.dry_run else steps_planned,
395
  fp16=True, bf16=False,
396
+ # measured decision, not a default: A-B found eager attention 52 % faster at seq 1024 and OOM at
397
+ # 2048; checkpointing is what makes eager at 2048 possible at all, at the cost of a recompute pass
398
+ gradient_checkpointing=args.grad_ckpt,
399
  ddp_find_unused_parameters=False,
400
  dataloader_num_workers=2,
401
  dataloader_pin_memory=False,
 
505
  "micro_batch": args.micro_batch, "seq_len": args.seq_len,
506
  "accum": args.accum, "world": world,
507
  "params": pc["sum_numel"], "attn": args.attn,
508
+ "grad_ckpt": bool(args.grad_ckpt),
509
  "effective_attn": eff_attn,
510
  "peak_gpu_gb": peak_gb()}, sort_keys=True))
511