From (I think) v2.6.0, torch.accelerator.current_accelerator() allows the device to be identified within a function without it being passed as a parameter.
This release added the torch.accelerator package, which allows easier interaction with accelerators / devices.