In this example it wouldn’t change the behavior, and the optimizer will just skip all parameters without a gradient.
However, “explicit is better than implicit” according to the Python Zen, so the the first approach might be cleaner.
There are some edge cases, where e.g. a parameter was trained, then frozen and should therefore not be updated anymore.
However, if you are using weight decay, this "frozen’ parameter might still be updated.
As you can see, this is not the usual use case, but might create some headache while debugging.