当前位置:网站首页>Replace the GPU card number when pytorch loads the historical model, map_ Location settings
Replace the GPU card number when pytorch loads the historical model, map_ Location settings
2022-07-03 13:33:00 【Zi Yan Ruoshui】
pytorch When saving the model after training , Will put the equipment number used in the training process ( for example gpu Card number cuda:0 ,cpu) Also preserved . When pytorch When reloading the historical model , The model defaults to the equipment card number during training , Load the weight onto the corresponding card number .
However , Sometimes the equipment conditions of the test process and the training process are inconsistent .
for instance ,A The main engine has four GPU card , And then we use cuda:3 Training models , And save the model .
During the test , We need to be in the customer's B Host running model , however B The host has only one piece gpu card :cuda:0 .
If the model is loaded by default ,pytorch We can't find gpu equipment , Or some other mistake .
here , When loading, you need to make a transformation , by torch.load Appoint gpu How devices are mapped :
according to pytorch Documents , When loading the model , You can specify the tensor Load to a specific target GPU On .
Loading methods are :
>>> torch.load('tensors.pt')
# 1. Load all tensors onto the GPU 0
>>> torch.load('tensors.pt', map_location=torch.device('cuda:0'))
# 2. Load all tensors onto GPU 1
>>> torch.load('tensors.pt', map_location=lambda storage, loc: storage.cuda(1))
# 3. Map tensors from GPU 1 to GPU 0
>>> torch.load('tensors.pt', map_location={'cuda:1':'cuda:0'})
The measured found :
Method 1 It is not loaded into the target card at all , What card did the model originally train on , Or load it onto the original old card number , Therefore, the designation failed .
Method 3, Errors are reported between codes ,location.startswith(‘cuda’): AttributeError: ‘NoneType’ object has no attribute ‘startswitch’, Analyze the code and find that this is torch Their own bug! Cheating father .
Method 2: You can handle it normally tensor All loaded to cuda1 On .
————————————————
Copyright notice : This paper is about CSDN Blogger 「Icoding_F2014」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :https://blog.csdn.net/jmh1996/article/details/111041108
边栏推荐
- Asp.Net Core1.1版本没了project.json,这样来生成跨平台包
- Spark实战1:单节点本地模式搭建Spark运行环境
- Typeerror resolved: argument 'parser' has incorrect type (expected lxml.etree.\u baseparser, got type)
- 双链笔记 RemNote 综合评测:快速输入、PDF 阅读、间隔重复/记忆
- 71 articles on Flink practice and principle analysis (necessary for interview)
- Logback 日志框架
- CVPR 2022 | 美团技术团队精选6篇优秀论文解读
- 编程内功之编程语言众多的原因
- Logseq 评测:优点、缺点、评价、学习教程
- Flink SQL knows why (12): is it difficult to join streams? (top)
猜你喜欢

Error running 'application' in idea running: the solution of command line is too long
[email protected] chianxin: Perspective of Russian Ukrainian cyber war - Security confrontation and sanctions g"/>Start signing up CCF C ³- [email protected] chianxin: Perspective of Russian Ukrainian cyber war - Security confrontation and sanctions g

Flink SQL knows why (XV): changed the source code and realized a batch lookup join (with source code attached)

File uploading and email sending

SQL Injection (POST/Search)

User and group command exercises

Logseq evaluation: advantages, disadvantages, evaluation, learning tutorial

MySQL_ JDBC

Flink SQL knows why (12): is it difficult to join streams? (top)

研发团队资源成本优化实践
随机推荐
JSON serialization case summary
Elk note 24 -- replace logstash consumption log with gohangout
Flutter动态化 | Fair 2.5.0 新版本特性
This math book, which has been written by senior ml researchers for 7 years, is available in free electronic version
untiy世界边缘的物体阴影闪动,靠近远点的物体阴影正常
MapReduce实现矩阵乘法–实现代码
双向链表(我们只需要关注插入和删除函数)
regular expression
已解决TypeError: Argument ‘parser‘ has incorrect type (expected lxml.etree._BaseParser, got type)
Today's sleep quality record 77 points
json序列化时案例总结
SwiftUI 开发经验之作为一名程序员需要掌握的五个最有力的原则
使用tensorflow进行完整的DNN深度神经网络CNN训练完成图片识别案例
Logback log framework
File uploading and email sending
R语言gt包和gtExtras包优雅地、漂亮地显示表格数据:nflreadr包以及gtExtras包的gt_plt_winloss函数可视化多个分组的输赢值以及内联图(inline plot)
Flink code is written like this. It's strange that the window can be triggered (bad programming habits)
Flick SQL knows why (10): everyone uses accumulate window to calculate cumulative indicators
mysql更新时条件为一查询
Error handling when adding files to SVN:.... \conf\svnserve conf:12: Option expected