torch.cuda.set_device¶ torch.cuda.set_device(device)[source][source]¶ 設定當前裝置。 不建議使用此函式,而應優先考慮使用 device 上下文管理器。在大多數情況下,最好使用 CUDA_VISIBLE_DEVICES 環境變數。 引數 device (torch.device 或 int) – 所選裝置。如果此引數為負數,則此函式不執行任何操作。