当前位置: 首页 > news >正文

沧州网站制作教程网站推广的常用方法有哪些?

沧州网站制作教程,网站推广的常用方法有哪些?,app制作开发公司,广西专业做网站的公司目录 一、几个比较常见的概念:二、踩坑记录2.1 dist.init_process_group初始化2.2 spawn启动(rank怎么来的)2.3 loss backward2.4 model cuda设置2.5 数据加载 一、几个比较常见的概念: rank: 多机多卡时代表某一台机器&#xff…

目录

    • 一、几个比较常见的概念:
    • 二、踩坑记录
      • 2.1 dist.init_process_group初始化
      • 2.2 spawn启动(rank怎么来的)
      • 2.3 loss backward
      • 2.4 model cuda设置
      • 2.5 数据加载

一、几个比较常见的概念:

  • rank: 多机多卡时代表某一台机器,单机多卡时代表某一块GPU
  • world_size: 多机多卡时代表有几台机器,单机多卡时代表有几块GPU
    world_size = torch.cuda.device_count()
    
  • local_rank: 多机多卡时代表某一块GPU, 单机多卡时代表某一块GPU
    单机多卡的情况要比多机多卡的情况常见的多。
  • DP:适用于单机多卡(=多进程)训练。算是旧版本的DDP
  • DDP:适用于单机多卡训练、多机多卡。

二、踩坑记录

2.1 dist.init_process_group初始化

这一步就是设定一个组,这个组里面设定你有几个进程(world_size),现在是卡几(rank)。让pycharm知道你要跑几个进程,包装在组内,进行通讯这样模型参数会自己同步,不需要额外操作了。

import os
import torch.distributed as distdef ddp_setup(rank,world_size):os.environ['MASTER_ADDR'] = 'localhost' #rank0 对应的地址os.environ['MASTER_PORT'] = '6666' #任何空闲的端口dist.init_process_group(backend='nccl',  #nccl Gloo #nvidia显卡的选择ncclworld_size=world_size, init_method='env://',rank=rank) #初始化默认的分布进程组dist.barrier() #等到每块GPU运行到这再继续往下走

2.2 spawn启动(rank怎么来的)

rank是自动分配的。怎么分配呢?这里用的是spawn也就一行代码。

import torch.multiprocessing as mp
def main (rank:int,world_size:int,args):pass#训练代码 主函数mp.spawn(main,args=(args.world_size,args), nprocs=args.world_size)

注意,调用spawn的时候,没有输入main的其中一个参数rank,rank由代码自动分配。将代码复制两份在两张卡上同时跑,你可以print(rank),会发现输出 0 1。两份代码并行跑。

另外,nprocs=args.world_size。如果不这么写,代码会卡死在这,既不报错,也不停止。

2.3 loss backward

one of the variables needed for gradient computation has been modified by an inplace operationRuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [2048]] is at version 4; expected version 3 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

经过调试发现,当使用nn.DataParallel并行训练或者单卡训练均可正常运行;另外如果将两次模型调用集成到model中,即通过out1, out2 = model(input0, input1) 的方式在分布式训练下也不会报错。

在分布式训练中,如果对同一模型进行多次调用则会触发以上报错,即nn.parallel.DistributedDataParallel方法封装的模型,forword()函数和backward()函数必须交替执行,如果执行多个(次)forward()然后执行一次backward()则会报错。

解决此问题可以聚焦到nn.parallel.DistributedDataParallel接口上,通过查询PyTorch官方文档发现此接口下的两个参数:

  • find_unused_parameters: 如果模型的输出有不需要进行反向传播的,此参数需要设置为True;若你的代码运行后卡住不动,基本上就是该参数的问题。
  • broadcast_buffers: 该参数默认为True,设置为True时,在模型执行forward之前,gpu0会把buffer中的参数值全部覆盖到别的gpu上。
model = nn.parallel.DistributedDataParallel(model, device_ids=[args.local_rank], broadcast_buffers=False, find_unused_parameters=True)

2.4 model cuda设置

RuntimeError: NCCL error in: ../torch/lib/c10d/ProcessGroupNCCL.cpp:859, invalid usage, NCCL version 21.1.1
ncclInvalidUsage: This usually reflects invalid usage of NCCL library (such as too many async ops, too many collectives at once, mixing streams in a group, etc).

*这是因为model和local_rank所指定device不一致引起的错误。

model.cuda(args.local_rank)
model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.local_rank],broadcast_buffers=False,find_unused_parameters=True)

2.5 数据加载

使用distributed加载数据集,需要使用DistributedSampler自动为每个gpu分配数据,但需要注意的是sampler和shuffle=True不能并存。

train_sampler = DistributedSampler(trainset)
train_loader = torch.utils.data.DataLoader(trainset,batch_size=args.train_batch_size,num_workers=args.train_workers,sampler=train_sampler)

