Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
9bow committed Mar 27, 2022
1 parent db48b10 commit 9810487
Show file tree
Hide file tree
Showing 35 changed files with 1,615 additions and 166 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/1_TRANSLATE_REQUEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ _(๋ฐ˜๋“œ์‹œ ์ง€ํ‚ค์…”์•ผ ํ•˜๋Š” ์ผ์ •์ด ์•„๋‹™๋‹ˆ๋‹ค - ์ผ์ •์ด ๋„ˆ๋ฌด ๋Šฆ์–ด
## ๊ด€๋ จ ์ด์Šˆ
_ํ˜„์žฌ ๋ฒˆ์—ญ ์š”์ฒญ / ์ง„ํ–‰ ๋‚ด์—ญ์„ ๋ณด๊ธฐ ์œ„ํ•ด ๊ฐ ๋ฒ„์ „์˜ ๋ฉ”์ธ ์ด์Šˆ๋ฅผ ์ฐธ์กฐํ•ฉ๋‹ˆ๋‹ค._ <br />
_(ํŠน๋ณ„ํ•œ ์ผ์ด ์—†๋‹ค๋ฉด ๋ณ€๊ฒฝํ•˜์ง€ ์•Š์œผ์…”๋„ ๋ฉ๋‹ˆ๋‹ค.)_
* ๊ด€๋ จ ์ด์Šˆ: #387 (v1.10)
* ๊ด€๋ จ ์ด์Šˆ: #445 (v1.11)
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

PyTorch์—์„œ ์ œ๊ณตํ•˜๋Š” ํŠœํ† ๋ฆฌ์–ผ์˜ ํ•œ๊ตญ์–ด ๋ฒˆ์—ญ์„ ์œ„ํ•œ ์ €์žฅ์†Œ์ž…๋‹ˆ๋‹ค.\
๋ฒˆ์—ญ์˜ ๊ฒฐ๊ณผ๋ฌผ์€ [https://tutorials.pytorch.kr](https://tutorials.pytorch.kr)์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. (๋ฒˆ์—ญ์„ ์ง„ํ–‰ํ•˜๋ฉฐ **๋ถˆ๊ทœ์น™์ ์œผ๋กœ** ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.)\
ํ˜„์žฌ ๋ฒ„์ „์˜ ๋ฒˆ์—ญ / ๋ณ€๊ฒฝ ๊ด€๋ จ ์ด์Šˆ๋Š” [#387 ์ด์Šˆ](https://github.com/PyTorchKorea/tutorials-kr/issues/387)๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.
ํ˜„์žฌ ๋ฒ„์ „์˜ ๋ฒˆ์—ญ / ๋ณ€๊ฒฝ ๊ด€๋ จ ์ด์Šˆ๋Š” [#445 ์ด์Šˆ](https://github.com/PyTorchKorea/tutorials-kr/issues/445)๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.

## ๊ธฐ์—ฌํ•˜๊ธฐ

Expand All @@ -22,20 +22,12 @@ PyTorch์—์„œ ์ œ๊ณตํ•˜๋Š” ํŠœํ† ๋ฆฌ์–ผ์˜ ํ•œ๊ตญ์–ด ๋ฒˆ์—ญ์„ ์œ„ํ•œ ์ €์žฅ์†Œ

## ์›๋ฌธ

ํ˜„์žฌ PyTorch v1.10.1 ํŠœํ† ๋ฆฌ์–ผ([pytorch/tutorials@444fbd1](https://github.com/pytorch/tutorials/commit/444fbd16f2ddf9967baf8b06e83867a141b071c2) ๊ธฐ์ค€) ๋ฒˆ์—ญ์ด ์ง„ํ–‰ ์ค‘์ž…๋‹ˆ๋‹ค.
ํ˜„์žฌ PyTorch v1.11 ํŠœํ† ๋ฆฌ์–ผ([pytorch/tutorials@6e21cf2](https://github.com/pytorch/tutorials/commit/6e21cf2e81beb8b4dddc9713be0c8746087fd59e) ๊ธฐ์ค€) ๋ฒˆ์—ญ์ด ์ง„ํ–‰ ์ค‘์ž…๋‹ˆ๋‹ค.

์ตœ์‹  ๋ฒ„์ „์˜ ํŠœํ† ๋ฆฌ์–ผ(๊ณต์‹, ์˜์–ด)์€ [PyTorch tutorials ์‚ฌ์ดํŠธ](https://pytorch.org/tutorials) ๋ฐ [PyTorch tutorials ์ €์žฅ์†Œ](https://github.com/pytorch/tutorials)๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.

## ๊ณผ๊ฑฐ ๋ฒ„์ „

### PyTorch v1.0 ์ด์ƒ์˜ ํŠœํ† ๋ฆฌ์–ผ ๋ณด๊ธฐ

v1.0 ์ดํ›„ ๋ฒˆ์—ญ์€ ๋ณ„๋„ ์ €์žฅ์†Œ๋กœ ๊ด€๋ฆฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. [์ด ์ €์žฅ์†Œ์˜ Release ๋ฉ”๋‰ด](https://github.com/PyTorchKorea/tutorials-kr/releases)๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”. \
`๋ฒ„์ „-base`(์˜ˆ. `1.9-base`)๋Š” ํ•ด๋‹น ๋ฒ„์ „์„ ์‹œ์ž‘ํ•  ๋•Œ์˜ ๋ฆด๋ฆฌ์ฆˆ์ด๊ณ , `๋ฒ„์ „-latest`(์˜ˆ. `1.9-latest`)๋Š” ํ•ด๋‹น ๋ฒ„์ „์˜ ๋งˆ์ง€๋ง‰ ๋ฆด๋ฆฌ์ฆˆ์ž…๋‹ˆ๋‹ค.

ํ•ด๋‹น ๋ฆด๋ฆฌ์ฆˆ์˜ ๋ฌธ์„œ๋ฅผ ๋‚ด๋ ค๋ฐ›์œผ์‹  ํ›„ ๋นŒ๋“œํ•˜์‹œ๋ฉด ํ•ด๋‹น ๋ฒ„์ „์˜ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. \
๋นŒ๋“œ ๋ฐฉ๋ฒ•์€ [๊ธฐ์—ฌํ•˜๊ธฐ ๋ฌธ์„œ์˜ `2-5. (๋‚ด ์ปดํ“จํ„ฐ์—์„œ) ๊ฒฐ๊ณผ ํ™•์ธํ•˜๊ธฐ`](https://github.com/PyTorchKorea/tutorials-kr/blob/master/CONTRIBUTING.md#2-5-๋‚ด-์ปดํ“จํ„ฐ์—์„œ-๊ฒฐ๊ณผ-ํ™•์ธํ•˜๊ธฐ) ๋ถ€๋ถ„์„ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.

### PyTorch v1.0 ์ด์ „(v0.3 & v0.4)์˜ ํŠœํ† ๋ฆฌ์–ผ ๋ณด๊ธฐ

์•„๋ž˜ ๋งํฌ์—์„œ ๊ณผ๊ฑฐ ๋ฒ„์ „์˜ ํŠœํ† ๋ฆฌ์–ผ ๋ฒˆ์—ญ์„ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ˜„์žฌ๋Š” ๋ฒˆ์—ญ์ด ์ด๋ค„์ง€๊ณ  ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
Expand All @@ -45,6 +37,14 @@ v1.0 ์ดํ›„ ๋ฒˆ์—ญ์€ ๋ณ„๋„ ์ €์žฅ์†Œ๋กœ ๊ด€๋ฆฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. [์ด ์ €์žฅ
| 0.4.1 | [PyTorch-tutorials-kr-0.4](https://9bow.github.io/PyTorch-tutorials-kr-0.4) | [GitHub ์ €์žฅ์†Œ](https://github.com/PyTorchKorea/tutorials-kr-0.4) |
| 0.3.1 | [PyTorch-tutorials-kr-0.3.1](https://9bow.github.io/PyTorch-tutorials-kr-0.3.1) | [GitHub ์ €์žฅ์†Œ](https://github.com/PyTorchKorea/tutorials-kr-0.3.1) |

### PyTorch v1.0 ์ด์ƒ์˜ ํŠœํ† ๋ฆฌ์–ผ ๋ณด๊ธฐ

v1.0 ์ดํ›„ ๋ฒˆ์—ญ์€ ๋ณ„๋„ ์ €์žฅ์†Œ๋กœ ๊ด€๋ฆฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. [์ด ์ €์žฅ์†Œ์˜ Release ๋ฉ”๋‰ด](https://github.com/PyTorchKorea/tutorials-kr/releases)๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”. \
`๋ฒ„์ „-base`(์˜ˆ. `1.9-base`)๋Š” ํ•ด๋‹น ๋ฒ„์ „์„ ์‹œ์ž‘ํ•  ๋•Œ์˜ ๋ฆด๋ฆฌ์ฆˆ์ด๊ณ , `๋ฒ„์ „-latest`(์˜ˆ. `1.9-latest`)๋Š” ํ•ด๋‹น ๋ฒ„์ „์˜ ๋งˆ์ง€๋ง‰ ๋ฆด๋ฆฌ์ฆˆ์ž…๋‹ˆ๋‹ค.

ํ•ด๋‹น ๋ฆด๋ฆฌ์ฆˆ์˜ ๋ฌธ์„œ๋ฅผ ๋‚ด๋ ค๋ฐ›์œผ์‹  ํ›„ ๋นŒ๋“œํ•˜์‹œ๋ฉด ํ•ด๋‹น ๋ฒ„์ „์˜ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. \
๋นŒ๋“œ ๋ฐฉ๋ฒ•์€ [๊ธฐ์—ฌํ•˜๊ธฐ ๋ฌธ์„œ์˜ `2-5. (๋‚ด ์ปดํ“จํ„ฐ์—์„œ) ๊ฒฐ๊ณผ ํ™•์ธํ•˜๊ธฐ`](https://github.com/PyTorchKorea/tutorials-kr/blob/master/CONTRIBUTING.md#2-5-๋‚ด-์ปดํ“จํ„ฐ์—์„œ-๊ฒฐ๊ณผ-ํ™•์ธํ•˜๊ธฐ) ๋ถ€๋ถ„์„ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.

---
This is a project to translate [pytorch/tutorials@444fbd1](https://github.com/pytorch/tutorials/commit/444fbd16f2ddf9967baf8b06e83867a141b071c2) into Korean.
This is a project to translate [pytorch/tutorials@6e21cf2](https://github.com/pytorch/tutorials/commit/6e21cf2e81beb8b4dddc9713be0c8746087fd59e) into Korean.
For the latest version, please visit to the [official PyTorch tutorials repo](https://github.com/pytorch/tutorials).
Binary file added _static/img/distributed/DDP_memory.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _static/img/distributed/FSDP_autowrap.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _static/img/distributed/FSDP_memory.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _static/img/distributed/fsdp_workflow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _static/img/thumbnails/cropped/realtime_rpi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _static/img/thumbnails/torchrec.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 23 additions & 2 deletions advanced_source/cpp_extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,27 @@ into C++. Our primary datatype for all computations will be
also that we can include ``<iostream>`` or *any other C or C++ header* -- we have
the full power of C++11 at our disposal.

Note that CUDA-11.5 nvcc will hit internal compiler error while parsing torch/extension.h on Windows.
To workaround the issue, move python binding logic to pure C++ file.
Example use:

.. code-block:: cpp
#include <ATen/ATen.h>
at::Tensor SigmoidAlphaBlendForwardCuda(....)
Instead of:

.. code-block:: cpp
#include <torch/extension.h>
torch::Tensor SigmoidAlphaBlendForwardCuda(...)
Currently open issue for nvcc bug `here
<https://github.com/pytorch/pytorch/issues/69460>`_.
Complete workaround code example `here
<https://github.com/facebookresearch/pytorch3d/commit/cb170ac024a949f1f9614ffe6af1c38d972f7d48>`_.

Forward Pass
************

Expand Down Expand Up @@ -497,7 +518,7 @@ duration::
(new_h.sum() + new_C.sum()).backward()
backward += time.time() - start

print('Forward: {:.3f} us | Backward {:.3f} us'.format(forward * 1e6/1e5, backward * 1e6/1e5))
print('Forward: {:.3f} s | Backward {:.3f} s'.format(forward, backward))

If we run this code with the original LLTM we wrote in pure Python at the start
of this post, we get the following numbers (on my machine)::
Expand Down Expand Up @@ -667,7 +688,7 @@ We'll start with the C++ file, which we'll call ``lltm_cuda.cpp``, for example:
// C++ interface
#define CHECK_CUDA(x) TORCH_CHECK(x.type().is_cuda(), #x " must be a CUDA tensor")
#define CHECK_CUDA(x) TORCH_CHECK(x.device().is_cuda(), #x " must be a CUDA tensor")
#define CHECK_CONTIGUOUS(x) TORCH_CHECK(x.is_contiguous(), #x " must be contiguous")
#define CHECK_INPUT(x) CHECK_CUDA(x); CHECK_CONTIGUOUS(x)
Expand Down
15 changes: 8 additions & 7 deletions advanced_source/ddp_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
**Author**: `Pritam Damania <https://github.com/pritamdamania87>`_
**๋ฒˆ์—ญ**: `๋ฐฑ์„ ํฌ <https://github.com/spongebob03>`_
์ด ํŠœํ† ๋ฆฌ์–ผ์€ `๋ถ„์‚ฐ ๋ฐ์ดํ„ฐ ๋ณ‘๋ ฌ์ฒ˜๋ฆฌ(Distributed Data Parallel) <https://pytorch.org/docs/stable/generated/torch.nn.parallel.DistributedDataParallel.html>`__ ์™€
`๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ ํŒŒ์ดํ”„๋ผ์ธ <https://pytorch.org/docs/stable/pipeline.html>`__
๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ฌ๋Ÿฌ GPU์— ๊ฑธ์นœ ๊ฑฐ๋Œ€ํ•œ ํŠธ๋žœ์Šคํฌ๋จธ(Transformer) ๋ชจ๋ธ์„ ์–ด๋–ป๊ฒŒ ํ•™์Šต์‹œํ‚ค๋Š”์ง€ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.
Expand All @@ -26,7 +26,7 @@
#

######################################################################
# ``PositionalEncoding`` ๋ชจ๋“ˆ์€ ์‹œํ€€์Šค์—์„œ ํ† ํฐ์˜ ์ƒ๋Œ€์ , ์ ˆ๋Œ€์  ์œ„์น˜์— ๋Œ€ํ•œ
# ``PositionalEncoding`` ๋ชจ๋“ˆ์€ ์‹œํ€€์Šค์—์„œ ํ† ํฐ์˜ ์ƒ๋Œ€์ , ์ ˆ๋Œ€์  ์œ„์น˜์— ๋Œ€ํ•œ
# ๋ช‡๋ช‡ ์ •๋ณด๋ฅผ ์ฃผ์ž…ํ•ฉ๋‹ˆ๋‹ค.
# ์œ„์น˜ ์ธ์ฝ”๋”ฉ์€ ์ž„๋ฒ ๋”ฉ๊ณผ ๊ฐ™์€ ์ฐจ์›์„ ๊ฐ€์ง€๋ฏ€๋กœ
# ๋‘˜์„ ํ•ฉ์น  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ, ์ฃผํŒŒ์ˆ˜๊ฐ€ ๋‹ค๋ฅธ ``sine`` ๊ณผ ``cosine`` ํ•จ์ˆ˜๋ฅผ
Expand Down Expand Up @@ -61,10 +61,10 @@ def forward(self, x):


######################################################################
# ์ด๋ฒˆ ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š”, ํŠธ๋žœ์Šคํฌ๋จธ ๋ชจ๋ธ์„ ๋‘ ๊ฐœ์˜ GPU์— ๊ฑธ์ณ์„œ ๋‚˜๋ˆ„๊ณ 
# ์ด๋ฒˆ ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š”, ํŠธ๋žœ์Šคํฌ๋จธ ๋ชจ๋ธ์„ ๋‘ ๊ฐœ์˜ GPU์— ๊ฑธ์ณ์„œ ๋‚˜๋ˆ„๊ณ 
# ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ ํŒŒ์ดํ”„๋ผ์ธ์œผ๋กœ ํ•™์Šต์‹œ์ผœ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ถ”๊ฐ€๋กœ,
# `๋ถ„์‚ฐ ๋ฐ์ดํ„ฐ ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ <https://pytorch.org/docs/stable/generated/torch.nn.parallel.DistributedDataParallel.html>`__
# ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ด ํŒŒ์ดํ”„๋ผ์ธ์˜ ๋‘ ๋ณต์ œ๋ฅผ ํ›ˆ๋ จ์‹œํ‚ต๋‹ˆ๋‹ค. ํ•œ ํ”„๋กœ์„ธ์Šค๋Š”
# ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ด ํŒŒ์ดํ”„๋ผ์ธ์˜ ๋‘ ๋ณต์ œ๋ฅผ ํ›ˆ๋ จ์‹œํ‚ต๋‹ˆ๋‹ค. ํ•œ ํ”„๋กœ์„ธ์Šค๋Š”
# GPUs 0, 1์— ๊ฑฐ์ณ ํŒŒ์ดํ”„๋ฅผ ๊ตฌ๋™ํ•˜๊ณ  ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค๋Š” GPUs 2, 3์—์„œ ํŒŒ์ดํ”„๋ฅผ ๊ตฌ๋™ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ๋‹ค์Œ, ์ด ๋‘
# ํ”„๋กœ์„ธ์Šค๋Š” ๋ถ„์‚ฐ ๋ฐ์ดํ„ฐ ๋ณ‘๋ ฌ์ฒ˜๋ฆฌ๋กœ ๋‘ ๋ณต์ œ๋ณธ(replica)์„ ํ•™์Šต์‹œํ‚ต๋‹ˆ๋‹ค.
# ๋ชจ๋ธ์€ ๋ฐ”๋กœ `nn.Transformer ์™€ TorchText ๋กœ ์‹œํ€€์Šค-ํˆฌ-์‹œํ€€์Šค(Sequence-to-Sequence) ๋ชจ๋ธ๋งํ•˜๊ธฐ
Expand Down Expand Up @@ -138,9 +138,10 @@ def run_worker(rank, world_size):
# ---------------------------
#


######################################################################
# ํ•™์Šต ํ”„๋กœ์„ธ์Šค๋Š” ``torchtext`` ์˜ Wikitext-2 ๋ฐ์ดํ„ฐ์…‹์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
# torchtext ๋ฐ์ดํ„ฐ์…‹์— ์ ‘๊ทผํ•˜๊ธฐ ์ „์—, https://github.com/pytorch/data ์„ ์ฐธ๊ณ ํ•˜์—ฌ torchdata๋ฅผ
# ์„ค์น˜ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.
# ๋‹จ์–ด ์˜ค๋ธŒ์ ํŠธ๋Š” ํ›ˆ๋ จ ๋ฐ์ดํ„ฐ์…‹์œผ๋กœ ๋งŒ๋“ค์–ด์ง€๊ณ , ํ† ํฐ์„ ํ…์„œ(tensor)๋กœ ์ˆ˜์น˜ํ™”ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.
# ์‹œํ€€์Šค ๋ฐ์ดํ„ฐ๋กœ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์—ฌ, ``batchify()`` ํ•จ์ˆ˜๋Š” ๋ฐ์ดํ„ฐ์…‹์„ ์—ด(column)๋“ค๋กœ ์ •๋ฆฌํ•˜๊ณ ,
# ``batch_size`` ์‚ฌ์ด์ฆˆ์˜ ๋ฐฐ์น˜๋“ค๋กœ ๋‚˜๋ˆˆ ํ›„์— ๋‚จ์€ ๋ชจ๋“  ํ† ํฐ์„ ๋ฒ„๋ฆฝ๋‹ˆ๋‹ค.
Expand Down Expand Up @@ -223,7 +224,7 @@ def batchify(data, bsz, rank, world_size, is_train=False):
#
# .. image:: ../_static/img/transformer_input_target.png
#
# ์ฒญํฌ๊ฐ€ ์ฐจ์› 0์— ์†ํ•˜๋ฉฐ
# ์ฒญํฌ๊ฐ€ ์ฐจ์› 0์— ์†ํ•˜๋ฉฐ
# ํŠธ๋žœ์Šคํฌ๋จธ ๋ชจ๋ธ์˜ ``S`` ์ฐจ์›๊ณผ ์ผ์น˜ํ•œ๋‹ค๋Š” ๊ฒƒ์„ ์œ ์˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
# ๋ฐฐ์น˜ ์ฐจ์›ย ``N``ย ์€ 1 ์ฐจ์›์— ํ•ด๋‹นํ•ฉ๋‹ˆ๋‹ค.
#
Expand All @@ -246,7 +247,7 @@ def get_batch(source, i):
######################################################################
# ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ ํŒŒ์ดํ”„๋ผ์ธ์„ ํ™œ์šฉํ•œ ๋Œ€ํ˜• ํŠธ๋žœ์Šคํฌ๋จธ ๋ชจ๋ธ ํ•™์Šต์„ ๋ณด์ด๊ธฐ ์œ„ํ•ด,
# ํŠธ๋žœ์Šคํฌ๋จธ ๊ณ„์ธต ๊ทœ๋ชจ๋ฅผ ์ ์ ˆํžˆ ํ™•์žฅ์‹œํ‚ต๋‹ˆ๋‹ค.
# 4096์ฐจ์›์˜ ์ž„๋ฒ ๋”ฉ ๋ฒกํ„ฐ, 4096์˜ ์€๋‹‰ ์‚ฌ์ด์ฆˆ, 16๊ฐœ์˜ ์–ดํ…์…˜ ํ—ค๋“œ(attention head)์™€ ์ด 8 ๊ฐœ์˜
# 4096์ฐจ์›์˜ ์ž„๋ฒ ๋”ฉ ๋ฒกํ„ฐ, 4096์˜ ์€๋‹‰ ์‚ฌ์ด์ฆˆ, 16๊ฐœ์˜ ์–ดํ…์…˜ ํ—ค๋“œ(attention head)์™€ ์ด 8 ๊ฐœ์˜
# ํŠธ๋žœ์Šคํฌ๋จธ ๊ณ„์ธต (``nn.TransformerEncoderLayer``)๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์ตœ๋Œ€
# **~1 ์–ต** ๊ฐœ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ฐ–๋Š” ๋ชจ๋ธ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
#
Expand Down
4 changes: 2 additions & 2 deletions beginner_source/audio_feature_extractions_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def plot_kaldi_pitch(waveform, sample_rate, pitch, nfcc):
# Mel Filter Bank
# ---------------
#
# ``torchaudio.functional.create_fb_matrix`` generates the filter bank
# ``torchaudio.functional.melscale_fbanks`` generates the filter bank
# for converting frequency bins to mel-scale bins.
#
# Since this function does not require input audio/features, there is no
Expand All @@ -277,7 +277,7 @@ def plot_kaldi_pitch(waveform, sample_rate, pitch, nfcc):
n_mels = 64
sample_rate = 6000

mel_filters = F.create_fb_matrix(
mel_filters = F.melscale_fbanks(
int(n_fft // 2 + 1),
n_mels=n_mels,
f_min=0.,
Expand Down
10 changes: 5 additions & 5 deletions beginner_source/basics/autogradqs_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
# ์—์„œ ์ฐพ์•„๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
#

print('Gradient function for z =', z.grad_fn)
print('Gradient function for loss =', loss.grad_fn)
print(f"Gradient function for z = {z.grad_fn}")
print(f"Gradient function for loss = {loss.grad_fn}")

######################################################################
# ๋ณ€ํ™”๋„(Gradient) ๊ณ„์‚ฐํ•˜๊ธฐ
Expand Down Expand Up @@ -185,12 +185,12 @@
inp = torch.eye(5, requires_grad=True)
out = (inp+1).pow(2)
out.backward(torch.ones_like(inp), retain_graph=True)
print("First call\n", inp.grad)
print(f"First call\n{inp.grad}")
out.backward(torch.ones_like(inp), retain_graph=True)
print("\nSecond call\n", inp.grad)
print(f"\nSecond call\n{inp.grad}")
inp.grad.zero_()
out.backward(torch.ones_like(inp), retain_graph=True)
print("\nCall after zeroing gradients\n", inp.grad)
print(f"\nCall after zeroing gradients\n{inp.grad}")


######################################################################
Expand Down
6 changes: 3 additions & 3 deletions beginner_source/basics/buildmodel_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
# `torch.cuda <https://pytorch.org/docs/stable/notes/cuda.html>`_ ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€
# ํ™•์ธํ•˜๊ณ  ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด CPU๋ฅผ ๊ณ„์† ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

device = 'cuda' if torch.cuda.is_available() else 'cpu'
print(f'Using {device} device')
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Using {device} device")

##############################################
# ํด๋ž˜์Šค ์ •์˜ํ•˜๊ธฐ
Expand Down Expand Up @@ -176,7 +176,7 @@ def forward(self, x):
#


print("Model structure: ", model, "\n\n")
print(f"Model structure: {model}\n\n")

for name, param in model.named_parameters():
print(f"Layer: {name} | Size: {param.size()} | Values : {param[:2]} \n")
Expand Down
2 changes: 1 addition & 1 deletion beginner_source/basics/data_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def __getitem__(self, idx):


def __init__(self, annotations_file, img_dir, transform=None, target_transform=None):
self.img_labels = pd.read_csv(annotations_file, names=['file_name', 'label'])
self.img_labels = pd.read_csv(annotations_file)
self.img_dir = img_dir
self.transform = transform
self.target_transform = target_transform
Expand Down
7 changes: 3 additions & 4 deletions beginner_source/basics/quickstart_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
from torch import nn
from torch.utils.data import DataLoader
from torchvision import datasets
from torchvision.transforms import ToTensor, Lambda, Compose
import matplotlib.pyplot as plt
from torchvision.transforms import ToTensor

######################################################################
# PyTorch๋Š” `TorchText <https://pytorch.org/text/stable/index.html>`_, `TorchVision <https://pytorch.org/vision/stable/index.html>`_ ๋ฐ
Expand Down Expand Up @@ -66,8 +65,8 @@
test_dataloader = DataLoader(test_data, batch_size=batch_size)

for X, y in test_dataloader:
print("Shape of X [N, C, H, W]: ", X.shape)
print("Shape of y: ", y.shape, y.dtype)
print(f"Shape of X [N, C, H, W]: {X.shape}")
print(f"Shape of y: {y.shape} {y.dtype}")
break

######################################################################
Expand Down
10 changes: 5 additions & 5 deletions beginner_source/basics/tensorqs_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@

# GPU๊ฐ€ ์กด์žฌํ•˜๋ฉด ํ…์„œ๋ฅผ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค
if torch.cuda.is_available():
tensor = tensor.to('cuda')
tensor = tensor.to("cuda")


######################################################################
Expand All @@ -124,9 +124,9 @@
# **NumPy์‹์˜ ํ‘œ์ค€ ์ธ๋ฑ์‹ฑ๊ณผ ์Šฌ๋ผ์ด์‹ฑ:**

tensor = torch.ones(4, 4)
print('First row: ', tensor[0])
print('First column: ', tensor[:, 0])
print('Last column:', tensor[..., -1])
print(f"First row: {tensor[0]}")
print(f"First column: {tensor[:, 0]}")
print(f"Last column: {tensor[..., -1]}")
tensor[:,1] = 0
print(tensor)

Expand Down Expand Up @@ -171,7 +171,7 @@
# ์—ฐ์‚ฐ ๊ฒฐ๊ณผ๋ฅผ ํ”ผ์—ฐ์‚ฐ์ž(operand)์— ์ €์žฅํ•˜๋Š” ์—ฐ์‚ฐ์„ ๋ฐ”๊ฟ”์น˜๊ธฐ ์—ฐ์‚ฐ์ด๋ผ๊ณ  ๋ถ€๋ฅด๋ฉฐ, ``_`` ์ ‘๋ฏธ์‚ฌ๋ฅผ ๊ฐ–์Šต๋‹ˆ๋‹ค.
# ์˜ˆ๋ฅผ ๋“ค์–ด: ``x.copy_(y)`` ๋‚˜ ``x.t_()`` ๋Š” ``x`` ๋ฅผ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

print(tensor, "\n")
print(f"{tensor} \n")
tensor.add_(5)
print(tensor)

Expand Down
33 changes: 19 additions & 14 deletions beginner_source/text_sentiment_ngrams_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,35 @@
#
# torchtext ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๊ฐ€๊ณต๋˜์ง€ ์•Š์€ ํ…์ŠคํŠธ ๋ฌธ์žฅ๋“ค์„ ๋งŒ๋“œ๋Š”(yield) ๋ช‡ ๊ฐ€์ง€ ๊ธฐ์ดˆ ๋ฐ์ดํ„ฐ์…‹ ๋ฐ˜๋ณต์ž(raw dataset iterator)๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
# ์˜ˆ๋ฅผ ๋“ค์–ด, ``AG_NEWS`` ๋ฐ์ดํ„ฐ์…‹ ๋ฐ˜๋ณต์ž๋Š” ๋ ˆ์ด๋ธ”(label)๊ณผ ๋ฌธ์žฅ์˜ ํŠœํ”Œ(tuple) ํ˜•ํƒœ๋กœ ๊ฐ€๊ณต๋˜์ง€ ์•Š์€ ๋ฐ์ดํ„ฐ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.
#
# torchtext ๋ฐ์ดํ„ฐ์…‹์— ์ ‘๊ทผํ•˜๊ธฐ ์ „์—, https://github.com/pytorch/data ์„ ์ฐธ๊ณ ํ•˜์—ฌ torchdata๋ฅผ
# ์„ค์น˜ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.
#

import torch
from torchtext.datasets import AG_NEWS
train_iter = AG_NEWS(split='train')
train_iter = iter(AG_NEWS(split='train'))

######################################################################
# ::
#
# next(train_iter)
# >>> (3, "Wall St. Bears Claw Back Into the Black (Reuters) Reuters -
# Short-sellers, Wall Street's dwindling\\band of ultra-cynics, are seeing green
# again.")
# >>> (3, "Fears for T N pension after talks Unions representing workers at Turner
# Newall say they are 'disappointed' after talks with stricken parent firm Federal
# Mogul.")
#
# next(train_iter)
# >>> (3, 'Carlyle Looks Toward Commercial Aerospace (Reuters) Reuters - Private
# investment firm Carlyle Group,\\which has a reputation for making well-timed
# and occasionally\\controversial plays in the defense industry, has quietly
# placed\\its bets on another part of the market.')
# >>> (4, "The Race is On: Second Private Team Sets Launch Date for Human
# Spaceflight (SPACE.com) SPACE.com - TORONTO, Canada -- A second\\team of
# rocketeers competing for the #36;10 million Ansari X Prize, a contest
# for\\privately funded suborbital space flight, has officially announced
# the first\\launch date for its manned rocket.")
#
# next(train_iter)
# >>> (3, "Oil and Economy Cloud Stocks' Outlook (Reuters) Reuters - Soaring
# crude prices plus worries\\about the economy and the outlook for earnings are
# expected to\\hang over the stock market next week during the depth of
# the\\summer doldrums.")
# >>> (4, 'Ky. Company Wins Grant to Study Peptides (AP) AP - A company founded
# by a chemistry researcher at the University of Louisville won a grant to develop
# a method of producing better peptides, which are short chains of amino acids, the
# building blocks of proteins.')
#

######################################################################
Expand Down Expand Up @@ -75,7 +80,7 @@ def yield_tokens(data_iter):
# ::
#
# vocab(['here', 'is', 'an', 'example'])
# >>> [475, 21, 30, 5286]
# >>> [475, 21, 30, 5297]
#
# ํ† ํฌ๋‚˜์ด์ €์™€ ์–ดํœ˜์ง‘์„ ๊ฐ–์ถ˜ ํ…์ŠคํŠธ ์ฒ˜๋ฆฌ ํŒŒ์ดํ”„๋ผ์ธ์„ ์ค€๋น„ํ•ฉ๋‹ˆ๋‹ค.
# ํ…์ŠคํŠธ ํŒŒ์ดํ”„๋ผ์ธ๊ณผ ๋ ˆ์ด๋ธ”(label) ํŒŒ์ดํ”„๋ผ์ธ์€ ๋ฐ์ดํ„ฐ์…‹ ๋ฐ˜๋ณต์ž๋กœ๋ถ€ํ„ฐ ์–ป์–ด์˜จ ๊ฐ€๊ณต๋˜์ง€ ์•Š์€ ๋ฌธ์žฅ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.
Expand All @@ -91,7 +96,7 @@ def yield_tokens(data_iter):
# ::
#
# text_pipeline('here is the an example')
# >>> [475, 21, 2, 30, 5286]
# >>> [475, 21, 2, 30, 5297]
# label_pipeline('10')
# >>> 9
#
Expand Down
Loading

0 comments on commit 9810487

Please sign in to comment.