当前位置:网站首页>PyTorch: In-place Operation
PyTorch: In-place Operation
2022-07-05 00:26:00 【harry_ tea】
Contents of this article
In-place Operation
In-place operation stay pytorch Middle refers to support in situ modification tensor, This can avoid new memory overhead , Mainly to reduce the consumption of video memory
But in pytorch When back propagating to get the calculation graph, you need to obtain the value of the intermediate variable , If you use in-place After the operation, the intermediate value is lost , Unable to get calculation diagram , But why are some activation functions written in-place Operation? ?
With ReLU Function as an example , It does not change when the input value is positive in-place Whether it does not affect the result ; When the input is negative, it is 0 No back propagation, so it doesn't affect
common In-place operation
1. Symbolic calculation
*=
+=
Wait for the operation
stay pytorch Try to avoid
tensor = torch.tensor([[1,2,3], [4,5,6]])
print(tensor.data_ptr())
tensor += 2
print(tensor.data_ptr())
tensor = tensor+2
print(tensor.data_ptr())
''' 140430616339712 140430616339712 # in-place 140430616321664 # out-of-place '''
( Continue to supplement )
common Out-of-place operation
1. Symbolic calculation
a=a+b
etc. , Reference resources In-place operation
边栏推荐
- JS how to realize array to tree
- 打新债开户注册安全吗?有没有风险的?靠谱吗?
- lambda expressions
- What did I pay for it transfer to testing post from confusion to firmness?
- Summary of week 22-07-02
- Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
- 《论文笔记》Multi-UAV Collaborative Monocular SLAM
- Netcore3.1 JSON web token Middleware
- IELTS examination process, what to pay attention to and how to review?
- What is the difference between port mapping and port forwarding
猜你喜欢
Detailed explanation of openharmony resource management
Some basic functions of enterprise projects are developed, and important things are saved to online first a
华为200万年薪聘请数据治理专家!背后的千亿市场值得关注
How to use fast parsing to make IOT cloud platform
初识ROS
Significance of acrel EMS integrated energy efficiency platform in campus construction
abc 258 G - Triangle(bitset)
IT转测试岗,从迷茫到坚定我究竟付出了什么?
巩固表达式C# 案例简单变量运算
2022.07.03(LC_6108_解密消息)
随机推荐
Multilingual Wikipedia website source code development part II
两个数相互替换
Microservice
TS quick start - functions
GDB常用命令
(脚本)一键部署redis任意版本 —— 筑梦之路
如果炒股开华泰证券的户,在网上开户安全吗?
Skills in analyzing the trend chart of London Silver
Fast parsing intranet penetration helps enterprises quickly achieve collaborative office
GDB common commands
Actual combat simulation │ JWT login authentication
js如何实现数组转树
abc 258 G - Triangle(bitset)
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
Hologres Query管理及超时处理
海思3559万能平台搭建:YUV422的踩坑记录
[error reporting] "typeerror: cannot read properties of undefined (reading 'split')“
How to do the project of computer remote company in foreign Internet?
ORB(Oriented FAST and Rotated BRIEF)
电力运维云平台:开启电力系统“无人值班、少人值守”新模式