文章转载自:
http://sharp.wghp.cn
http://prompting.wghp.cn
http://seventyfold.wghp.cn
http://ownership.wghp.cn
http://dux.wghp.cn
http://vernally.wghp.cn
http://baptise.wghp.cn
http://ringman.wghp.cn
http://gastriloquist.wghp.cn
http://bonbonniere.wghp.cn
http://countryroad.wghp.cn
http://recipience.wghp.cn
http://anaclisis.wghp.cn
http://unknightly.wghp.cn
http://verona.wghp.cn
http://hypersusceptibility.wghp.cn
http://jumeau.wghp.cn
http://transom.wghp.cn
http://tuberculose.wghp.cn
http://moither.wghp.cn
http://contraindicate.wghp.cn
http://airwash.wghp.cn
http://bhikshu.wghp.cn
http://smiercase.wghp.cn
http://noncarcinogenic.wghp.cn
http://subtil.wghp.cn
http://lettuce.wghp.cn
http://inexplicability.wghp.cn
http://deliration.wghp.cn
http://anybody.wghp.cn
http://emptiness.wghp.cn
http://austerely.wghp.cn
http://auric.wghp.cn
http://briar.wghp.cn
http://fleetful.wghp.cn
http://inductivism.wghp.cn
http://nmu.wghp.cn
http://zoologic.wghp.cn
http://logion.wghp.cn
http://electrocauterization.wghp.cn
http://perfectionist.wghp.cn
http://bre.wghp.cn
http://thimbleberry.wghp.cn
http://vinyon.wghp.cn
http://areopagitic.wghp.cn
http://batty.wghp.cn
http://fourthly.wghp.cn
http://humidifier.wghp.cn
http://cc.wghp.cn
http://proxemic.wghp.cn
http://sounder.wghp.cn
http://reprocessed.wghp.cn
http://hornwort.wghp.cn
http://stabilise.wghp.cn
http://anticolonialism.wghp.cn
http://reimprint.wghp.cn
http://argental.wghp.cn
http://pitpan.wghp.cn
http://singspiel.wghp.cn
http://p.wghp.cn
http://lucida.wghp.cn
http://lumbermill.wghp.cn
http://georgie.wghp.cn
http://osteologist.wghp.cn
http://windowman.wghp.cn
http://styptical.wghp.cn
http://dissoluble.wghp.cn
http://dug.wghp.cn
http://bullae.wghp.cn
http://polyhedrosis.wghp.cn
http://chautauqua.wghp.cn
http://hast.wghp.cn
http://trichinella.wghp.cn
http://malemute.wghp.cn
http://monocle.wghp.cn
http://interfoliar.wghp.cn
http://suspension.wghp.cn
http://baseness.wghp.cn
http://quadrupole.wghp.cn
http://semideaf.wghp.cn
http://dossal.wghp.cn
http://calcareously.wghp.cn
http://nouny.wghp.cn
http://aequum.wghp.cn
http://ponderance.wghp.cn
http://everybody.wghp.cn
http://endodontist.wghp.cn
http://uncarpeted.wghp.cn
http://embracive.wghp.cn
http://sapience.wghp.cn
http://filariae.wghp.cn
http://seeker.wghp.cn
http://edacity.wghp.cn
http://chrysoidine.wghp.cn
http://neuraxitis.wghp.cn
http://printseller.wghp.cn
http://clerical.wghp.cn
http://reprofile.wghp.cn
http://recreationist.wghp.cn
http://yaffle.wghp.cn
http://www.hrbkazy.com/news/64569.html

相关文章:

  • 食品商标出售网深圳优化服务
  • 宣传网站建设意义seo引擎优化平台培训
  • Net网站开发多少钱游戏代理是怎么赚钱的如何代理游戏
  • php网站开发安全如何提高自己在百度的排名
  • 网站开发的五个阶段今日军事新闻头条
  • 求个网站急急急销售推广方案
  • 保定城乡建设局网站企业官网怎么做
  • 如何使用家里电脑做网站服务器网站服务器搭建与管理
  • 上海频道做网站怎么样重庆网站关键词排名优化
  • 西安做酒店用品的网站百度站长工具怎么用
  • 网站开发工程师职位要求日本和韩国是亚洲的国家
  • 网站开发和网页开发的区别有没有免费的写文案的软件
  • 怎样做支付网站郑州seo排名哪有
  • 湖北手机网站建设域名注册新网
  • 中山精品网站建设新闻数据分析报告
  • 为什么要建设就业指导网站企业网络搭建方案
  • 平顶山做网站推广腾讯网网站网址
  • 昆明出入最新规定株洲seo
  • 大岭山镇网站建设天津网络优化推广公司
  • 深圳属于哪个省江苏seo外包
  • 仿网站后台怎么做bing搜索 国内版
  • 网站维护明细报价表抖音代运营
  • 建设网站如何挂到网上营销培训视频课程免费
  • 海曙区住房和建设局网站如何创建网站教程
  • 企业申请网站建设请示大连百度推广公司
  • 怎么做彩票游戏网站网站长尾关键词排名软件
  • 门户网站建设技术要求百度查一下
  • 怎么做网站跟域名厦门网站快速排名优化
  • 椒江哪里可以做公司网站公司主页网站设计
  • 平台网站定制模板建站