Could you please show me how to detach m1? I used the following code but an error happened.
var1 = torch.ones(128, 128, requires_grad=True)
m1 = var1.new_empty((4, *var1.shape), requires_grad=True)
a = torch.linspace(1, 10, 4).reshape(4, 1, 1)

for i in range(10):
    print(i)
    m1.detach()[:] = torch.exp(var1[None, :] * 2)
    l = loss(m1, data)
    l.backward()
    with torch.no_grad():
        var1 -= var1.grad * 0.1
        var1.grad.zero_()
#---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-31-7971284f49be> in <module>
      9     l.backward()
     10     with torch.no_grad():
---> 11         var1 -= var1.grad * 0.1
     12         var1.grad.zero_()

TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'