当前位置: 首页> 娱乐> 影视 > 网站建站网站299266co_十堰吧_赣州网站建设公司_关键词优化哪家好

网站建站网站299266co_十堰吧_赣州网站建设公司_关键词优化哪家好

时间:2025/7/8 17:12:02来源:https://blog.csdn.net/qq_51234298/article/details/146522930 浏览次数:0次
网站建站网站299266co_十堰吧_赣州网站建设公司_关键词优化哪家好

如标题所示,博主有任务 想要快速上手DDP以测试RDMA介入下的延迟带宽.

环境准备:

验证PyTorch:

python -c "import torch; print(torch.__version__, torch.cuda.device_count())"

核心概念:

进程组:每个GPU对应一个独立进程
​AllReduce:跨卡聚合数据(如梯度)
​torchrun:官方推荐启动工具
在这里插入图片描述

测试两卡all-reduce

看看博主的卡:
在这里插入图片描述

import torch
import torch.distributed as distdist.init_process_group(backend='nccl')
rank = dist.get_rank()
world_size = dist.get_world_size()print(f'I am rank: {rank}  of world {world_size}')input_tensor = torch.rand([1024, 1024, 10], dtype=torch.float).to('cuda:%d' % rank)
input_tensor.fill_(1.0)dist.all_reduce(input_tensor)print(input_tensor[0][0])

结果:
在这里插入图片描述

还想进一步测试不同buffer size下的延迟和带宽情况:

import os
import torch
import torch.distributed as dist
import timeos.environ['MASTER_ADDR'] = '127.0.0.1'
os.environ['MASTER_PORT'] = '29500'dist.init_process_group(backend='nccl')
rank = dist.get_rank()
torch.cuda.set_device(rank)
world_size = dist.get_world_size()buffer_sizes = [1, 1024, 2048, 4096, 8192, 256 * 1024, 512 * 1024, 1024 * 1024, 4 * 1024 * 1024, 256 * 1024 * 1024]def benchmark(size):input_tensor = torch.ones(size, dtype=torch.float32).to(f'cuda:{rank}')torch.cuda.synchronize()start = time.time()dist.all_reduce(input_tensor)torch.cuda.synchronize()elapsed = time.time() - startif rank == 0:data_size = size * 4  # float32占4字节bandwidth = (data_size / elapsed) / (1024**2)  # MB/sprint(f"Size: {size/1024:.1f} KB\tLatency: {elapsed*1000:.3f} ms\tBandwidth: {bandwidth:.2f} MB/s")if rank == 0:print("Buffer Size (KB)\tLatency (ms)\tBandwidth (MB/s)")print("------------------------------------------------")for size in buffer_sizes:benchmark(size)dist.destroy_process_group()

结果:
在这里插入图片描述

至此 单机两卡h20测试成功 带宽延迟符合预期

关键字:网站建站网站299266co_十堰吧_赣州网站建设公司_关键词优化哪家好

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: