当前位置:网站首页>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
边栏推荐
- Introduction to the implementation principle of rxjs observable filter operator
- 父亲和篮球
- pytorch 载入历史模型时更换gpu卡号,map_location设置
- Mobile phones and computers can be used, whole people, spoof code connections, "won't you Baidu for a while" teach you to use Baidu
- 顺序表(C语言实现)
- ThreadPoolExecutor realizes multi-threaded concurrency and obtains the return value (elegant and concise way)
- JSP and filter
- Today's sleep quality record 77 points
- Logseq 评测:优点、缺点、评价、学习教程
- PowerPoint tutorial, how to save a presentation as a video in PowerPoint?
猜你喜欢

Students who do not understand the code can also send their own token, which is easy to learn BSC

Kivy教程之 盒子布局 BoxLayout将子项排列在垂直或水平框中(教程含源码)

2022-02-14 analysis of the startup and request processing process of the incluxdb cluster Coordinator

Introduction to the implementation principle of rxjs observable filter operator

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

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

Box layout of Kivy tutorial BoxLayout arranges sub items in vertical or horizontal boxes (tutorial includes source code)

Flink code is written like this. It's strange that the window can be triggered (bad programming habits)

Annotation and reflection

This math book, which has been written by senior ml researchers for 7 years, is available in free electronic version
随机推荐
开始报名丨CCF C³[email protected]奇安信:透视俄乌网络战 —— 网络空间基础设施面临的安全对抗与制裁博弈...
MySQL functions and related cases and exercises
Cadre de logback
Flink SQL knows why (19): the transformation between table and datastream (with source code)
php:  The document cannot be displayed in Chinese
Flink SQL knows why (16): dlink, a powerful tool for developing enterprises with Flink SQL
The shortage of graphics cards finally came to an end: 3070ti for more than 4000 yuan, 2000 yuan cheaper than the original price, and 3090ti
8皇后问题
pytorch 载入历史模型时更换gpu卡号,map_location设置
Flink SQL knows why (7): haven't you even seen the ETL and group AGG scenarios that are most suitable for Flink SQL?
2022-02-11 heap sorting and recursion
Resource Cost Optimization Practice of R & D team
Smbms project
Libuv Library - Design Overview (Chinese version)
(first) the most complete way to become God of Flink SQL in history (full text 180000 words, 138 cases, 42 pictures)
网上开户哪家证券公司佣金最低,我要开户,网上客户经理开户安全吗
18W word Flink SQL God Road manual, born in the sky
Spark实战1:单节点本地模式搭建Spark运行环境
Kivy教程之 盒子布局 BoxLayout将子项排列在垂直或水平框中(教程含源码)
R语言使用data函数获取当前R环境可用的示例数据集:获取datasets包中的所有示例数据集、获取所有包的数据集、获取特定包的数据集