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

天津建设银行网站首页棋牌源码之家

天津建设银行网站首页,棋牌源码之家,wordpress模板2zzt,长沙生活信息网pytorch单精度、半精度、混合精度、单卡、多卡#xff08;DP / DDP#xff09;、FSDP、DeepSpeed#xff08;环境没搞起来#xff09;模型训练代码#xff0c;并对比不同方法的训练速度以及GPU内存的使用 代码#xff1a;pytorch_model_train FairScale#xff08;你真…pytorch单精度、半精度、混合精度、单卡、多卡DP / DDP、FSDP、DeepSpeed环境没搞起来模型训练代码并对比不同方法的训练速度以及GPU内存的使用 代码pytorch_model_train FairScale你真的需要FSDP、DeepSpeed吗 在了解各种训练方式之前先来看一下 FairScale 给出的一个模型训练方式选择的流程选择适合自己的方式就是最好的。 训练环境设置 模型预训练的Resnet50数据集Cifar10硬件资源一台4卡Tesla P40训练设置5 epoch、128 batch size观察指标显存占用、GPU使用率、训练时长、模型训练结果 备注 由于P40硬件限制不支持半精度fp16的训练在fp16条件下训练的速度会受到影 响ResNet50模型较小batch_size1时单卡仅占用 0.34G显存绝大部分显存都被输入数据以及中间激活占用 测试基准batch_size1 单卡显存占用0.34 G单卡GPU使用率峰值60% 单卡单精度训练 代码文件pytorch_SingleGPU.py单卡显存占用11.24 G单卡GPU使用率峰值100%训练时长5 epoch1979 s训练结果准确率85%左右 单卡半精度训练 代码文件pytorch_half_precision.py单卡显存占用5.79 G单卡GPU使用率峰值100%训练时长5 epoch1946 s训练结果准确率75%左右 备注 单卡半精度训练的准确率只有75%单精度的准确率在85%左右 单卡混合精度训练 AUTOMATIC MIXED PRECISION PACKAGE - TORCH.AMP CUDA AUTOMATIC MIXED PRECISION EXAMPLES PyTorch 源码解读之 torch.cuda.amp: 自动混合精度详解 如何使用 PyTorch 进行半精度、混(合)精度训练 如何使用 PyTorch 进行半精度训练 pytorch模型训练之fp16、apm、多GPU模型、梯度检查点gradient checkpointing显存优化等 Working with Multiple GPUs 代码文件pytorch_auto_mixed_precision.py单卡显存占用6.02 G单卡GPU使用率峰值100%训练时长5 epoch1546 s训练结果准确率85%左右 混合精度训练过程 混合精度训练基本流程 维护一个 FP32 数值精度模型的副本在每个iteration 拷贝并且转换成 FP16 模型前向传播FP16 的模型参数loss 乘 scale factor s反向传播FP16 的模型参数和参数梯度参数梯度乘 1/s利用 FP16 的梯度更新 FP32 的模型参数 autocast结合GradScaler用法 # Creates model and optimizer in default precision model Net().cuda() optimizer optim.SGD(model.parameters(), ...)# Creates a GradScaler once at the beginning of training. scaler GradScaler()for epoch in epochs:for input, target in data:optimizer.zero_grad()# Runs the forward pass with autocasting.with autocast(device_typecuda, dtypetorch.float16):output model(input)loss loss_fn(output, target)# Scales loss. Calls backward() on scaled loss to create scaled gradients.# Backward passes under autocast are not recommended.# Backward ops run in the same dtype autocast chose for corresponding forward ops.scaler.scale(loss).backward()# scaler.step() first unscales the gradients of the optimizers assigned params.# If these gradients do not contain infs or NaNs, optimizer.step() is then called,# otherwise, optimizer.step() is skipped.scaler.step(optimizer)# Updates the scale for next iteration.scaler.update()基于GradScaler进行梯度裁剪 scaler.scale(loss).backward() scaler.unscale_(optimizer) torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm) scaler.step(optimizer) scaler.update()autocast用法 # Creates some tensors in default dtype (here assumed to be float32) a_float32 torch.rand((8, 8), devicecuda) b_float32 torch.rand((8, 8), devicecuda) c_float32 torch.rand((8, 8), devicecuda) d_float32 torch.rand((8, 8), devicecuda)with torch.autocast(device_typecuda):# torch.mm is on autocasts list of ops that should run in float16.# Inputs are float32, but the op runs in float16 and produces float16 output.# No manual casts are required.e_float16 torch.mm(a_float32, b_float32)# Also handles mixed input typesf_float16 torch.mm(d_float32, e_float16)# After exiting autocast, calls f_float16.float() to use with d_float32 g_float32 torch.mm(d_float32, f_float16.float())autocast嵌套使用 # Creates some tensors in default dtype (here assumed to be float32) a_float32 torch.rand((8, 8), devicecuda) b_float32 torch.rand((8, 8), devicecuda) c_float32 torch.rand((8, 8), devicecuda) d_float32 torch.rand((8, 8), devicecuda)with torch.autocast(device_typecuda):e_float16 torch.mm(a_float32, b_float32)with torch.autocast(device_typecuda, enabledFalse):# Calls e_float16.float() to ensure float32 execution# (necessary because e_float16 was created in an autocasted region)f_float32 torch.mm(c_float32, e_float16.float())# No manual casts are required when re-entering the autocast-enabled region.# torch.mm again runs in float16 and produces float16 output, regardless of input types.g_float16 torch.mm(d_float32, f_float32)4卡 DPData Parallel 代码文件pytorch_DP.py单卡显存占用3.08 G单卡GPU使用率峰值99%训练时长5 epoch742 s训练结果准确率85%左右 4卡 DDPDistributed Data Parallel pytorch-multi-gpu-training /ddp_train.py DISTRIBUTED COMMUNICATION PACKAGE - TORCH.DISTRIBUTED 代码文件pytorch_DDP.py单卡显存占用3.12 G单卡GPU使用率峰值99%训练时长5 epoch560 s训练结果准确率85%左右 代码启动命令单机 4 GPU python -m torch.distributed.launch --nproc_per_node4 --nnodes1 pytorch_DDP.py 基于accelerate的 DDP huggingface/accelerate Hugging Face开源库accelerate详解 代码文件accelerate_DDP.py单卡显存占用3.15 G单卡GPU使用率峰值99%训练时长5 epoch569 s训练结果准确率85%左右 accelerate配置文件default_DDP.yml compute_environment: LOCAL_MACHINE distributed_type: MULTI_GPU downcast_bf16: no gpu_ids: all machine_rank: 0 main_training_function: main mixed_precision: no num_machines: 1 num_processes: 4 rdzv_backend: static same_network: true tpu_env: [] tpu_use_cluster: false tpu_use_sudo: false use_cpu: false代码启动命令单机 4 GPU accelerate launch --config_file ./config/default_DDP.yml accelerate_DDP.py Pytorch FSDPFully Sharded Data Parallel Pytorch FULLY SHARDED DATA PARALLEL (FSDP) 初识 2023 年了大模型训练还要不要用 PyTorch 的 FSDP GETTING STARTED WITH FULLY SHARDED DATA PARALLEL(FSDP) batch_size 1 单卡显存占用0.19 G相比基准测试的 0.34G 有减少但是没有达到4倍单卡GPU使用率峰值60% batch_size 128 单卡显存占用2.88 G单卡GPU使用率峰值99% 代码文件pytorch_FSDP.py 训练时长5 epoch581 s 训练结果准确率85%左右 备注 pytorch里面的FSDP的batchsize是指单张卡上的batch大小 代码启动命令单机 4 GPU python -m torch.distributed.launch --nproc_per_node4 --nnodes1 pytorch_FSDP.py FSDP包装后的模型 代码中指定对Resnet50中的Linear和Conv2d层应用FSDP。 基于accelerate的 FSDPFully Sharded Data Parallel batch_size 1 单卡显存占用0.38 G相比基准测试的 0.34G 并没有减少单卡GPU使用率峰值60% batch_size 128 单卡显存占用2.90 G单卡GPU使用率峰值99% 代码文件accelerate_FSDP.py 训练时长5 epoch576 s对于这个小模型速度和DDP相当 训练结果准确率85%左右 accelerate配置文件default_FSDP.yml compute_environment: LOCAL_MACHINE distributed_type: FSDP downcast_bf16: no fsdp_config:fsdp_auto_wrap_policy: SIZE_BASED_WRAPfsdp_backward_prefetch_policy: BACKWARD_PREfsdp_forward_prefetch: truefsdp_min_num_params: 1000000fsdp_offload_params: falsefsdp_sharding_strategy: 1fsdp_state_dict_type: SHARDED_STATE_DICTfsdp_sync_module_states: truefsdp_use_orig_params: true machine_rank: 0 main_training_function: main mixed_precision: no num_machines: 1 num_processes: 4 rdzv_backend: static same_network: true tpu_env: [] tpu_use_cluster: false tpu_use_sudo: false use_cpu: false代码启动命令单机 4 GPU accelerate launch --config_file ./config/default_FSDP.yml accelerate_FSDP.py Pytorch DeepSpeed环境没搞起来哈哈哈 [BUG] error: unrecognized arguments: --deepspeed ./ds_config.json #3961 fused_adam.so: cannot open shared object file: No such file or directory #119 DeepSpeedExamples/training/cifar/ Getting Started 代码文件pytorch_DeepSpeed.py 单卡显存占用 单卡GPU使用率峰值 训练时长5 epoch 训练结果 代码启动命令单机 4 GPU deepspeed pytorch_DeepSpeed.py --deepspeed_config ./config/zero_stage2_config.json 基于accelerate的 DeepSpeed环境没搞起来哈哈哈 DeepSpeed介绍 深度解析如何使用DeepSpeed加速PyTorch模型训练 DeepSpeed 代码文件accelerate_DeepSpeed.py单卡显存占用单卡GPU使用率峰值训练时长5 epoch训练结果
http://www.hkea.cn/news/14421897/

