grad clipping seems to slightly speed up training in the beginning but i can't see a big difference later in the training. it costs non-negligeable compute to clip. adding it for now because it is standard, and i think more necessary as the model becomes larger. practitioners may consider turning it off for minor efficiency gains

This commit is contained in:
Andrej Karpathy committed 2023-01-27 16:45:09 +00:00
1 parent e0c689cf38
commit 3cb3fc059c
2 files changed
+3 -1

No files matched your search

+3
View File
@@ -59,6 +59,7 @@ max_iters = 600000 # total number of training iterations
weight_decay = 1e-2
beta1 = 0.9
beta2 = 0.95
grad_clip = 1.0 # clip gradients at this value, or disable if == 0.0
# learning rate decay settings
decay_lr = True # whether to decay the learning rate
warmup_iters = 2000 # how many steps to warm up for
@@ -270,6 +271,8 @@ while True:
with ctx:
logits, loss = model(X, Y)
loss.backward()
if grad_clip != 0:
torch.nn.utils.clip_grad_norm_(model.parameters(), grad_clip)
optimizer.step()
optimizer.zero_grad(set_to_none=True)