Hi,
It works as expected:
import torch 

inp = torch.rand(5, 10, requires_grad=True)

w1 = torch.rand(10, 1, requires_grad=True)
w0 = torch.rand(1, 1, requires_grad=True)

out = w0 + inp.mm(w1)

out.sum().backward()

print("w1")
print(w1)

print("inp.grad")
print(inp.grad)

Keep in mind here that the first dimension of inp is a “batch” and so the gradient will be w1 repeated as many times as they are elements in the batch.