当前位置:网站首页>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
边栏推荐
- JSON serialization case summary
- Logseq 评测:优点、缺点、评价、学习教程
- 2022-02-14 incluxdb cluster write data writetoshard parsing
- 【R】 [density clustering, hierarchical clustering, expectation maximization clustering]
- 【历史上的今天】7 月 3 日:人体工程学标准法案;消费电子领域先驱诞生;育碧发布 Uplay
- json序列化时案例总结
- Error handling when adding files to SVN:.... \conf\svnserve conf:12: Option expected
- Kivy教程之 如何自动载入kv文件
- JSP and filter
- Setting up Oracle datagurd environment
猜你喜欢

When we are doing flow batch integration, what are we doing?

Logseq evaluation: advantages, disadvantages, evaluation, learning tutorial

MySQL installation, uninstallation, initial password setting and general commands of Linux

Unity EmbeddedBrowser浏览器插件事件通讯
![[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion](/img/3b/28327bbf5eb19254f03500a41e2adb.jpg)
[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion

Elk note 24 -- replace logstash consumption log with gohangout

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

Resource Cost Optimization Practice of R & D team

This math book, which has been written by senior ml researchers for 7 years, is available in free electronic version

8皇后问题
随机推荐
[sort] bucket sort
Road construction issues
MySQL constraints
用户和组命令练习
Logback log framework
栈应用(平衡符)
Flink SQL knows why (VIII): the wonderful way to parse Flink SQL tumble window
Swiftui development experience: the five most powerful principles that a programmer needs to master
Convolution emotion analysis task4
Flink SQL knows why (XIV): the way to optimize the performance of dimension table join (Part 1) with source code
JS convert pseudo array to array
【历史上的今天】7 月 3 日:人体工程学标准法案;消费电子领域先驱诞生;育碧发布 Uplay
Anan's doubts
MyCms 自媒体商城 v3.4.1 发布,使用手册更新
今日睡眠质量记录77分
Spark practice 1: build spark operation environment in single node local mode
8 Queen question
Flink SQL knows why (XI): weight removal is not only count distinct, but also powerful duplication
106. How to improve the readability of SAP ui5 application routing URL
This math book, which has been written by senior ml researchers for 7 years, is available in free electronic version