Skip to content

Translate torchrec_tutorial #599 - #600

Merged
hyoyoung merged 4 commits into
PyTorchKR:masterfrom
gorae17:torchrec
Sep 14, 2022
Merged

Translate torchrec_tutorial #599#600
hyoyoung merged 4 commits into
PyTorchKR:masterfrom
gorae17:torchrec

Conversation

@gorae17

@gorae17 gorae17 commented Sep 8, 2022

Copy link
Copy Markdown
Contributor

๋ผ์ด์„ ์Šค ๋™์˜

๋ณ€๊ฒฝํ•ด์ฃผ์‹œ๋Š” ๋‚ด์šฉ์— BSD 3ํ•ญ ๋ผ์ด์„ ์Šค๊ฐ€ ์ ์šฉ๋จ์„ ๋™์˜ํ•ด์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋” ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๊ธฐ์—ฌํ•˜๊ธฐ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.

๋™์˜ํ•˜์‹œ๋ฉด ์•„๋ž˜ [ ]๋ฅผ [x]๋กœ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”.

  • ๊ธฐ์—ฌํ•˜๊ธฐ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์˜€์œผ๋ฉฐ, ๋ณธ PR ๋‚ด์šฉ์— BSD 3ํ•ญ ๋ผ์ด์„ ์Šค๊ฐ€ ์ ์šฉ๋จ์— ๋™์˜ํ•ฉ๋‹ˆ๋‹ค.

๊ด€๋ จ ์ด์Šˆ ๋ฒˆํ˜ธ

์ด Pull Request์™€ ๊ด€๋ จ์žˆ๋Š” ์ด์Šˆ ๋ฒˆํ˜ธ๋ฅผ ์ ์–ด์ฃผ์„ธ์š”.

์ด์Šˆ ๋˜๋Š” PR ๋ฒˆํ˜ธ ์•ž์— #์„ ๋ถ™์ด์‹œ๋ฉด ์ œ๋ชฉ์„ ๋ฐ”๋กœ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. (์˜ˆ. #999 )

PR ์ข…๋ฅ˜

์ด PR์— ํ•ด๋‹น๋˜๋Š” ์ข…๋ฅ˜ ์•ž์˜ [ ]์„ [x]๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”.

  • ์˜คํƒˆ์ž๋ฅผ ์ˆ˜์ •ํ•˜๊ฑฐ๋‚˜ ๋ฒˆ์—ญ์„ ๊ฐœ์„ ํ•˜๋Š” ๊ธฐ์—ฌ
  • ๋ฒˆ์—ญ๋˜์ง€ ์•Š์€ ํŠœํ† ๋ฆฌ์–ผ์„ ๋ฒˆ์—ญํ•˜๋Š” ๊ธฐ์—ฌ
  • ๊ณต์‹ ํŠœํ† ๋ฆฌ์–ผ ๋‚ด์šฉ์„ ๋ฐ˜์˜ํ•˜๋Š” ๊ธฐ์—ฌ
  • ์œ„ ์ข…๋ฅ˜์— ํฌํ•จ๋˜์ง€ ์•Š๋Š” ๊ธฐ์—ฌ

PR ์„ค๋ช…

์ด PR๋กœ ๋ฌด์—‡์ด ๋‹ฌ๋ผ์ง€๋Š”์ง€ ๋Œ€๋žต์ ์œผ๋กœ ์•Œ๋ ค์ฃผ์„ธ์š”.
torchrec_tutorial ํŽ˜์ด์ง€๊ฐ€ ํ•œ๊ตญ์–ด๋กœ ๋ฒˆ์—ญ๋ฉ๋‹ˆ๋‹ค.

@bub3690 bub3690 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค. ์–ด๋ ค์šด ๊ธ€์ด๊ตฐ์š”..
์˜คํƒ€ ์œ„์ฃผ๋กœ ์ ๊ฒ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

`dlrm <https://github.com/pytorch/torchrec/tree/main/examples/dlrm>`__
example, which includes multinode training on the criteo terabyte
dataset, using Metaโ€™s `DLRM <https://arxiv.org/abs/1906.00091>`__.
์˜ˆ์ œ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”. ์ด ์˜ˆ์ œ๋Š” Metaโ€™์˜ `DLRM <https://arxiv.org/abs/1906.00091>`__ ์„ ์‚ฌ์šฉํ•˜์—ฌ

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜ ๊ฐ€ ์žˆ์œผ๋‹ˆ โ€™๋Š” ๋นผ๋„ ๋˜๊ฒ ์Šต๋‹ˆ๋‹ค

์š”๊ตฌ ์‚ฌํ•ญ: python >= 3.7

We highly recommend CUDA when using TorchRec. If using CUDA: cuda >= 11.0
TorchRec์„ ์‚ฌ์šฉํ•  ๋•Œ๋Š” CUDA๋ฅผ ์ ๊ทน ์ถ”์ฒœํ•ฉ๋‹ˆ๋‹ค. CUDA๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ: cuda > = 11.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์›๋ณธ๊ณผ ๋‹ฌ๋ฆฌ> ๋’ค์— ๋„์–ด์“ฐ๊ธฐ๊ฐ€ ์ถ”๊ฐ€๋์Šต๋‹ˆ๋‹ค.

number of entity IDs per feature per example. In order to enable this
โ€œjaggedโ€ representation, we use the TorchRec datastructure
|KeyedJaggedTensor|_ (KJT).
์˜ˆ์ œ ๋ฐ ๊ธฐ๋Šฅ๋ณ„๋กœ ์—”ํ‹ฐํ‹ฐ ID๊ฐ€ ์ž„์˜์˜ ์ˆ˜์ธ ๋‹ค์–‘ํ•œ ์˜ˆ์ œ๋ฅผ ํšจ์œจ์ ์œผ๋ฃŒ ๋‚˜ํƒ€๋‚ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

This comment was marked as abuse.


Putting it all together, querying our distributed model with a KJT minibatch
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
์ด์ •๋ฆฌ: KJT ๋ฏธ๋‹ˆ๋ฐฐ์น˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ถ„์‚ฐ ๋ชจ๋ธ ์ฟผ๋ฆฌํ•˜๊ธฐ

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด์ •๋ฆฌ ๋ผ๋Š” ๋‚ด์šฉ์ด ์žˆ๋‚˜์š”?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋’ค๋Šฆ๊ฒŒ ์ดํ•ดํ–ˆ์Šต๋‹ˆ๋‹ค.
"์ด์ •๋ฆฌํ•˜์—ฌ, KJT ๋ฏธ๋‹ˆ๋ฐฐ์น˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ถ„์‚ฐ ๋ชจ๋ธ ์ฟผ๋ฆฌํ•˜๊ธฐ"
: ๋Œ€์‹  ํ•œ๋ฌธ์žฅ์œผ๋กœ ํ•˜๋Š”๊ฒŒ ์–ด๋–ค๊ฐ€์š”?

@hyoyoung hyoyoung added the ์ปจํŠธ๋ฆฌ๋ทฐํ†ค ์˜คํ”ˆ์†Œ์Šค ์ปจํŠธ๋ฆฌ๋ทฐํ†ค ๊ด€๋ จ ์ด์Šˆ/PR label Sep 9, 2022

@hyoyoung hyoyoung left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ธด ๊ธ€ ๋ฒˆ์—ญํ•˜์‹œ๋А๋ผ ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค

๋ช‡๊ฐ€์ง€ ์ˆ˜์ •์‚ฌํ•ญ์„ ์ œ์•ˆ๋“œ๋ฆฝ๋‹ˆ๋‹ค

