for i in range(30000):
    optimizer.zero_grad()
    y = (x-2)**2
    y.backward(retain_graph=True)
    optimizer.step()


19000 tensor(1.7238) tensor(1.00000e-02 *7.6316)
20000 tensor(1.7971) tensor(1.00000e-02 *4.1186)
21000 tensor(1.8638) tensor(1.00000e-02 *1.8556)
22000 tensor(1.9210) tensor(1.00000e-03 *6.2550)
23000 tensor(1.9642) tensor(1.00000e-03 *1.2822)
24000 tensor(1.9896) tensor(1.00000e-04 *1.0800)
25000 tensor(1.9986) tensor(1.00000e-06 *1.8781)
26000 tensor(2.0000) tensor(1.00000e-09 *2.1949)
27000 tensor(2.0000) tensor(1.00000e-11 *7.3669)
28000 tensor(2.0000) tensor(1.00000e-11 *2.7512)
29000 tensor(2.0000) tensor(1.00000e-12 *9.6065)
30000 tensor(2.0000) tensor(1.00000e-12 *3.6380)