当前位置:网站首页>Understanding of the detach() function of pytorch
Understanding of the detach() function of pytorch
2022-06-13 01:04:00 【kaims】
https://blog.csdn.net/qq_27825451/article/details/95498211
https://blog.csdn.net/weixin_33913332/article/details/93300411?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-4.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-4.no_search_link
detach() & data()
** detach()** Back to a new tensor, It is separated from the current calculation diagram , But it still points to the storage location of the original variable , Its grad_fn=None And requires_grad=False, I got this tensor It is never necessary to calculate its gradient , Without gradient grad, Even if it's later re requires_grad Set as true, It also doesn't have gradients grad.
** Be careful :** Back to tensor And the original tensor Share the same memory data .in-place The function will be modified in two tensor At the same time ( Because they share memory data ), At this point, when you want to call backward() May cause errors .
** data() Functions and detach() ** Same function , But it does not guarantee in-place The security of .
**In-place Correctness check :** be-all tensor Will record what's used on them in-place operations. If pytorch detected tensor In a Function Has been saved for backward, But then it was in-place operations modify . When that happens , stay backward When ,pytorch You're going to report a mistake . This mechanism guarantees , If you use in-place operations, But in backward There is no error reported in the process , Then the gradient calculation is correct .
detach_()
** detach_()** take tensor From the... That created it graph In the separation of , Take it as a leaf node , Its grad_fn=None And requires_grad=False. Same as detach(), but detach_() Is a modification of itself (in-place operation ), and detach() A new tensor.
边栏推荐
- Deep learning model pruning
- MySQL transaction
- 生物解锁--指纹录入流程
- Androi天气
- [JS component] floating text
- How many steps are appropriate for each cycle of deep learning?
- Characteristics of transactions -- atomicity (implementation principle)
- Common skills of quantitative investment - index part 2: detailed explanation of BOL (Bollinger line) index, its code implementation and drawing
- 深度学习训练多少轮?迭代多少次?
- Kotlin collaboration, the life cycle of a job
猜你喜欢

How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of DBCD, ROC, vroc, Cr and psy index strategy income

Quantitative investment traditional index investment decision vs Monte Carlo simulation method
![[Latex] 插入圖片](/img/0b/3304aaa03d3fea3ebb93b0348c3131.png)
[Latex] 插入圖片

五篇经典好文,值得一看(2)

Addition and modification of JPA

STM32 USB Basics

軟件測試的幾種分類,一看就明了

Five classic articles worth reading

什么是 Meebits?一个简短的解释

Pipeline流水线项目构建
随机推荐
生态聚合NFT来袭,Metaverse Ape引领Web 3.0元宇宙新范式革命
How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic benefits of ASI, VR, arbr, DPO and trix indicators
leetcode 206. Reverse linked list
The scope builder coroutinescope, runblocking and supervisorscope of kotlin collaboration processes run synchronously. How can other collaboration processes not be suspended when the collaboration pro
Binary tree -- using hierarchical sequence and middle sequence to determine a tree
Et5.0 value type generation
[JS component] floating text
pytorch和tensorflow有什么区别?
Addition and modification of JPA
Three column simple Typecho theme lanstar/ Blue Star Typecho theme
The seventh finals of the Blue Bridge Cup
Characteristics of transactions - persistence (implementation principle)
The grass is bearing seeds
MySQL异常:com.mysql.jdbc.PacketTooBigException: Packet for query is too large(4223215 > 4194304)
Today's sleep quality record 74 points
Canvas airplane game
[Latex] 插入图片
304. Merge two ordered arrays
[virtual machine] notes on virtual machine environment problems
什么是 Meebits?一个简短的解释