Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

inp = torch.eye(4, 5, requiresgrad=True) out = (inp+1).pow(2).t()…

  1. User

    inp = torch.eye(4, 5, requires_grad=True) out = (inp+1).pow(2).t() out.backward(torch.ones_like(out), retain_graph=True) print(f"First call\n{inp.grad}") out.backward(torch.ones_like(out), retain_graph=True) print(f"\nSecond call\n{inp.grad}") inp.grad.zero_() out.backward(torch.ones_like(out), retain_graph=True) print(f"\nCall after zeroing gradients\n{inp.grad}")

  2. Assistant

    First call tensor([[4., 4., 4., 4., 4.], [4., 4., 4., 4., 4.], [4., 4., 4., 4., 4.], [0., 0., 0., 0., 0.]], grad_fn=)

    Second call tensor([[8., 8., 8., 8., 8.], [8., 8., 8., 8., 8.], [8., 8., 8., 8., 8.], [0., 0., 0., 0., 0.]], grad_fn=)

    Call after zeroing gradients tensor([[4., 4., 4., 4., 4.], [4., 4., 4., 4., 4.], [4., 4., 4., 4., 4.], [0., 0., 0., 0., 0.]])