with torch.no_grad(): for p in model.parameters(): p -= p.grad * lr model.zero_grad()