当前位置:网站首页>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
边栏推荐
- Start signing up CCF C ³- [email protected] chianxin: Perspective of Russian Ukrainian cyber war - Security confrontation and sanctions g
- Typeerror resolved: argument 'parser' has incorrect type (expected lxml.etree.\u baseparser, got type)
- CVPR 2022 | interpretation of 6 excellent papers selected by meituan technical team
- Tencent cloud tdsql database delivery and operation and maintenance Junior Engineer - some questions of Tencent cloud cloudlite certification (TCA) examination
- Convolution emotion analysis task4
- rxjs Observable filter Operator 的实现原理介绍
- Flink SQL knows why (17): Zeppelin, a sharp tool for developing Flink SQL
- 已解决(机器学习中查看数据信息报错)AttributeError: target_names
- Flink SQL knows why (7): haven't you even seen the ETL and group AGG scenarios that are most suitable for Flink SQL?
- Multi table query of MySQL - multi table relationship and related exercises
猜你喜欢

Setting up remote links to MySQL on Linux

STM32 and motor development (from MCU to architecture design)

已解决TypeError: Argument ‘parser‘ has incorrect type (expected lxml.etree._BaseParser, got type)

【历史上的今天】7 月 3 日:人体工程学标准法案;消费电子领域先驱诞生;育碧发布 Uplay

2022-02-14 incluxdb cluster write data writetoshard parsing
![[sort] bucket sort](/img/52/95514b5a70cea75821883e016d8adf.jpg)
[sort] bucket sort

Mycms we media mall v3.4.1 release, user manual update

rxjs Observable filter Operator 的实现原理介绍

KEIL5出现中文字体乱码的解决方法

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
随机推荐
Flink SQL knows why (XV): changed the source code and realized a batch lookup join (with source code attached)
Comprehensive evaluation of double chain notes remnote: fast input, PDF reading, interval repetition / memory
Libuv库 - 设计概述(中文版)
【R】 [density clustering, hierarchical clustering, expectation maximization clustering]
Universal dividend source code, supports the dividend of any B on the BSC
Logseq 评测:优点、缺点、评价、学习教程
106. How to improve the readability of SAP ui5 application routing URL
Can newly graduated European college students get an offer from a major Internet company in the United States?
Realize the recognition and training of CNN images, and process the cifar10 data set and other methods through the tensorflow framework
8 Queen question
静态链表(数组的下标代替指针)
Flink SQL knows why (12): is it difficult to join streams? (top)
Tutoriel PowerPoint, comment enregistrer une présentation sous forme de vidéo dans Powerpoint?
显卡缺货终于到头了:4000多块可得3070Ti,比原价便宜2000块拿下3090Ti
Asp. Net core1.1 without project JSON, so as to generate cross platform packages
Convolution emotion analysis task4
2022-02-11 heap sorting and recursion
【被动收入如何挣个一百万】
ThreadPoolExecutor realizes multi-threaded concurrency and obtains the return value (elegant and concise way)
Reptile