python - 如何知道 pytorch 中使用了多少 GPU?
问题描述
我用来启动培训的 bash 文件如下所示:
CUDA_VISIBLE_DEVICES=3,4 python -m torch.distributed.launch \
--nproc_per_node=2 train.py \
--batch_size 6 \
--other_args
我发现每个 GPU 中张量的批量大小实际上是batch_size / num_of_gpu
= 6/2
= 3。
当我初始化我的网络时,我需要知道每个 GPU 的批量大小。(Ps. 在这个阶段,我不能input_tensor.shape
用来获取批量维度的大小,因为 jet 中没有数据。)
不知何故,我找不到 pytorch 将参数存储在哪里--nproc_per_node
。那么我怎么能知道使用了多少 GPU,而无需手动传递呢--other_args
?
解决方案
我认为您正在寻找torch.distributed.get_world_size()
- 这将告诉您创建了多少进程。
推荐阅读
- shell - 源文件移动到 unix 中的存档文件夹
- c# - 卡巴斯基将 C# 应用程序检测为特洛伊木马病毒 (VHO:Trojan.MSIL.Convagent.gen)
- python - 使用 webbrowser 而不是 Selenium
- c++ - 具有先前模板参数类型的自动返回类型实参的函数类型的模板参数
- discord.js - 我在将这两个代码组合在一起时遇到问题:
- https - aks agic 中的入口重写规则给出 502
- google-apps-script - 在嵌入式组合图表的图例中隐藏一些系列
- javascript - 停用记录时禁用 Dynamics 365 中的确认弹出窗口
- php - CodeIgniter 和 angularjs 中的上传文件错误
- java - 如何解决这个错误?!在 android studio 中遇到问题