Instructions to use AbdulElahGwaith/transformers with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AbdulElahGwaith/transformers with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("AbdulElahGwaith/transformers", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download docs/source/ko/accelerator_selection.md from AbdulElahGwaith/transformers: direct link, hf CLI and curl.
- Browser
- Download file 5.6 kB
-
https://huggingface.co/AbdulElahGwaith/transformers/resolve/main/docs/source/ko/accelerator_selection.md
- Command line
-
hf download hf://AbdulElahGwaith/transformers/docs/source/ko/accelerator_selection.md
-
curl -L -o accelerator_selection.md https://huggingface.co/AbdulElahGwaith/transformers/resolve/main/docs/source/ko/accelerator_selection.md
GPU ์ ํํ๊ธฐ [[gpu-selection]]
๋ถ์ฐ ํ์ต ๊ณผ์ ์์ ์ฌ์ฉํ GPU์ ๊ฐ์์ ์์๋ฅผ ์ ํ ์ ์์ต๋๋ค. ์ด ๋ฐฉ๋ฒ์ ์๋ก ๋ค๋ฅธ ์ฐ์ฐ ์ฑ๋ฅ์ ๊ฐ์ง GPU๊ฐ ์์ ๋ ๋ ๋น ๋ฅธ GPU๋ฅผ ์ฐ์ ์ ์ผ๋ก ์ฌ์ฉํ๊ฑฐ๋, ์ฌ์ฉ ๊ฐ๋ฅํ GPU ์ค ์ผ๋ถ๋ง ์ ํํ์ฌ ํ์ฉํ๊ณ ์ ํ ๋ ์ ์ฉํฉ๋๋ค. ์ด ์ ํ ๊ณผ์ ์ DistributedDataParallel๊ณผ DataParallel์์ ๋ชจ๋ ์๋ํฉ๋๋ค. Accelerate๋ DeepSpeed ํตํฉ์ ํ์ํ์ง ์์ต๋๋ค.
์ด ๊ฐ์ด๋๋ ์ฌ์ฉํ GPU์ ๊ฐ์๋ฅผ ์ ํํ๋ ๋ฐฉ๋ฒ๊ณผ ์ฌ์ฉ ์์๋ฅผ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํฉ๋๋ค.
GPU ๊ฐ์ ์ง์ [[number-of-gpus]]
์๋ฅผ ๋ค์ด, GPU๊ฐ 4๊ฐ ์๊ณ ๊ทธ์ค ์ฒ์ 2๊ฐ๋ง ์ฌ์ฉํ๋ ค๋ ๊ฒฝ์ฐ, ์๋ ๋ช ๋ น์ด๋ฅผ ์คํํ์ธ์.
์ฌ์ฉํ GPU ๊ฐ์๋ฅผ ์ ํ๊ธฐ ์ํด --nproc_per_node ์ต์
์ ์ฌ์ฉํ์ธ์.
torchrun --nproc_per_node=2 trainer-program.py ...
์ฌ์ฉํ GPU ๊ฐ์๋ฅผ ์ ํ๊ธฐ ์ํด --num_processes ์ต์
์ ์ฌ์ฉํ์ธ์.
accelerate launch --num_processes 2 trainer-program.py ...
์ฌ์ฉํ GPU ๊ฐ์๋ฅผ ์ ํ๊ธฐ ์ํด --num_gpus ์ต์
์ ์ฌ์ฉํ์ธ์.
deepspeed --num_gpus 2 trainer-program.py ...
GPU ์์ [[order-of-gpus]]
์ฌ์ฉํ GPU์ ๊ทธ ์์๋ฅผ ์ง์ ํ๋ ค๋ฉด CUDA_VISIBLE_DEVICES ํ๊ฒฝ ๋ณ์๋ฅผ ์ค์ ํ์ธ์. ๊ฐ์ฅ ์ฌ์ด ๋ฐฉ๋ฒ์ ~/bashrc ๋๋ ๋ค๋ฅธ ์์ ์ค์ ํ์ผ์์ ํด๋น ๋ณ์๋ฅผ ์ค์ ํ๋ ๊ฒ์
๋๋ค. CUDA_VISIBLE_DEVICES๋ ์ฌ์ฉํ GPU๋ฅผ ๋งคํํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค. ์๋ฅผ ๋ค์ด, GPU๊ฐ 4๊ฐ (0, 1, 2, 3) ์๊ณ ๊ทธ์ค์์ 0๋ฒ๊ณผ 2๋ฒ GPU๋ง ์ฌ์ฉํ๊ณ ์ถ์ ๊ฒฝ์ฐ, ๋ค์๊ณผ ๊ฐ์ด ์ค์ ํ ์ ์์ต๋๋ค:
CUDA_VISIBLE_DEVICES=0,2 torchrun trainer-program.py ...
์ค์ง ๋ ๊ฐ์ ๋ฌผ๋ฆฌ์ GPU(0, 2)๋ง PyTorch์์ "๋ณด์ด๋" ์ํ๊ฐ ๋๋ฉฐ, ๊ฐ๊ฐ cuda:0๊ณผ cuda:1๋ก ๋งคํ๋ฉ๋๋ค. ๋ํ, GPU ์ฌ์ฉ ์์๋ฅผ ๋ฐ๋๋ก ์ค์ ํ ์๋ ์์ต๋๋ค. ์ด ๊ฒฝ์ฐ, GPU 0์ด cuda:1, GPU 2๊ฐ cuda:0์ผ๋ก ๋งคํ๋ฉ๋๋ค."
CUDA_VISIBLE_DEVICES=2,0 torchrun trainer-program.py ...
CUDA_VISIBLE_DEVICES ํ๊ฒฝ ๋ณ์๋ฅผ ๋น ๊ฐ์ผ๋ก ์ค์ ํ์ฌ GPU๊ฐ ์๋ ํ๊ฒฝ์ ๋ง๋ค ์๋ ์์ต๋๋ค.
CUDA_VISIBLE_DEVICES= python trainer-program.py ...
๋ค๋ฅธ ํ๊ฒฝ ๋ณ์์ ๋ง์ฐฌ๊ฐ์ง๋ก, CUDA_VISIBLE_DEVICES๋ฅผ ์ปค๋งจ๋ ๋ผ์ธ์ ์ถ๊ฐํ๋ ๋์ exportํ์ฌ ์ค์ ํ ์๋ ์์ต๋๋ค. ๊ทธ๋ฌ๋ ์ด ๋ฐฉ์์ ํ๊ฒฝ ๋ณ์๊ฐ ์ด๋ป๊ฒ ์ค์ ๋์๋์ง๋ฅผ ์์ด๋ฒ๋ฆด ๊ฒฝ์ฐ, ์๋ชป๋ GPU๋ฅผ ์ฌ์ฉํ ์ํ์ด ์๊ธฐ ๋๋ฌธ์ ๊ถ์ฅํ์ง ์์ต๋๋ค. ํน์ ํ์ต ์คํ์ ๋ํด ๋์ผํ ์ปค๋งจ๋ ๋ผ์ธ์์ ํ๊ฒฝ ๋ณ์๋ฅผ ์ค์ ํ๋ ๊ฒ์ด ์ผ๋ฐ์ ์ธ ๋ฐฉ๋ฒ์ ๋๋ค.
CUDA_DEVICE_ORDER๋ GPU์ ์์๋ฅผ ์ ์ดํ๋ ๋ฐ ์ฌ์ฉํ ์ ์๋ ๋์ฒด ํ๊ฒฝ ๋ณ์์
๋๋ค. ์ด ๋ณ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋ค์๊ณผ ๊ฐ์ ๋ฐฉ์์ผ๋ก GPU ์์๋ฅผ ์ง์ ํ ์ ์์ต๋๋ค:
- NVIDIA ๋ฐ AMD GPU์ PCIe ๋ฒ์ค ID๋ ๊ฐ๊ฐ nvidia-smi์ rocm-smi์ ์์์ ์ผ์นํฉ๋๋ค.
export CUDA_DEVICE_ORDER=PCI_BUS_ID
- GPU ์ฐ์ฐ ๋ฅ๋ ฅ
export CUDA_DEVICE_ORDER=FASTEST_FIRST
The CUDA_DEVICE_ORDER is especially useful if your training setup consists of an older and newer GPU, where the older GPU appears first, but you cannot physically swap the cards to make the newer GPU appear first. In this case, set CUDA_DEVICE_ORDER=FASTEST_FIRST to always use the newer and faster GPU first (nvidia-smi or rocm-smi still reports the GPUs in their PCIe order). Or you could also set export CUDA_VISIBLE_DEVICES=1,0.
CUDA_DEVICE_ORDER๋ ๊ตฌํ GPU์ ์ ํ GPU๊ฐ ํผํฉ๋ ํ๊ฒฝ์์ ํนํ ์ ์ฉํฉ๋๋ค. ์๋ฅผ ๋ค์ด, ๊ตฌํ GPU๊ฐ ๋จผ์ ํ์๋์ง๋ง ๋ฌผ๋ฆฌ์ ์ผ๋ก ๊ต์ฒดํ ์ ์๋ ๊ฒฝ์ฐ, CUDA_DEVICE_ORDER=FASTEST_FIRST๋ฅผ ์ค์ ํ๋ฉด ํญ์ ์ ํ ๋ฐ ๋ ๋น ๋ฅธ GPU๋ฅผ ์ฐ์ ์ ์ผ๋ก ์ฌ์ฉ(nvidia-smi ๋๋ rocm-smi๋ PCIe ์์๋๋ก GPU๋ฅผ ํ์ํจ)ํ ์ ์์ต๋๋ค. ๋๋, export CUDA_VISIBLE_DEVICES=1,0์ ์ค์ ํ์ฌ GPU ์ฌ์ฉ ์์๋ฅผ ์ง์ ์ง์ ํ ์๋ ์์ต๋๋ค.