Properly guard PyTorch stuff
# What does this PR do?

#23438 accidentally broke main since the objects in `.generation` imported are only available when PyTorch is installed. This PR fixes that.
_The documentation is not available anymore as the PR was closed or merged._