called |DistributedModelParallel|_,
or DMP. Like PyTorchโ€™s DistributedDataParallel, DMP wraps a model to
enable distributed training.
์ถ”์ฒœ ์‹œ์Šคํ…œ์„ ๊ตฌ์ถ•ํ•  ๋•Œ, ์ œํ’ˆ์ด๋‚˜ ํŽ˜์ด์ง€์™€ ๊ฐ™์€ ์—”ํ‹ฐํ‹ฐ๋ฅผ ์ž„๋ฒ ๋””๋“œ๋กœ ํ‘œํ˜„ํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์Šต๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entities๋Š” ๋ณดํ†ต ์กด์žฌ๋‚˜ ๋…๋ฆฝ์ฒด ๋“ฑ์œผ๋กœ ๋ฒˆ์—ญ๋˜๋‚˜
์—ฌ๊ธฐ์„œ๋Š” ๊ฐ์ฒด๋กœ ์˜์—ญํ•ด๋„ ์ข‹์„๋“ฏํ•ฉ๋‹ˆ๋‹ค
embedding์€ ๋‚ด์žฅ๋œ๋‹ค๊ณ  ํ•˜๊ฑฐ๋‚˜, ๋ฒˆ์—ญํ•˜์ง€ ์•Š๊ณ  ์ž„๋ฒ ๋”ฉ์œผ๋กœ ๋ผ๊ณ  ํ•ด๋„ ์ข‹์„๋“ฏ ํ•ฉ๋‹ˆ๋‹ค

enable distributed training.
์ถ”์ฒœ ์‹œ์Šคํ…œ์„ ๊ตฌ์ถ•ํ•  ๋•Œ, ์ œํ’ˆ์ด๋‚˜ ํŽ˜์ด์ง€์™€ ๊ฐ™์€ ์—”ํ‹ฐํ‹ฐ๋ฅผ ์ž„๋ฒ ๋””๋“œ๋กœ ํ‘œํ˜„ํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์Šต๋‹ˆ๋‹ค.
Meta AI์˜ `๋”ฅ๋Ÿฌ๋‹ ์ถ”์ฒœ ๋ชจ๋ธ <https://arxiv.org/abs/1906.00091>`__ ๋˜๋Š” DLRM์„ ์˜ˆ๋กœ ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์—”ํ‹ฐํ‹ฐ์˜ ์ˆ˜๊ฐ€ ์ฆ๊ฐ€ํ•จ์— ๋”ฐ๋ผ, ์ž„๋ฒ ๋””๋“œ ํ…Œ์ด๋ธ”์˜ ํฌ๊ธฐ๊ฐ€ ๋‹จ์ผ GPU์˜ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ดˆ๊ณผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ž„๋ฒ ๋”ฉ ํ…Œ์ด๋ธ”์ด ์กฐ๊ธˆ ๋” ์ž์—ฐ์Šค๋Ÿฝ์ง€ ์•Š์„๊นŒ์š”?


Distributed Setup
~~~~~~~~~~~~~~~~~
๋ถ„์‚ฐ ์…‹์—…

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์…‹์—…์€ ์„ค์ •์œผ๋กœ ์ˆœํ™” ๊ฐ€๋Šฅ ํ•  ๋“ฏ ๋ณด์ž…๋‹ˆ๋‹ค. ์•„๋ž˜ ๋ฌธ๋‹จ์—์„œ๋„ ๊ทธ๋ ‡๊ฒŒ ์‚ฌ์šฉํ•˜์‹ ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค

~~~~~~~~~~~~~~~~~~~~~~~~

