Factor out methods
With PyTorch's DataParallel, it is not possible to simply iterate over parameters in order to find the `nn.Module`'s dtype or device.

Some efforts were made to catch the error (`StopIteration`) in most cases, but the some were forgotten. This PR factors the try/except in a method, which is applied everywhere instead.

Closes #10214
@sgugger @patrickvonplaten verified this fixed the issue in #10214