I agree with your that torch.tensor(5.) would seem to be even better here for what you’re trying to achieve.

It seems most concise.
The tensor will be truly a scalar (0-dim) tensor (you’d need to do torch.ones(())) for that.
There isn’t any performance aspect. (e.g. when you’re in the middle of a computation, it’s always good to create the tensor on the right device rather than starting on CPU moving it, but this isn’t applicable here.)
As an aside, torch.full would probably be more natural than torch.ones.

One likely reason this isn’t used as much is that in the very olden days (before 0.4?), PyTorch didn’t have 0-dim tensor support and these things are very hard to get out of people’s heads (like Variable or using torch.Tensor or using .data left and right). It seems people find old code with that an then adapt it so it runs and does what they want (which is, of course, OK and I’m happy when people can make new stuff from old code). I’m sure I’m guilty of not moving all my code to best practices.
Best regards
Thomas