Now, weโ€™re ready to wrap our model with |DistributedModelParallel|_ (DMP). Instantiating DMP will:
์ด์ œ ๋ชจ๋ธ์„ |DistributedModelParallel|_ (DMP)๋กœ ๋ž˜ํ•‘ํ•  ์ค€๋น„๊ฐ€ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ž˜ํ•‘์€ ๊ฐ์‹ธ๋‘๊ธฐ๋กœ ์ˆœํ™” ๊ฐ€๋Šฅํ•  ๋“ฏ ํ•ฉ๋‹ˆ๋‹ค

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hyoyoung ์šฉ์–ด์ง‘์— wrapper๋ฅผ ๋ž˜ํผ๋กœ ๋ฒˆ์—ญํ•œ๋‹ค๊ณ  ํ•˜์—ฌ ๋ž˜ํ•‘์ด๋ผ๊ณ  ์‚ฌ์šฉํ•˜์˜€๋Š”๋ฐ, ์ˆœํ™”ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์„๊นŒ์š”?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrapper๋Š” ์šฉ์–ด์ง‘์— ๋ž˜ํผ๋ผ๊ณ  ๋˜์–ด์žˆ๊ณ , ๋ณดํ†ต ๋ณ‘๊ธฐ๋ฅผ ํ•ด์„œ ์“ฐ๊ณคํ•ฉ๋‹ˆ๋‹ค
์ทจํ–ฅ์ฐจ์— ๊ฐ€๊นŒ์šด๋ฐ, ์ €๋Š” ๋ž˜ํผ๋Š” ๋”ฐ๋กœ ๋ฒˆ์—ญํ•˜๊ธฐ๊ฐ€ ์–ด๋ ต๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ ๋ž˜ํผ(wrapper)๋กœ ์“ฐ๊ธฐ๋ฅผ ๊ถŒ์œ ํ•˜๊ณ 
wrapping์€ ๊ฐ์‹ธ๋‘๊ธฐ, ํฌ์žฅํ•˜๊ธฐ๋กœ ์ˆœํ™”ํ•˜๊ธฐ ์‰ฝ๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ ๋ฐ”๊ฟ”๋‹ฌ๋ผ๊ณ  ์š”์ฒญ์„ ํ•˜๋Š” ํŽธ์ž…๋‹ˆ๋‹ค.

ํ•ด๋‹น ๋ถ€๋ถ„ ๋‹ค์‹œ ์ฝ์–ด๋ณด์‹œ๊ณ , ๋ž˜ํ•‘์ด ๋” ๋‚ซ๋‹ค๋ฉด, ๋Œ“๊ธ€๋กœ ์–˜๊ธฐํ•ด์ฃผ์‹ ๋’ค์— ๊ทธ๋Œ€๋กœ ๋‘์…”๋„ ๋ฌด๋ฐฉํ•ฉ๋‹ˆ๋‹ค.

embedding table(s) (i.e., the EmbeddingBagCollection).
2. Actually shard the model. This includes allocating memory for each
embedding table on the appropriate device(s).
1. ๋ชจ๋ธ์„ ์ƒค๋”ฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค. DMP๋Š” ์ด์šฉ ๊ฐ€๋Šฅํ•œ โ€˜shardersโ€™๋ฅผ ์ˆ˜์ง‘ํ•˜๊ณ 

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์—ฌ๊ธฐ์„œ ์ƒค๋”ฉ(shard)๋ผ๊ณ  ๋ณ‘๊ธฐํ•ด๋„ ์ข‹์„๋“ฏ ํ•ฉ๋‹ˆ๋‹ค

Note that the KJT batch size is
``batch_size = len(lengths)//len(keys)``. In the above example,
batch_size is 3.
KJT ๋ฐฐ์น˜ ํฌ๊ธฐ๋Š” ``batch_size = len(lengths)//len(keys)`` ์ž…๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note ๋ถ€๋ถ„์€ ์‚ด๋ ค์„œ ๋ฒˆ์—ญํ•ด๋„ ์ข‹์„๋“ฏ ํ•ฉ๋‹ˆ๋‹ค

KJT ๋ฐฐ์น˜ ํฌ๊ธฐ๋Š” batch_size = len(lengths)//len(keys) ์ธ ๊ฒƒ์„ ๋ˆˆ์—ฌ๊ฒจ ๋ด์ฃผ์„ธ์š”.

