当前位置:网站首页>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
边栏推荐
- MySQL constraints
- Task5: multi type emotion analysis
- regular expression
- Can newly graduated European college students get an offer from a major Internet company in the United States?
- DQL basic query
- Comprehensive evaluation of double chain notes remnote: fast input, PDF reading, interval repetition / memory
- 这本数学书AI圈都在转,资深ML研究员历时7年之作,免费电子版可看
- Disruptor -- a high concurrency and high performance queue framework for processing tens of millions of levels
- Error handling when adding files to SVN:.... \conf\svnserve conf:12: Option expected
- 父亲和篮球
猜你喜欢
Flink SQL knows why (7): haven't you even seen the ETL and group AGG scenarios that are most suitable for Flink SQL?
Flutter动态化 | Fair 2.5.0 新版本特性
2022-02-14 incluxdb cluster write data writetoshard parsing
Flink SQL knows why (XV): changed the source code and realized a batch lookup join (with source code attached)
今日睡眠质量记录77分
Servlet
[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
Resolved (error in viewing data information in machine learning) attributeerror: target_ names
[email protected]奇安信:透视俄乌网络战 —— 网络空间基础设施面临的安全对抗与制裁博弈..."/>
开始报名丨CCF C³[email protected]奇安信:透视俄乌网络战 —— 网络空间基础设施面临的安全对抗与制裁博弈...
Kivy教程之 盒子布局 BoxLayout将子项排列在垂直或水平框中(教程含源码)
随机推荐
2022-02-13 plan for next week
The 35 required questions in MySQL interview are illustrated, which is too easy to understand
MapReduce implements matrix multiplication - implementation code
PowerPoint 教程,如何在 PowerPoint 中將演示文稿另存為視頻?
CVPR 2022 | interpretation of 6 excellent papers selected by meituan technical team
DQL basic query
When we are doing flow batch integration, what are we doing?
Tutoriel PowerPoint, comment enregistrer une présentation sous forme de vidéo dans Powerpoint?
PostgreSQL installation
Flink SQL knows why (VIII): the wonderful way to parse Flink SQL tumble window
Task5: multi type emotion analysis
MapReduce实现矩阵乘法–实现代码
用户和组命令练习
Flick SQL knows why (10): everyone uses accumulate window to calculate cumulative indicators
Reptile
Asp.Net Core1.1版本没了project.json,这样来生成跨平台包
Anan's doubts
AI 考高数得分 81,网友:AI 模型也免不了“内卷”!
JSP and filter
Asp. Net core1.1 without project JSON, so as to generate cross platform packages