You are freezing all parameters in:
for param in model.parameters():
    param.requires_grad = False

which will yield this error, since the output won’t have a valid grad_fn (no trainable parameters were used calculating the output).