Spaces:
Runtime error
Runtime error
<!--- | |
Copyright 2022 The HuggingFace Team. All rights reserved. | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
โ ๏ธ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be | |
rendered properly in your Markdown viewer. | |
--> | |
# ํ๋ จ์ฉ ์ฌ์ฉ์ ๋ง์ถคํ ํ๋์จ์ด [[custom-hardware-for-training]] | |
๋ชจ๋ธ ํ๋ จ๊ณผ ์ถ๋ก ์ ์ฌ์ฉํ๋ ํ๋์จ์ด๋ ์ฑ๋ฅ์ ํฐ ์ํฅ์ ๋ฏธ์น ์ ์์ต๋๋ค. GPU์ ๋ํด ์์ธํ ์์๋ณด๋ ค๋ฉด, Tim Dettmer์ ํ๋ฅญํ ๋ธ๋ก๊ทธ ํฌ์คํธ๋ฅผ ํ์ธํด๋ณด์ธ์. [๋ธ๋ก๊ทธ ํฌ์คํธ ๋งํฌ](https://timdettmers.com/2020/09/07/which-gpu-for-deep-learning/) (์์ด๋ก ์์ฑ๋จ). | |
GPU ์ค์ ์ ๋ํ ์ค์ฉ์ ์ธ ์กฐ์ธ์ ์ดํด๋ณด๊ฒ ์ต๋๋ค. | |
## GPU [[gpu]] | |
๋ ํฐ ๋ชจ๋ธ์ ํ๋ จ์ํฌ ๋๋ ๊ธฐ๋ณธ์ ์ผ๋ก ์ธ ๊ฐ์ง ์ต์ ์ด ์์ต๋๋ค: | |
- ๋ ํฐ GPU | |
- ๋ ๋ง์ GPU | |
- ๋ ๋ง์ CPU ๋ฐ NVMe ([DeepSpeed-Infinity](../en/main_classes/deepspeed#nvme-support)๋ฅผ ํตํ ์คํ๋ก๋(offload)) | |
์ฐ์ , ํ๋์ GPU๋ง ์ฌ์ฉํ๋ ๊ฒฝ์ฐ๋ถํฐ ์์ํด๋ด ์๋ค. | |
### ์ ์ ๊ณต๊ธ๊ณผ ๋๊ฐ [[power-and-cooling]] | |
๋น์ผ ๊ณ ์ฑ๋ฅ GPU๋ฅผ ๊ตฌ๋งคํ ๊ฒฝ์ฐ, ์ฌ๋ฐ๋ฅธ ์ ์ ๊ณต๊ธ๊ณผ ์ถฉ๋ถํ ๋๊ฐ์ ์ ๊ณตํด์ผ ํฉ๋๋ค. | |
**์ ์ ๊ณต๊ธ**: | |
์ผ๋ถ ๊ณ ์ฑ๋ฅ ์๋น์์ฉ GPU๋ 2๊ฐ ํน์ ๊ฐ๋๊ฐ๋ค 3๊ฐ์ PCI-E 8ํ ์ ์ ์์ผ์ด ์์ต๋๋ค. ์นด๋์ ์๋ ์์ผ ์๋งํผ ๋ ๋ฆฝ์ ์ธ 12V PCI-E 8ํ ์ผ์ด๋ธ์ด ์ฐ๊ฒฐ๋์ด ์๋์ง ํ์ธํ์ธ์. ๊ฐ์ ์ผ์ด๋ธ์ ํ์ชฝ ๋์ ์๋ 2๊ฐ์ ์คํ๋ฆฟ(๋๋ ํผ๊ทธํ ์ผ(pigtail) ์ผ์ด๋ธ)์ ์ฌ์ฉํ์ง ๋ง์ธ์. ์ฆ, GPU์ 2๊ฐ์ ์์ผ์ด ์๋ค๋ฉด, PSU(์ ์ ๊ณต๊ธ ์ฅ์น)์์ ์นด๋๋ก ์ฐ๊ฒฐ๋๋ 2๊ฐ์ PCI-E 8ํ ์ผ์ด๋ธ์ด ํ์ํ๋ฉฐ, ๋์ 2๊ฐ์ PCI-E 8ํ ์ปค๋ฅํฐ๊ฐ ์๋ ์ผ์ด๋ธ์ด ํ์ํ์ง ์์ต๋๋ค! ๊ทธ๋ ์ง ์์ผ๋ฉด ์นด๋์ ์ ์ฒด ์ฑ๋ฅ์ ์ ๋๋ก ๋ฐํํ์ง ๋ชปํ ์ ์์ต๋๋ค. | |
๊ฐ๊ฐ์ PCI-E 8ํ ์ ์ ์ผ์ด๋ธ์ PSU ์ชฝ์ 12V ๋ ์ผ์ ์ฐ๊ฒฐ๋์ด์ผ ํ๋ฉฐ ์ต๋ 150W์ ์ ๋ ฅ์ ๊ณต๊ธํ ์ ์์ต๋๋ค. | |
์ผ๋ถ ๋ค๋ฅธ GPU๋ PCI-E 12ํ ์ปค๋ฅํฐ๋ฅผ ์ฌ์ฉํ๋ฉฐ, ์ด๋ฌํ ์ปค๋ฅํฐ๋ ์ต๋ 500W-600W์ ์ ๋ ฅ์ ๊ณต๊ธํ ์ ์์ต๋๋ค. | |
์ ๊ฐํ GPU๋ 6ํ ์ปค๋ฅํฐ๋ฅผ ์ฌ์ฉํ๋ฉฐ, ์ต๋ 75W์ ์ ๋ ฅ์ ๊ณต๊ธํฉ๋๋ค. | |
๋ํ GPU๊ฐ ์์ ์ ์ธ ์ ์์ ๋ฐ์ ์ ์๋๋ก ๊ณ ๊ธ PSU๋ฅผ ์ ํํด์ผ ํฉ๋๋ค. ์ผ๋ถ ์ ํ์ง์ PSU๋ GPU๊ฐ ์ต๊ณ ์ฑ๋ฅ์ผ๋ก ๋์ํ๊ธฐ ์ํด ํ์ํ ์ ์์ ์์ ์ ์ผ๋ก ๊ณต๊ธํ์ง ๋ชปํ ์ ์์ต๋๋ค. | |
๋ฌผ๋ก , PSU๋ GPU์ ์ ์์ ๊ณต๊ธํ๊ธฐ์ ์ถฉ๋ถํ ์ฌ๋ถ์ ์ ๋ ฅ ์ฉ๋์ ๊ฐ์ ธ์ผ ํฉ๋๋ค. | |
**๋๊ฐ**: | |
GPU๊ฐ ๊ณผ์ด๋๋ฉด ์ฑ๋ฅ์ด ์ ํ๋๊ณ ์ต๋ ์ฑ๋ฅ์ ๋ฐํํ์ง ๋ชปํ ์ ์์ผ๋ฉฐ, ๋๋ฌด ๋จ๊ฑฐ์์ง๋ฉด ์ค์ง๋ ์ ์์ต๋๋ค. | |
GPU๊ฐ ๊ณผ์ด๋ ๋ ์ ํํ ์ ์ ์จ๋๋ฅผ ์๊ธฐ ์ด๋ ค์ฐ๋, ์๋ง๋ +80โ ๋ฏธ๋ง์ด๋ฉด ์ข์ง๋ง ๋ ๋ฎ์์๋ก ์ข์ต๋๋ค. 70โ-75โ ์ ๋๊ฐ ํ๋ฅญํ ์จ๋ ๋ฒ์์ ๋๋ค. ์ฑ๋ฅ ์ ํ๊ฐ ๋ฐ์ํ๊ธฐ ์์ํ๋ ์จ๋๋ ๋๋ต 84โ-90โ ์ ๋์ผ ๊ฒ์ ๋๋ค. ํ์ง๋ง ์ฑ๋ฅ ์ ํ ์ด์ธ์๋ ์ง์์ ์ผ๋ก ๋งค์ฐ ๋์ ์จ๋๋ GPU ์๋ช ์ ๋จ์ถ์ํฌ ์ ์์ต๋๋ค. | |
์ด์ด์, ์ฌ๋ฌ ๊ฐ์ GPU๋ฅผ ์ฌ์ฉํ ๋ ๊ฐ์ฅ ์ค์ํ ์ธก๋ฉด ์ค ํ๋์ธ GPU ๊ฐ ์ฐ๊ฒฐ ๋ฐฉ์์ ์ดํด๋ณด๊ฒ ์ต๋๋ค. | |
### ๋ค์ค GPU ์ฐ๊ฒฐ ๋ฐฉ์ [[multigpu-connectivity]] | |
๋ค์ค GPU๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ GPU ๊ฐ์ ์ฐ๊ฒฐ ๋ฐฉ์์ ์ ์ฒด ํ๋ จ ์๊ฐ์ ํฐ ์ํฅ์ ๋ฏธ์น ์ ์์ต๋๋ค. ๋ง์ฝ GPU๊ฐ ๋์ผํ ๋ฌผ๋ฆฌ์ ๋ ธ๋์ ์์ ๊ฒฝ์ฐ, ๋ค์๊ณผ ๊ฐ์ด ํ์ธํ ์ ์์ต๋๋ค: | |
``` | |
nvidia-smi topo -m | |
``` | |
๋ง์ฝ NVLink๋ก ์ฐ๊ฒฐ๋ ๋์ผ GPU ํ๊ฒฝ์ด๋ผ๋ฉด, ๋ค์๊ณผ ๊ฐ์ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค: | |
``` | |
GPU0 GPU1 CPU Affinity NUMA Affinity | |
GPU0 X NV2 0-23 N/A | |
GPU1 NV2 X 0-23 N/A | |
``` | |
NVLink๋ฅผ ์ง์ํ์ง ์๋ ๋ค๋ฅธ ํ๊ฒฝ์ ๊ฒฝ์ฐ์๋ ๋ค์๊ณผ ๊ฐ์ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค: | |
``` | |
GPU0 GPU1 CPU Affinity NUMA Affinity | |
GPU0 X PHB 0-11 N/A | |
GPU1 PHB X 0-11 N/A | |
``` | |
์ด ๊ฒฐ๊ณผ์๋ ๋ค์๊ณผ ๊ฐ์ ๋ฒ๋ก๊ฐ ํฌํจ๋์ด ์์ต๋๋ค: | |
``` | |
X = Self | |
SYS = Connection traversing PCIe as well as the SMP interconnect between NUMA nodes (e.g., QPI/UPI) | |
NODE = Connection traversing PCIe as well as the interconnect between PCIe Host Bridges within a NUMA node | |
PHB = Connection traversing PCIe as well as a PCIe Host Bridge (typically the CPU) | |
PXB = Connection traversing multiple PCIe bridges (without traversing the PCIe Host Bridge) | |
PIX = Connection traversing at most a single PCIe bridge | |
NV# = Connection traversing a bonded set of # NVLinks | |
``` | |
๋ฐ๋ผ์ ์ฒซ ๋ฒ์งธ ๊ฒฐ๊ณผ์ `NV2`๋ GPU๊ฐ 2๊ฐ์ NVLink๋ก ์ฐ๊ฒฐ๋์ด ์๋ค๋ ๊ฒ์ ๋ํ๋ด๊ณ , ๋ ๋ฒ์งธ ๊ฒฐ๊ณผ์ `PHB`๋ ์ผ๋ฐ์ ์ธ ์๋น์์ฉ PCIe+๋ธ๋ฆฟ์ง ์ค์ ์ ๊ฐ์ง๊ณ ์๋ค๋ ๊ฒ์ ๋ํ๋ ๋๋ค. | |
์ค์ ์์ ์ด๋ค ์ ํ์ ์ฐ๊ฒฐ ๋ฐฉ์์ ๊ฐ์ง๊ณ ์๋์ง ํ์ธํ์ธ์. ์ผ๋ถ ์ฐ๊ฒฐ ๋ฐฉ์์ GPU ๊ฐ ํต์ ์ ๋ ๋น ๋ฅด๊ฒ ๋ง๋ค ์ ์์ผ๋ฉฐ(NVLink์ ๊ฐ์ด), ์ด๋ค ์ฐ๊ฒฐ ๋ฐฉ์์ ๋ ๋๋ฆฌ๊ฒ ๋ง๋ค ์ ์์ต๋๋ค(PHB์ ๊ฐ์ด). | |
์ฌ์ฉํ๋ ํ์ฅ์ฑ ์๋ฃจ์ ์ ์ข ๋ฅ์ ๋ฐ๋ผ ์ฐ๊ฒฐ ์๋๊ฐ ์ฃผ์ํ ์ํฅ์ ๋ฏธ์น ์๋ ์๊ณ ๋ฏธ๋ฏธํ ์ํฅ์ ๋ฏธ์น ์๋ ์์ต๋๋ค. DDP์ ๊ฐ์ด GPU๊ฐ ๊ฑฐ์ ๋๊ธฐํํ์ง ์์๋ ๋๋ ๊ฒฝ์ฐ, ์ฐ๊ฒฐ ์๋๊ฐ ๋๋ ค๋ ํฐ ์ํฅ์ ๋ฐ์ง ์์ต๋๋ค. ๋ฐ๋ฉด ZeRO-DP์ ๊ฐ์ด GPU๊ฐ ํต์ ์ด ๋ง์ด ํ์ํ ๊ฒฝ์ฐ, ๋ ๋น ๋ฅธ ํ๋ จ์ ์ํด์๋ ๋ ๋น ๋ฅธ ์ฐ๊ฒฐ ์๋๊ฐ ์ค์ํฉ๋๋ค. | |
#### NVLink [[nvlink]] | |
[NVLink](https://en.wikipedia.org/wiki/NVLink)๋ Nvidia์์ ๊ฐ๋ฐํ ์ ์ ๊ธฐ๋ฐ์ ์ง๋ ฌ ๋ค์ค ๋ ์ธ ๊ทผ๊ฑฐ๋ฆฌ ํต์ ๋งํฌ์ ๋๋ค. | |
์๋ก์ด ์ธ๋์ NVLink๋ ๋ ๋น ๋ฅธ ๋์ญํญ์ ์ ๊ณตํฉ๋๋ค. [Nvidia Ampere GA102 GPU Architecture](https://www.nvidia.com/content/dam/en-zz/Solutions/geforce/ampere/pdf/NVIDIA-ampere-GA102-GPU-Architecture-Whitepaper-V1.pdf)์์ ์๋์ ๊ฐ์ ์ ๋ณด๋ฅผ ํ์ธํ์ค ์ ์์ต๋๋ค: | |
> 3์ธ๋ NVLinkยฎ | |
> GA102 GPU๋ 4๊ฐ์ x4 ๋งํฌ๋ฅผ ํฌํจํ๋ NVIDIA์ 3์ธ๋ NVLink ์ธํฐํ์ด์ค๋ฅผ ํ์ฉํ๋ฉฐ, | |
> ๊ฐ ๋งํฌ๋ ๋ ๊ฐ์ GPU ๊ฐ์ ๊ฐ ๋ฐฉํฅ์ผ๋ก ์ด๋น 14.0625GB์ ๋์ญํญ์ ์ ๊ณตํฉ๋๋ค. | |
> 4๊ฐ์ ๋งํฌ๋ ๊ฐ ๋ฐฉํฅ์ ์ด๋น 56.25GB์ ๋์ญํญ์ ์ ๊ณตํ๋ฉฐ, ๋ ๊ฐ์ GPU ๊ฐ์๋ ์ด๋น 112.5GB์ ์ด ๋์ญํญ์ ์ ๊ณตํฉ๋๋ค. | |
> ๋ ๊ฐ์ RTX 3090 GPU๋ฅผ NVLink๋ฅผ ์ฌ์ฉํด SLI๋ก ์ฐ๊ฒฐํ ์ ์์ต๋๋ค. | |
> (3-Way ๋ฐ 4-Way SLI ๊ตฌ์ฑ์ ์ง์๋์ง ์์์ ์ ์ํ์ธ์.) | |
๋ฐ๋ผ์ `nvidia-smi topo -m`์ ๊ฒฐ๊ณผ์์ `NVX`์ ๊ฐ์ด ๋์์๋ก ๋ ์ข์ต๋๋ค. ์ธ๋๋ GPU ์ํคํ ์ฒ์ ๋ฐ๋ผ ๋ค๋ฅผ ์ ์์ต๋๋ค. | |
๊ทธ๋ ๋ค๋ฉด, gpt2๋ฅผ ์์ wikitext ์ํ๋ก ํ์ต์ํค๋ ์์ ๋ฅผ ํตํด, NVLink๊ฐ ํ๋ จ์ ์ด๋ค ์ํฅ์ ๋ฏธ์น๋์ง ์ดํด๋ณด๊ฒ ์ต๋๋ค. | |
๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค: | |
| NVlink | Time | | |
| ----- | ---: | | |
| Y | 101s | | |
| N | 131s | | |
NVLink ์ฌ์ฉ ์ ํ๋ จ์ด ์ฝ 23% ๋ ๋น ๋ฅด๊ฒ ์๋ฃ๋จ์ ํ์ธํ ์ ์์ต๋๋ค. ๋ ๋ฒ์งธ ๋ฒค์น๋งํฌ์์๋ `NCCL_P2P_DISABLE=1`์ ์ฌ์ฉํ์ฌ NVLink๋ฅผ ์ฌ์ฉํ์ง ์๋๋ก ์ค์ ํ์ต๋๋ค. | |
์ ์ฒด ๋ฒค์น๋งํฌ ์ฝ๋์ ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค: | |
```bash | |
# DDP w/ NVLink | |
rm -r /tmp/test-clm; CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch \ | |
--nproc_per_node 2 examples/pytorch/language-modeling/run_clm.py --model_name_or_path gpt2 \ | |
--dataset_name wikitext --dataset_config_name wikitext-2-raw-v1 --do_train \ | |
--output_dir /tmp/test-clm --per_device_train_batch_size 4 --max_steps 200 | |
{'train_runtime': 101.9003, 'train_samples_per_second': 1.963, 'epoch': 0.69} | |
# DDP w/o NVLink | |
rm -r /tmp/test-clm; CUDA_VISIBLE_DEVICES=0,1 NCCL_P2P_DISABLE=1 python -m torch.distributed.launch \ | |
--nproc_per_node 2 examples/pytorch/language-modeling/run_clm.py --model_name_or_path gpt2 \ | |
--dataset_name wikitext --dataset_config_name wikitext-2-raw-v1 --do_train | |
--output_dir /tmp/test-clm --per_device_train_batch_size 4 --max_steps 200 | |
{'train_runtime': 131.4367, 'train_samples_per_second': 1.522, 'epoch': 0.69} | |
``` | |
ํ๋์จ์ด: ๊ฐ๊ฐ 2๊ฐ์ TITAN RTX 24GB + 2๊ฐ์ NVLink (`NV2` in `nvidia-smi topo -m`) | |
์ํํธ์จ์ด: `pytorch-1.8-to-be` + `cuda-11.0` / `transformers==4.3.0.dev0` | |