当前位置:网站首页>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
边栏推荐
- php:  The document cannot be displayed in Chinese
- Task5: multi type emotion analysis
- 实现CNN图像的识别和训练通过tensorflow框架对cifar10数据集等方法的处理
- 使用tensorflow进行完整的DNN深度神经网络CNN训练完成图片识别案例
- JSP and filter
- PowerPoint 教程,如何在 PowerPoint 中將演示文稿另存為視頻?
- CVPR 2022 | 美团技术团队精选6篇优秀论文解读
- SQL Injection (POST/Search)
- Red hat satellite 6: better management of servers and clouds
- Swiftui development experience: the five most powerful principles that a programmer needs to master
猜你喜欢

Internet of things completion -- (stm32f407 connects to cloud platform detection data)

常见的几种最优化方法Matlab原理和深度分析

研发团队资源成本优化实践

When updating mysql, the condition is a query

DQL basic query

PowerPoint 教程,如何在 PowerPoint 中將演示文稿另存為視頻?

Mysql database basic operation - regular expression

MySQL functions and related cases and exercises

Kivy教程之 如何自动载入kv文件

Box layout of Kivy tutorial BoxLayout arranges sub items in vertical or horizontal boxes (tutorial includes source code)
随机推荐
ThreadPoolExecutor realizes multi-threaded concurrency and obtains the return value (elegant and concise way)
rxjs Observable filter Operator 的实现原理介绍
Tencent cloud tdsql database delivery and operation and maintenance Junior Engineer - some questions of Tencent cloud cloudlite certification (TCA) examination
Error handling when adding files to SVN:.... \conf\svnserve conf:12: Option expected
This math book, which has been written by senior ml researchers for 7 years, is available in free electronic version
JSP and filter
STM32 and motor development (from MCU to architecture design)
[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
PostgreSQL installation
pytorch 载入历史模型时更换gpu卡号,map_location设置
人身变声器的原理
Flutter动态化 | Fair 2.5.0 新版本特性
【电脑插入U盘或者内存卡显示无法格式化FAT32如何解决】
Flink code is written like this. It's strange that the window can be triggered (bad programming habits)
【被动收入如何挣个一百万】
Unity EmbeddedBrowser浏览器插件事件通讯
In the promotion season, how to reduce the preparation time of defense materials by 50% and adjust the mentality (personal experience summary)
Flutter动态化 | Fair 2.5.0 新版本特性
Resolved (error in viewing data information in machine learning) attributeerror: target_ names
AI 考高数得分 81,网友:AI 模型也免不了“内卷”!