Hi,
The .grad field of a Variable is only filled when a gradient is actually computed for this Variable.
You are getting this error because at least one parameter of your model does not have a .grad field, which means that it was not used when computing loss. This can be caused for example if you have an extra nn.Parameter in one of your modules that is not actually used in the forward.
You can change your print to the following to avoid the error:
for p in model.parameters():
    if p.grad is not None:
        print(p.grad.data)