IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 人工智能 -> pytorch通信算子reduce_scatter简介 -> 正文阅读

[人工智能]pytorch通信算子reduce_scatter简介

算子原型

dist.reduce_scatter(output, input_list, op=<ReduceOp.SUM>, group=None, async_op=False)

  • output(tensor): output tensor
  • input_list(list[tensor]): list of tensors to reduce and scatter
  • group(ProcessGroup, optional): the process group to work on, If None, the default process will be used. async_op
  • async_op(bool, optional)

函数功能:

各进程input_list做all_reduce操作,然后scatter到各个output中。

例子

以如下代码为例,各进程中的input_list是[0,1,2,3],
all_reduce完之后是[0,4,8,12]
scatter到各个进程中的output分别是[0,4,8,12]

import os
import torch
import torch.distributed as dist
from torch.multiprocessing import Process

os.environ['MASTER_ADDR'] = '127.0.0.1'
os.environ['MASTER_PORT'] = '29500'
backend = 'nccl'
dist.init_process_group(backend)
rank = dist.get_rank()

# simple dist
if rank == 0:
    print("pid is {}, rank is {}".format(os.getpid(), rank))
else:
    print("pid is {}, rank is {}".format(os.getpid(), rank))

torch.cuda.set_device(rank)
output = torch.tensor(0).to("cuda:{}".format(rank))
input_list = [torch.tensor(var).to("cuda:{}".format(rank)) for var in range(4)]


if rank == 0:
    dist.reduce_scatter(output, input_list, op=dist.ReduceOp.SUM, async_op=False)
else:
    dist.reduce_scatter(output, input_list, op=dist.ReduceOp.SUM, async_op=False)
print('Pid is ', os.getpid(), ', Rank ', rank, ', output is: ', output)

打印信息

Pid is  14230 , Rank  0 , output is:  tensor(0, device='cuda:0')
Pid is  14232 , Rank  2 , output is:  tensor(8, device='cuda:2')
Pid is  14231 , Rank  1 , output is:  tensor(4, device='cuda:1')
Pid is  14233 , Rank  3 , output is:  tensor(12, device='cuda:3')
  人工智能 最新文章
2022吴恩达机器学习课程——第二课(神经网
第十五章 规则学习
FixMatch: Simplifying Semi-Supervised Le
数据挖掘Java——Kmeans算法的实现
大脑皮层的分割方法
【翻译】GPT-3是如何工作的
论文笔记:TEACHTEXT: CrossModal Generaliz
python从零学(六)
详解Python 3.x 导入(import)
【答读者问27】backtrader不支持最新版本的
上一篇文章      下一篇文章      查看所有文章
加:2021-07-28 07:45:54  更:2021-07-28 07:50:35 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年4日历 -2024/4/25 5:38:57-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码