That should be enough, since output won’t have a valid .grad_fn, which indicates that no computation graph was created.
If you try to call backward() on output, you would get the typical error:
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn

You could also wrap this code snippet in another with torch.no_grad() block just to make sure that no gradient are calculated even if you are using a weight parameter, which might require gradients.