์ •๋„๋Š” ์–ด๋–จ๊นŒ์š”?


Finally, we can query our model using our minibatch of products and
users.
๋งˆ์ง€๋ง‰์œผ๋กœ ์ œํ’ˆ๊ณผ ์‚ฌ์šฉ์ž์˜ ๋ฏธ๋‹ˆ๋ฐฐ์น˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋ธ์„ ์ฟผ๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ฟผ๋ฆฌ๋Š” ์งˆ์˜๋กœ ์ˆœํ™”ํ•ด๋„ ๋  ๋“ฏํ•ฉ๋‹ˆ๋‹ค

@gorae17
gorae17 requested review from bub3690 and hyoyoung September 12, 2022 14:32

@hyoyoung hyoyoung left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ช‡๊ฐ€์ง€ ์ถ”๊ฐ€ ์ œ์•ˆ์„ ๋“œ๋ฆฝ๋‹ˆ๋‹ค

called |DistributedModelParallel|_,
or DMP. Like PyTorchโ€™s DistributedDataParallel, DMP wraps a model to
enable distributed training.
์ถ”์ฒœ ์‹œ์Šคํ…œ์„ ๊ตฌ์ถ•ํ•  ๋•Œ, ์ œํ’ˆ์ด๋‚˜ ํŽ˜์ด์ง€์™€ ๊ฐ™์€ ๊ฐ์ฒด๋ฅผ ์ž„๋ฒ ๋”ฉ์œผ๋กœ ํ‘œํ˜„ํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์Šต๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ตฌ์ถ•๋ณด๋‹ค๋Š” ์กฐ๊ธˆ ๋” ์‰ฌ์šด ๋‹จ์–ด์ธ, ๋งŒ๋“ค ๋•Œ๋กœ ๋ฐ”๊พธ๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?

enable distributed training.
์ถ”์ฒœ ์‹œ์Šคํ…œ์„ ๊ตฌ์ถ•ํ•  ๋•Œ, ์ œํ’ˆ์ด๋‚˜ ํŽ˜์ด์ง€์™€ ๊ฐ™์€ ๊ฐ์ฒด๋ฅผ ์ž„๋ฒ ๋”ฉ์œผ๋กœ ํ‘œํ˜„ํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์Šต๋‹ˆ๋‹ค.
Meta AI์˜ `๋”ฅ๋Ÿฌ๋‹ ์ถ”์ฒœ ๋ชจ๋ธ <https://arxiv.org/abs/1906.00091>`__ ๋˜๋Š” DLRM์„ ์˜ˆ๋กœ ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์—”ํ‹ฐํ‹ฐ์˜ ์ˆ˜๊ฐ€ ์ฆ๊ฐ€ํ•จ์— ๋”ฐ๋ผ, ์ž„๋ฒ ๋”ฉ ํ…Œ์ด๋ธ”์˜ ํฌ๊ธฐ๊ฐ€ ๋‹จ์ผ GPU์˜ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ดˆ๊ณผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์œ„์—๋Š” ๊ฐ์ฒด์ธ๋ฐ, ์—ฌ๊ธฐ์„œ๋Š” ์—”ํ‹ฐํ‹ฐ๋กœ ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค

