简体   繁体   English

在 PyTorch 中指定 GPU 设备 ID 的 DistributedDataParallel

[英]DistributedDataParallel with gpu device ID specified in PyTorch

I want to train my model through DistributedDataParallel on a sinle machine that has 8 GPUs.我想在具有 8 个 GPU 的单机上通过 DistributedDataParallel 训练我的模型。 But I want to train my model on four specified GPUs with device IDs 4, 5, 6, 7.但我想在设备 ID 为 4、5、6、7 的四个指定 GPU 上训练我的模型。

How to specify the GPU device ID for DistributedDataParallel?如何为 DistributedDataParallel 指定 GPU 设备 ID?

I think the world size will be 4 for this case, but what should be the rank in this case?我认为在这种情况下世界大小将是 4,但在这种情况下应该是什么等级?

You can set the environment variable CUDA_VISIBLE_DEVICES .您可以设置环境变量CUDA_VISIBLE_DEVICES Torch will read this variable and only use the GPUs specified in there. Torch 将读取此变量并仅使用其中指定的 GPU。 You can either do this directly in your python code like this:您可以直接在 Python 代码中执行此操作,如下所示:

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '4, 5, 6, 7'

Take care to execute this command before you initialize torch in any way, else the statement will not take effect.在您以任何方式初始化 Torch 之前,请注意执行此命令,否则该语句将不会生效。 The other option would be to set the environment variable temporarily before starting your script in the shell:另一个选项是在 shell 中启动脚本之前临时设置环境变量:

CUDA_VISIBLE_DEVICES=4,5,6,7 python your_script.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有不同 GPU 速度的 PyTorch DistributedDataParallel 是否同步权重? - Is PyTorch DistributedDataParallel with different GPU speeds syncing weights? Pytorch CPU CUDA 设备负载无 gpu - Pytorch CPU CUDA device load without gpu 如何在 Pytorch1.1 和 DistributedDataParallel() 中计算米? - How to calculate meters in Pytorch1.1 & DistributedDataParallel()? 在 Amazon SageMaker 上使用 PyTorch DistributedDataParallel 和 Hugging Face - Use PyTorch DistributedDataParallel with Hugging Face on Amazon SageMaker PyTorch ROCm 已出 - 如何将 select Radeon GPU 作为设备 - PyTorch ROCm is out - How to select Radeon GPU as device Pytorch - 在 GPU 上训练时,在设备 1 上的副本 1 中捕获 StopIteration 错误 - Pytorch - Caught StopIteration in replica 1 on device 1 error while Training on GPU Pytorch / 加载优化器的 state dict 时的设备问题(cpu,gpu) - Pytorch / device problem(cpu, gpu) when load state dict for optimizer 为什么我的简单 pytorch 网络不能在 GPU 设备上运行? - Why doesn't my simple pytorch network work on GPU device? pytorch - 如何对张量 \ 模型的设备 (cpu \ gpu) 设置进行故障排除 - pytorch - how to troubleshoot device (cpu \ gpu) settings of tensors \ models 使用 PyTorch DistributedDataParallel 在多个节点上训练时进程卡住 - Process stuck when training on multiple nodes using PyTorch DistributedDataParallel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM