当前位置:网站首页>【torch】: 并行训练并且可以动态设置第一个gpu的batch size
【torch】: 并行训练并且可以动态设置第一个gpu的batch size
2022-06-11 09:49:00 【Jack_Kuo】
问题
再使用torch训练模型的时候,想要使用单机多卡
解决
参照:pytorch多gpu并行训练
需要下载自定义的:data_parallel_my_v2.py
- 网络设置
model = SimcseModel(pretrained_model="./model_save", pooling=args.pooler, dropout=args.dropout)
print("torch.cuda.device_count()", torch.cuda.device_count())
if torch.cuda.device_count() > 1:
gpu0_bsz = int(np.sqrt(args.batch_size))
# 这里设置的gpu0的batch,因为很多时候需要gpu0计算其他的东西,这个消耗会比其他gpu大
print("gpu0_bsz", gpu0_bsz)
acc_grad = 1 # 这里没有设置累计梯度,所以设置为1
print("acc_grad", acc_grad)
from data_parallel_my_v2 import BalancedDataParallel
model = BalancedDataParallel(gpu0_bsz // acc_grad, model, dim=0) # .cuda()
model = model.to(args.device)
2.保存模型时设置
# 多卡gpu训练,保存方式需要做修改
if torch.cuda.device_count() > 1:
model.module.bert.save_pretrained(save_path)
else:
model.bert.save_pretrained(save_path)
边栏推荐
- 远程工作时代的物联网安全
- Flask (II) - route
- ESP8266_ Connect to Alibaba cloud through mqtt protocol
- Q1's revenue exceeded Wall Street's expectations, and the value of Zhiwen group is waiting to return
- ESP8266_ SmartConfig
- Leetcode brushing questions - hand tearing binary tree
- POJ3250「Bad Hair Day」
- rac expdp导出时报错:ORA-31693、ORA-31617、ORA-19505
- What is WSGI?
- 「INS-30131」 安装程序验证所需的初始设置失败
猜你喜欢

Can station B make money?

The difference and relation between machine learning and statistics

document对象

Redis transaction details

ESP8266_GET请求天气预报、json解析

Reconstruction des composants Oracle XDB

LeetCode刷题 —— 手撕二叉树

Oracle 11g RAC disk group has space and cannot add data files?

Troubleshooting the error ora-12545 reported by scanip in Oracle RAC

FPGA基础架构【参考ug998】
随机推荐
优秀测试工程师必备的4项安全测试方法!
ORACLE RAC中连接ScanIP报错ORA-12545的问题解决
js基础--Array对象
科技云报道:Web3.0浪潮下的隐私计算
【clickhouse专栏】新建库角色用户初始化
卸载grid时运行脚本报错Can‘t locate Env.pm in @INC
ESP8266_接入百度物联网核心套件、使用MQTT协议通信
ESP8266_ Connect to Alibaba cloud through mqtt protocol
C+每日练题(15)
Tap and longtap encapsulation of touch events -- from Ono
CVE-2021-40449 NtGdiResetDC UAF
图片规则翻页
An error can't locate env pm in @INC
jedisLock—redis分布式锁实现
面试常问:rem布局,flex布局等
等待事件 enq: KO - fast object checkpoint可行的一些处理方法
How do online app stores of laundry chain stores do?
Monotone stack
document对象
Technology cloud report: privacy computing under the wave of Web3.0