Both would yield the same result. However, in the second approach the optimizer will internally iterate all parameters and skip the ones which don’t require gradients.
This can have a tiny overhead, as this check is not needed in the first approach.