W3cubDocs

/PyTorch 2.9

device

class torch.cuda.device(device) [source]

Context-manager that changes the selected device.

Parameters

device (torch.device or int) – device index to select. It’s a no-op if this argument is a negative integer or None.

© 2025, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://docs.pytorch.org/docs/2.9/generated/torch.cuda.device.html