相关文章:

  • 无锡手机网站建设报价谷歌浏览器下载安装
  • 网站运营实训报告总结中山做网站联系电话
  • 网站设计开发建设公司中小企业管理课程培训
  • 建设厅网站预算员报名时间wordpress e
  • 杨浦专业做网站wordpress 文章显示全文
  • 北京城建设计院网站免费网站教程
  • 中文网站外链查询工具百度广告投放公司
  • 建设网站买的空间是服务器吗jquery 打开新网站
  • 哪个网站做图文素材多郑州网站建设培训
  • 外贸自己做网站梅州建站
  • 网站备案核验单怎么填wordpress 如何优化
  • 建设厅查询网站网站图片下载 代码
  • 网站建设平台 三合一柳州市建设中心网站首页
  • 温州做网站价格wordpress微信机器人高级版
  • 网站建设目标是什么意思长春网站制作诚推源晟
  • 广州网站建设(信科分公司)软件研发工程师
  • 手机网站字体大小自适应线上推广平台有哪些
  • 青岛 网站制作linux服务器怎么做网站
  • 最便宜的网站建设网站备案负责人幕布照
  • 云南省做网站开发的公司排名微网站建设方案
  • 怎么快速建立一个网站扬中网站推广报价
  • 电子商务网站设计物流方案业务外包
  • 做网站怎么不被找到怎样自己做网站卖钱
  • 学seo建网站南通市住房和建设局网站
  • 做色流网站要注意什么22 wordpress 模板
  • 深圳分销网站设计费用长久新开传奇网站
  • 做英语四级题的网站怎么做赌钱网站代理
  • 做排名出租网站免费客户管理软件排行
  • 网站建设的经费哈尔滨网站建设自助建站
  • 银川网站制作报价自定义短网址