์ถ”์ฒœ ์‹œ์Šคํ…œ์„ ๊ตฌ์ถ•ํ•  ๋•Œ, ์ œํ’ˆ์ด๋‚˜ ํŽ˜์ด์ง€์™€ ๊ฐ™์€ ๊ฐ์ฒด๋ฅผ ์ž„๋ฒ ๋”ฉ์œผ๋กœ ํ‘œํ˜„ํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์Šต๋‹ˆ๋‹ค.
Meta AI์˜ `๋”ฅ๋Ÿฌ๋‹ ์ถ”์ฒœ ๋ชจ๋ธ <https://arxiv.org/abs/1906.00091>`__ ๋˜๋Š” DLRM์„ ์˜ˆ๋กœ ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์—”ํ‹ฐํ‹ฐ์˜ ์ˆ˜๊ฐ€ ์ฆ๊ฐ€ํ•จ์— ๋”ฐ๋ผ, ์ž„๋ฒ ๋”ฉ ํ…Œ์ด๋ธ”์˜ ํฌ๊ธฐ๊ฐ€ ๋‹จ์ผ GPU์˜ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ดˆ๊ณผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ผ๋ฐ˜์ ์ธ ๋ฐฉ๋ฒ•์€ ๋ชจ๋ธ ๋ณ‘๋ ฌํ™”์˜ ์ผ์ข…์œผ๋กœ, ์ž„๋ฒ ๋”ฉ ํ…Œ์ด๋ธ”์„ ์—ฌ๋Ÿฌ ๋””๋ฐ”์ด์Šค๋กœ ์ƒค๋”ฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•„๋ž˜ ์ƒค๋”ฉ(shard) ๋ณ‘๊ธฐ๋ฅผ ์—ฌ๊ธฐ๋กœ ๋ฐ”๊พธ๋Š”๊ฒŒ ๋” ์ข‹์„๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค

~~~~~~~~~~~~~~~~~~~~~~~~

Now, weโ€™re ready to wrap our model with |DistributedModelParallel|_ (DMP). Instantiating DMP will:
์ด์ œ ๋ชจ๋ธ์„ |DistributedModelParallel|_ (DMP)๋กœ ๋ž˜ํ•‘ํ•  ์ค€๋น„๊ฐ€ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrapper๋Š” ์šฉ์–ด์ง‘์— ๋ž˜ํผ๋ผ๊ณ  ๋˜์–ด์žˆ๊ณ , ๋ณดํ†ต ๋ณ‘๊ธฐ๋ฅผ ํ•ด์„œ ์“ฐ๊ณคํ•ฉ๋‹ˆ๋‹ค
์ทจํ–ฅ์ฐจ์— ๊ฐ€๊นŒ์šด๋ฐ, ์ €๋Š” ๋ž˜ํผ๋Š” ๋”ฐ๋กœ ๋ฒˆ์—ญํ•˜๊ธฐ๊ฐ€ ์–ด๋ ต๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ ๋ž˜ํผ(wrapper)๋กœ ์“ฐ๊ธฐ๋ฅผ ๊ถŒ์œ ํ•˜๊ณ 
wrapping์€ ๊ฐ์‹ธ๋‘๊ธฐ, ํฌ์žฅํ•˜๊ธฐ๋กœ ์ˆœํ™”ํ•˜๊ธฐ ์‰ฝ๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ ๋ฐ”๊ฟ”๋‹ฌ๋ผ๊ณ  ์š”์ฒญ์„ ํ•˜๋Š” ํŽธ์ž…๋‹ˆ๋‹ค.

ํ•ด๋‹น ๋ถ€๋ถ„ ๋‹ค์‹œ ์ฝ์–ด๋ณด์‹œ๊ณ , ๋ž˜ํ•‘์ด ๋” ๋‚ซ๋‹ค๋ฉด, ๋Œ“๊ธ€๋กœ ์–˜๊ธฐํ•ด์ฃผ์‹ ๋’ค์— ๊ทธ๋Œ€๋กœ ๋‘์…”๋„ ๋ฌด๋ฐฉํ•ฉ๋‹ˆ๋‹ค.

์˜คํ”„์…‹์€ ์‹œํ€€์Šค๊ฐ€ ๊ฐ ์˜ˆ์ œ์—์„œ ๊ฐ€์ ธ์˜ค๋Š” ๊ฐ’์˜ ์ˆ˜์˜ ํ•ฉ์ธ 1-D ํ…์„œ์ž…๋‹ˆ๋‹ค.

