日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Pytorch 多GPU数据并行(DataParallel)

發布時間:2023/12/10 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Pytorch 多GPU数据并行(DataParallel) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

利用多個空閑GPU,提高模型訓練推理速度

import torch from gpuinfo import GPUInfo# 查詢空閑GPU gpu_ids = GPUInfo.check_empty() # 設置模型初始化設備 device = torch.device(f"cuda:{str(gpu_ids[0])}" if gpu_ids else "cpu") # 數據并行 model = xxxxxx model = torch.nn.DataParallel(model, device_ids=gpu_ids) # 模型加載到初始化設備中 model = model.to(device) # 模型計算數據并行 for line in dataloader:# 數據不需要加載到相同的設備中moded(line) # ......

DistributedDataParallel 相對于 DataParallel的優勢主要在模型訓練階段,模型推理時由于不涉及參數更新不需要進程間通信,所以推理速度應該相差不大

# The difference between DistributedDataParallel and DataParallel is: # DistributedDataParallel uses multiprocessing where a process is created for each GPU, # while DataParallel uses multithreading. By using multiprocessing, each GPU has its dedicated process, # this avoids the performance overhead caused by GIL of Python interpreter.

模型訓練時分布式多進程數據并行可結合這兩個類改寫
torch.nn.parallel.DistributedDataParallel
torch.utils.data.distributed.DistributedSampler
Distributed Data Parallel
(有時間再寫一版)

總結

以上是生活随笔為你收集整理的Pytorch 多GPU数据并行(DataParallel)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。