Update autograd_saved_tensors_hooks_tutorial.py - #598
Conversation
bub3690
left a comment
There was a problem hiding this comment.
๋ฒ์ญ๋ค์ด ์๋ ์ค๋ก ์ ํ์์ต๋๋ค.
์๋ฌธ์ ์ง์ฐ๊ณ ๋ค์ ์ ์ด์ฃผ์ ์ผ ํฉ๋๋ค.
bub3690
left a comment
There was a problem hiding this comment.
๋ฌธ๋ฒ์ด ๊นจ์ง ๋ถ๋ถ์ด ๋ง์ ๋ณด์ ๋๋ค.
๋น๋ ๋ถํ๋๋ฆฝ๋๋ค.
| # :width: 500 | ||
| # :align: center | ||
|
|
||
| # .. ๊ทธ๋ฆผ :: https://user-images.githubusercontent.com/8019486/130124570-f1074098-1bb3-459e-bf5a-03bf6f65b403.png |
There was a problem hiding this comment.
.. figure
:width
์ด ๋ถ๋ถ๋ค์ ๋ฌธ๋ฒ์ด๋ผ ๋ฒ์ญ์ ํ๋ฉด ์๋ ๊ฒ์ผ๋ก ๋ณด์ด๋ค์.
There was a problem hiding this comment.
๋ต.. ๊ฐ์ฌํฉ๋๋ค. ๋ฐ์ํ๊ฒ ์ต๋๋ค.
| # 1000) and how to combine this feature with ``nn.DataParallel``. | ||
| # | ||
| # ์ด ๋ง์ง๋ง ์์์๋ | ||
| # ๋ฐ๋์ ์ ์ฅํด์ผํ๋ฉฐ ์ด ๊ธฐ๋ฅ์ ``nn.DataParallel``์ ์ด๋ป๊ฒ ์กฐํฉํ๋ ํ ์๋ค์ ๋ํด ์ด๋ป๊ฒ ํํฐํ๋์ง์ ๋ํ ์ฆ๋ช ์ ํด๋ณด์์ต๋๋ค. |
There was a problem hiding this comment.
`` ์๋ค๋ก ๋ฐ์ด์ฐ๊ธฐ๊ฐ ์์ด์ผ ํฉ๋๋ค.
๋น๋ํด์ ํ์ธ ๋ถํ๋๋ฆฝ๋๋ค.
There was a problem hiding this comment.
๋ต.. ๊ฐ์ฌํฉ๋๋ค. ๋ฐ์ํ๊ฒ ์ต๋๋ค.
hyoyoung
left a comment
There was a problem hiding this comment.
๋ฒ์ญ์ด ์๋ฃ๋ ์์ด ๋ถ๋ถ์ ์ ๊ฑฐ ๋ถํ๋๋ฆฝ๋๋ค.
| @@ -1,5 +1,6 @@ | |||
| """ | |||
| Hooks for autograd saved tensors | |||
| ๋ฏธ๋ถ์๋ํ(autograd) ์ ์ฅ๋ ํ ์๋ฅผ ์ํ HOOK | |||
There was a problem hiding this comment.
Hooks๋ฅผ ๋ฒ์ญ ์ํ๊ธฐ๋ก ๊ฒฐ์ ํ์
จ๋ค๋ฉด
HOOK์ด ์๋๋ผ Hooks๋ฅผ ๊ทธ๋๋ก ๋์๋๊ฒ ๋ ๋์๋ฏํฉ๋๋ค
There was a problem hiding this comment.
๋ต.. ๊ฐ์ฌํฉ๋๋ค. ๋ฐ์ํ๊ฒ ์ต๋๋ค.
gorae17
left a comment
There was a problem hiding this comment.
๊ณ ์ํ์
จ์ต๋๋ค. ์ด๋ฏธ ๋ฆฌ๋ทฐ๋ฐ์ผ์ ๊ฒ์ฒ๋ผ, ์๋ฌธ์ ์ง์ฐ๊ณ ์๋ฌธ ์์น์ ๋ฒ์ญ ๋ฌธ์ฅ์ ์ ์ ํ make html-noplot์ผ๋ก ๋น๋ ํ html ํ์ผ์ ํ์ธํด๋ณด์๋ฉด ๊ฒฐ๊ณผ ์ดํด๋ณด์๋ ๋ฐ์ ๋์์ด ๋ ๊ฒ ๊ฐ์ต๋๋ค.
| ###################################################################### | ||
| # In this example, PyTorch saves intermediary values :math:`a` and | ||
| # :math:`b` in order to compute the gradient during the backward. | ||
| # ์ด ์์ ์์ ํ์ดํ ์น๋ ์ค๊ฐ ๊ฐ :math:`a` ๋ฐ :math:`b`๋ฅผ ์ ์ฅํ์ฌ ์ญ๋ฐฉํฅ ๋์ ๊ธฐ์ธ๊ธฐ๋ฅผ ๊ณ์ฐํฉ๋๋ค. |
There was a problem hiding this comment.
` ๊ฐ ํ๋ ์์ ๋์๋ ์๋ค๋ก ๋์ด์ฐ๊ธฐ๊ฐ ์์ด์ผ ํฉ๋๋ค.
There was a problem hiding this comment.
๋ต.. ๊ฐ์ฌํฉ๋๋ค. ๋ฐ์ํ๊ฒ ์ต๋๋ค.
|
| # ๊ทธ๋ฌ๋ ํน์ ์์ ์์๋ ์ญ์ ํ๋ฅผ ์ํํ๊ธฐ ์ํ ์ค๊ฐ๊ฒฐ๊ณผ๋ฅผ ์ ์ฅํด์ผ ํฉ๋๋ค. | ||
| # ์ด๋ฒ ํํ ๋ฆฌ์ผ์์๋ ์ด๋ฌํ ํ ์๋ฅผ ์ ์ฅ/๊ฒ์ํ๋ ๋ฐฉ๋ฒ๊ณผ ํจํน/์ธํจํน ํ๋ก์ธ์ค๋ฅผ ์ ์ดํ๊ธฐ์ํ hooks์ ์ ํ๋ ๋ฐฉ๋ฒ์ ์๋ดํฉ๋๋ค. | ||
|
|
||
| # ์ด ํํ ๋ฆฌ์ผ์์๋ ์ฌ์ฉ์๊ฐ ์ญ์ ํ๊ฐ ์ด๋ก ์์์ ์๋ํ๋ ๋ฐฉ์์ ์ต์ํ๋ค๊ณ ๊ฐ์ ํฉ๋๋ค. ์๋๋ผ๋ฉด, ์๋์ ์๋ฃ๋ฅผ ๋จผ์ ์ฝ์ด๋ณด์ธ์. |
There was a problem hiding this comment.
์๋ฌธ์ ์ถฉ์คํ๊ฒ ๋ฒ์ญ์ ํด์ฃผ์
จ๋๋ฐ์. ๊ฐ์ธ์ ์ธ ์๊ฒฌ์ผ๋ก๋ ์๋์ ๊ฐ์ด ์์ ํ๋ฉด ์กฐ๊ธ ๋ ์์ฐ์ค๋ฝ์ง ์์๊นํ์ฌ ์ ์๋๋ ค๋ด
๋๋ค.
'์ด ํํ ๋ฆฌ์ผ์์๋ ์ญ์ ํ๊ฐ ์ด๋ฃจ์ด์ง๋ ๋ฐฉ์์ ๋ํด ๋
์๊ฐ ์ด๋ก ์ ์ผ๋ก ์ ์๊ณ ์๋ค๊ณ ๊ฐ์ ํฉ๋๋ค.'
| # as it never copies any tensors. However, the graph can keep *references* | ||
| # to tensors that would otherwise have gone out of scope: those are | ||
| # referred to as **saved tensors**. | ||
| # ๋ชจ๋ธ์ ํ๋ จ์ ์ผ๋ฐ์ ์ผ๋ก ๊ฐ์ค์ ์ถ๋ก ์ ์ํด์ ์คํํ๋ ๊ฒ๋ณด๋ค ๋ ๋ง์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ฌ์ฉํฉ๋๋ค. |
There was a problem hiding this comment.
๊ฐ์ค์ ์ถ๋ก ์ด๋ผ๋ ๋ป๋ณด๋ค๋ inference (classification์ด๋ regression ๊ฐ์ prediction) ์ธก๋ฉด์์ ์๋ฏธ๊ฐ ์ ๋ฌ๋๋ ๊ฒ์ด ๋ ์ ํฉํ ๊ฒ ๊ฐ์ต๋๋ค. (ํ๊ตญ์ด๋ก ํํํ๋ฉด '๋ชจ๋ธ์ ์ธํผ๋ฐ์คํ๋ ๊ฒ๋ณด๋ค ํ์ตํ๋ ๊ณผ์ ์์ ๋ฉ๋ชจ๋ฆฌ๊ฐ ๋ ๋ง์ด ์ฌ์ฉ๋๋ค' ์ด๋ฐ ๋ป์ผ๋ก ์๋ฉ์ด ์กฐ๊ธ ์์ ๋๋ฉด ์ข์ ๊ฒ ๊ฐ์์!
There was a problem hiding this comment.
์ด ๋ถ๋ถ์ @garam24 ๋ ๋ง์๋๋ก ์์ ํ๋๊ฒ ์ข์๋ฏํฉ๋๋ค.
๋ฌธ๋งฅ์ ์๊ธฐ๊ฐ ์ด๋ ต์ต๋๋ค
|
|
||
| ###################################################################### | ||
| # Why does training a model (typically) requires more memory than evaluating it? | ||
| # (์ผ๋ฐ์ ์ผ๋ก)๋ชจ๋ธ์ ํ๋ จํ๋๋ฐ ํ๊ฐ๋ณด๋ค ๋ ๋ง์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์์ํ๊ฒ ๋๋ ์ด์ ๋ ๋ฌด์์ผ๊น์? |
There was a problem hiding this comment.
'๋ฉ๋ชจ๋ฆฌ๋ฅผ ์์ํ๊ฒ'๋ณด๋ค '์๋ชจํ๋', 'ํ์๋ก ํ๋' ๋ฑ์ผ๋ก ์์ ํ๋ฉด ๋ ์์ฐ์ค๋ฌ์ธ ๊ฒ ๊ฐ์ ์ ์ ์๊ฒฌ ๋๋ฆฝ๋๋ค.
hyoyoung
left a comment
There was a problem hiding this comment.
๋ช๊ฐ์ง ์์ ์ฌํญ์ ๋ ๋ถํ๋๋ฆฝ๋๋ค.
| """ | ||
| Hooks for autograd saved tensors | ||
| ๋ฏธ๋ถ์๋ํ(autograd) ์ ์ฅ๋ ํ ์๋ฅผ ์ํ Hooks | ||
| ======================= |
There was a problem hiding this comment.
๊ธธ๊ฒ๋ ์ ๋ชฉ๋งํผ =๋ ๋๋ ค์ฃผ์ธ์
| # as it never copies any tensors. However, the graph can keep *references* | ||
| # to tensors that would otherwise have gone out of scope: those are | ||
| # referred to as **saved tensors**. | ||
| # ๋ชจ๋ธ์ ํ๋ จ์ ์ผ๋ฐ์ ์ผ๋ก ๊ฐ์ค์ ์ถ๋ก ์ ์ํด์ ์คํํ๋ ๊ฒ๋ณด๋ค ๋ ๋ง์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ฌ์ฉํฉ๋๋ค. |
There was a problem hiding this comment.
์ด ๋ถ๋ถ์ @garam24 ๋ ๋ง์๋๋ก ์์ ํ๋๊ฒ ์ข์๋ฏํฉ๋๋ค.
๋ฌธ๋งฅ์ ์๊ธฐ๊ฐ ์ด๋ ต์ต๋๋ค
| # to tensors that would otherwise have gone out of scope: those are | ||
| # referred to as **saved tensors**. | ||
| # ๋ชจ๋ธ์ ํ๋ จ์ ์ผ๋ฐ์ ์ผ๋ก ๊ฐ์ค์ ์ถ๋ก ์ ์ํด์ ์คํํ๋ ๊ฒ๋ณด๋ค ๋ ๋ง์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ฌ์ฉํฉ๋๋ค. | ||
| # ๋๋ต์ ์ผ๋ก ๋งํ๋ฉด ํ์ดํ ์น๋ ์ญ์ ํ๋ฅผ ํธ์ถํ๋๋ฐ ํ์ํ ๊ณ์ฐ ๊ทธ๋ํ๋ฅผ ์ ์ฅํด์ผํ๋ฏ๋ก ์ถ๊ฐ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ด ์๊ธฐ ๋๋ฌธ์ด๋ค ๋ผ๊ณ ๋งํ ์ ์์ต๋๋ค. |
There was a problem hiding this comment.
๋๋ต์ ์ผ๋ก ๋งํ์๋ฉด ~ ๋งํ ์ ์์ต๋๋ค
๋ผ๊ณ ๋๋ฉ๋๋ค ์ด ๋ฌธ์ฅ์
๋๋ต์ ์ผ๋ก ๋งํ๋ฉด ํ์ดํ ์น๋ ์ญ์ ํ๋ฅผ ํธ์ถํ๋๋ฐ ํ์ํ ๊ณ์ฐ ๊ทธ๋ํ๋ฅผ ์ ์ฅํด์ผํ๋ฏ๋ก ์ถ๊ฐ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ด ์๊ธฐ ๋๋ฌธ์ ๋๋ค.
์ ๋๋ก ์์ ํ๋๊ฒ ์ข์๋ฏ ํฉ๋๋ค
| # In fact, PyTorch provides an API to conveniently use those hooks (as | ||
| # well as the ability to use pinned memory). | ||
| # | ||
| # ์ค์ ๋ก ํ์ดํ ์น๋ ์ด๋ฌํ ํํฌ๋ฅผ ํธ๋ฆฌํ๊ฒ ์ฌ์ฉํ ์ ์๋ API๋ฅผ ์ ๊ณตํฉ๋๋ค. (๊ณ ์ ๋ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ ๊ธฐ๋ฅ๋ ํฌํจ.) |
| # module and saves its tensors to CPU. | ||
| # ๋ฌผ๋ก ๋คํธ์ํฌ ํน์ ๋ถ๋ถ๋ง CPU์ ์ ์ฅํ์ฌ ์ ์ถฉ์์ ์กฐ์ ํ ์ ์์ต๋๋ค. | ||
| # | ||
| # ์๋ฅผ ๋ค์ด, ๋ชจ๋ ๋ชจ๋์ ๋ํํ๊ณ ํด๋น ํ ์๋ฅผ CPU์ ์ ์ฅํ๋ ํน๋ณํ |
| # The reason the above code is bad is that we are leaking files on the | ||
| # disk and they are never cleared. Fixing this is not as trivial as it | ||
| # seems. | ||
| # ์์ ์ฝ๋๊ฐ ๋์ ์ด์ ๋ ๋์คํฌ๋ ์ง์์ง์ง ์์ต๋๋ค. |
There was a problem hiding this comment.
์์ ์ฝ๋๊ฐ ๋์ ์ด์ ๋ ๋์คํฌ์ ์ ์ฅ๋ ํ์ผ์ด ๋์ถ๋๊ณ ํด๋น ํ์ผ์ ์ง์ธ์๋ ์๊ธฐ ๋๋ฌธ์ ๋๋ค.
| # saved tensor hooks and how they can be useful in a few scenarios to | ||
| # tradeoff memory for compute. | ||
| # | ||
| # ๋ง์ผ ์ฌ๊ธฐ๊น์ง ๋ฐ๋ผ์ค์ จ๋ค๋ฉด, ์ถํํฉ๋๋ค! ๋น์ ์ ์ ์ฅ๋ ํ ์ hooks์ ์ด๋ป๊ฒ ์ฌ์ฉํ๋์ง ๊ทธ๋ฆฌ๊ณ ๊ณ์ฐ ๋ฉ๋ชจ๋ฆฌ์ ํธ๋ ์ด๋ ์คํ์ ์์ด์ ๋ช๊ฐ์ง ์๋๋ฆฌ์ค๋ฅผ ์ ์ฉํ๊ฒ ์ฌ์ฉํ ์ ์์ต๋๋ค! |
There was a problem hiding this comment.
๊ณ์ฐ ๋ฉ๋ชจ๋ฆฌ์ ํธ๋ ์ด๋ ์คํ์ ์์ด์ ๋ช๊ฐ์ง ์๋๋ฆฌ์ค๋ฅผ ์ ์ฉํ๊ฒ ์ฌ์ฉํ ์ ์์ต๋๋ค!
->
๊ณ์ฐ ๋ฉ๋ชจ๋ฆฌ์ ์ ์ถฉ์์์ ๋ช๊ฐ์ง ์๋๋ฆฌ์ค๋ฅผ ์ ์ฉํ๊ฒ ์ฌ์ฉํ ์ ์์ต๋๋ค!
๋ผ์ด์ ์ค ๋์
๋ณ๊ฒฝํด์ฃผ์๋ ๋ด์ฉ์ BSD 3ํญ ๋ผ์ด์ ์ค๊ฐ ์ ์ฉ๋จ์ ๋์ํด์ฃผ์ ์ผ ํฉ๋๋ค.
๋ ์์ธํ ๋ด์ฉ์ ๊ธฐ์ฌํ๊ธฐ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํด์ฃผ์ธ์.
๋์ํ์๋ฉด ์๋
[ ]๋ฅผ[x]๋ก ๋ง๋ค์ด์ฃผ์ธ์.๊ด๋ จ ์ด์ ๋ฒํธ
์ด Pull Request์ ๊ด๋ จ์๋ ์ด์ ๋ฒํธ๋ฅผ ์ ์ด์ฃผ์ธ์.
์ด์ ๋๋ PR ๋ฒํธ ์์ #์ ๋ถ์ด์๋ฉด ์ ๋ชฉ์ ๋ฐ๋ก ํ์ธํ์ค ์ ์์ต๋๋ค. (์. #999 )
PR ์ข ๋ฅ
์ด PR์ ํด๋น๋๋ ์ข ๋ฅ ์์
[ ]์[x]๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์.PR ์ค๋ช
์ด PR๋ก ๋ฌด์์ด ๋ฌ๋ผ์ง๋์ง ๋๋ต์ ์ผ๋ก ์๋ ค์ฃผ์ธ์.