Letโ€™s look at an example, recreating the product EmbeddingBag above:
์œ„์˜ EmbeddingBag๋ฅผ ๋งŒ๋“œ๋Š” ์˜ˆ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recreating the product์˜ ์˜๋ฏธ๋ฅผ ์‚ด๋ ค์ฃผ๋Š”๊ฒŒ ์กฐ๊ธˆ ๋” ๋‚˜์„๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค.
์œ„์˜ ์˜ˆ์ œ์™€ ๋‹ค๋ฅธ ๋ฐฉ์‹์œผ๋กœ ์ž„๋ฒ ๋”ฉ๋ฐฑ์„ ๋งŒ๋“ค์—ˆ์œผ๋‹ˆ๊นŒ์š”

์œ„์˜ EmbeddingBag์„ ๋‹ค์‹œ ๋งŒ๋“ค์–ด๋ณด๋Š”, ์˜ˆ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

number of entity IDs per feature per example. In order to enable this
โ€œjaggedโ€ representation, we use the TorchRec datastructure
|KeyedJaggedTensor|_ (KJT).
์˜ˆ์ œ ๋ฐ ๊ธฐ๋Šฅ๋ณ„๋กœ ์—”ํ‹ฐํ‹ฐ ID๊ฐ€ ์ž„์˜์˜ ์ˆ˜์ธ ๋‹ค์–‘ํ•œ ์˜ˆ์ œ๋ฅผ ํšจ์œจ์ ์œผ๋กœ ๋‚˜ํƒ€๋‚ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์—”ํ‹ฐํ‹ฐ -> ๊ฐ์ฒด

bags, โ€œproductโ€ and โ€œuserโ€. Assume the minibatch is made up of three
examples for three users. The first of which has two product IDs, the
second with none, and the third with one product ID.
โ€œproductโ€ ์™€ โ€œuserโ€, 2๊ฐœ์˜ ์ž„๋ฒ ๋”ฉ ๊ทธ๋ฃน์˜ ์ปฌ๋ ‰์…˜์„ ์ฐธ์กฐํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์‚ดํŽด๋ด…๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์œ„์—์„œ๋Š” embeeding bags๋ฅผ ๋Œ€๊ฒŒ EmbeddingBag๋ผ๊ณ  ๋ฒˆ์—ญ์ด ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค.
์—ฌ๊ธฐ์„œ๋„ ๋งž์ถ”๋Š”๊ฒŒ ๋” ์ข‹์„๋“ฏํ•ฉ๋‹ˆ๋‹ค

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์›๋ฌธ์—์„œ EmbeddingBag์œผ๋กœ ์‚ฌ์šฉํ•œ ๋ถ€๋ถ„๊ณผ embedding bags๋กœ ์‚ฌ์šฉํ•œ ๋ถ€๋ถ„์„ ๊ตฌ๋ถ„ํ•ด์„œ ๋ฒˆ์—ญํ•˜๊ณ ์ž ํ•˜์˜€๋Š”๋ฐ์š”.
์ œ์•ˆํ•ด์ฃผ์‹ ๋Œ€๋กœ ํ†ต์ผํ•ด๋„ ์˜๋ฏธ๊ฐ€ ๋‹ฌ๋ผ์ง€์ง€ ์•Š์œผ๋‹ˆ ํ†ต์ผํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

This tutorial will cover three pieces of TorchRec: the ``nn.module`` |EmbeddingBagCollection|_, the |DistributedModelParallel|_ API, and
the datastructure |KeyedJaggedTensor|_.
์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” TorchRec์˜ 3๊ฐ€์ง€ ๋ถ€๋ถ„์„ ๋‹ค๋ฃน๋‹ˆ๋‹ค.
๊ทธ 3๊ฐ€์ง€๋Š” ``nn.module`` |EmbeddingBagCollection|_, |DistributedModelParallel|_ API, ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ |KeyedJaggedTensor|_ ์ž…๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์›๋ฌธ์˜ ๋œป์— ์ถฉ์‹คํ•˜๊ฒŒ ๋ฒˆ์—ญ์„ ํ•ด์ฃผ์…จ๋Š”๋ฐ
'์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” A, B, C ์ด๋ ‡๊ฒŒ TorchRec์˜ ์„ธ ๊ฐ€์ง€ ๋‚ด์šฉ์„ ๋‹ค๋ฃฐ ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.' ์ด๋Ÿฐ์‹์œผ๋กœ ํ‘œํ˜„๋˜๋Š”๊ฒŒ ๋” ์ž์—ฐ์Šค๋Ÿฝ์ง€ ์•Š์„๊นŒ ์ œ์•ˆ๋“œ๋ ค๋ด…๋‹ˆ๋‹ค.

Query vanilla nn.EmbeddingBag with input and offsets
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
์ž…๋ ฅ๊ณผ ์˜คํ”„์…‹์ด ์žˆ๋Š” ๋ฐ”๋‹๋ผ nn.EmbeddingBag ์งˆ์˜
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฐ”๋‹๋ผ๋ฅผ ๋งŽ์ด ์“ฐ๊ธฐ๋„ ํ•˜์ง€๋งŒ '๊ธฐ๋ณธ' ๋“ฑ์œผ๋กœ ๋ฒˆ์—ญ๋˜๋ฉด ์–ด๋–จ๊นŒ์š”?

โ€œjaggedโ€ representation, we use the TorchRec datastructure
|KeyedJaggedTensor|_ (KJT).
์˜ˆ์ œ ๋ฐ ๊ธฐ๋Šฅ๋ณ„๋กœ ์—”ํ‹ฐํ‹ฐ ID๊ฐ€ ์ž„์˜์˜ ์ˆ˜์ธ ๋‹ค์–‘ํ•œ ์˜ˆ์ œ๋ฅผ ํšจ์œจ์ ์œผ๋กœ ๋‚˜ํƒ€๋‚ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
์ด โ€œjaggedโ€ ํ‘œํ˜„์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด, TorchRec ๋ฐ์ดํ„ฐ๊ตฌ์กฐ |KeyedJaggedTensor|_ (KJT)๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'โ€œjaggedโ€ ํ‘œํ˜„์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด'๊ฐ€ ์–ด๋–ค ์˜๋ฏธ๋กœ ๋ฒˆ์—ญํ•˜์…จ๋Š”์ง€ ์ดํ•ด๋Š” ๋˜๋Š”๋ฐ ๊ฐœ์ธ์ ์ธ ์˜๊ฒฌ์œผ๋กœ๋Š”
๋‹ค์–‘ํ•œ/์œ ์—ฐํ•œ ํ‘œํ˜„์ด ๊ฐ€๋Šฅํ•˜๋„๋ก? ์ด๋Ÿฐ ์‹์œผ๋กœ ๋ฒˆ์—ญํ•˜๋Š” ๊ฒƒ์€ ์–ด๋–จ์ง€ ์ œ์•ˆ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

@gorae17
gorae17 requested review from bub3690, garam24 and hyoyoung and removed request for bub3690, garam24 and hyoyoung September 13, 2022 12:29
@gorae17
gorae17 removed the request for review from hyoyoung September 13, 2022 12:33
@gorae17
gorae17 requested review from garam24 and hyoyoung and removed request for garam24 September 13, 2022 12:33

@hyoyoung hyoyoung left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good

@hyoyoung
hyoyoung merged commit 601a656 into PyTorchKR:master Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

์ปจํŠธ๋ฆฌ๋ทฐํ†ค ์˜คํ”ˆ์†Œ์Šค ์ปจํŠธ๋ฆฌ๋ทฐํ†ค ๊ด€๋ จ ์ด์Šˆ/PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants