A newer version of the Gradio SDK is available:
5.34.2
๊ฐ์๊ธฐ ์ ํ [[accelerator-selection]]
๋ถ์ฐ ํ๋ จ ์ค์ ์ฌ์ฉํ ๊ฐ์๊ธฐ(CUDA, XPU, MPS, HPU ๋ฑ)์ ์์ ์์๋ฅผ ์ง์ ํ ์ ์์ต๋๋ค. ์ด๋ ์๋ก ๋ค๋ฅธ ์ฐ์ฐ ์ฑ๋ฅ์ ๊ฐ์ง ๊ฐ์๊ธฐ๊ฐ ์๊ณ ๋ ๋น ๋ฅธ ๊ฐ์๊ธฐ๋ฅผ ๋จผ์ ์ฌ์ฉํ๊ณ ์ถ์ ๋ ์ ์ฉํ ์ ์์ต๋๋ค. ๋๋ ์ฌ์ฉ ๊ฐ๋ฅํ ๊ฐ์๊ธฐ ์ค ์ผ๋ถ๋ง ์ฌ์ฉํ ์๋ ์์ต๋๋ค. ์ ํ ๊ณผ์ ์ DistributedDataParallel๊ณผ DataParallel ๋ชจ๋์์ ์๋ํฉ๋๋ค. Accelerate๋ DeepSpeed integration์ด ํ์ํ์ง ์์ต๋๋ค.
์ด ๊ฐ์ด๋๋ ์ฌ์ฉํ ๊ฐ์๊ธฐ์ ์์ ์ฌ์ฉ ์์๋ฅผ ์ ํํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค.
๊ฐ์๊ธฐ ์ [[number-of-accelerators]]
์๋ฅผ ๋ค์ด, 4๊ฐ์ ๊ฐ์๊ธฐ๊ฐ ์๊ณ ์ฒ์ 2๊ฐ๋ง ์ฌ์ฉํ๊ณ ์ถ๋ค๋ฉด ์๋ ๋ช ๋ น์ ์คํํ์ธ์.
--nproc_per_node
๋ฅผ ์ฌ์ฉํ์ฌ ์ฌ์ฉํ ๊ฐ์๊ธฐ ์๋ฅผ ์ ํํ์ธ์.
torchrun --nproc_per_node=2 trainer-program.py ...
--num_processes
๋ฅผ ์ฌ์ฉํ์ฌ ์ฌ์ฉํ ๊ฐ์๊ธฐ ์๋ฅผ ์ ํํ์ธ์.
accelerate launch --num_processes 2 trainer-program.py ...
--num_gpus
๋ฅผ ์ฌ์ฉํ์ฌ ์ฌ์ฉํ GPU ์๋ฅผ ์ ํํ์ธ์.
deepspeed --num_gpus 2 trainer-program.py ...
๊ฐ์๊ธฐ ์์ [[order-of-accelerators]]
์ฌ์ฉํ ํน์ ๊ฐ์๊ธฐ์ ๊ทธ ์์๋ฅผ ์ ํํ๋ ค๋ฉด ํ๋์จ์ด์ ์ ํฉํ ํ๊ฒฝ ๋ณ์๋ฅผ ์ฌ์ฉํ์ธ์. ์ด๋ ๊ฐ ์คํ๋ง๋ค ๋ช
๋ น์ค์์ ์ค์ ๋๋ ๊ฒฝ์ฐ๊ฐ ๋ง์ง๋ง, ~/.bashrc
๋ ๋ค๋ฅธ ์์ ์ค์ ํ์ผ์ ์ถ๊ฐํ ์๋ ์์ต๋๋ค.
์๋ฅผ ๋ค์ด, 4๊ฐ์ ๊ฐ์๊ธฐ(0, 1, 2, 3)๊ฐ ์๊ณ ๊ฐ์๊ธฐ 0๊ณผ 2๋ง ์คํํ๊ณ ์ถ๋ค๋ฉด:
CUDA_VISIBLE_DEVICES=0,2 torchrun trainer-program.py ...
GPU 0๊ณผ 2๋ง PyTorch์ "๋ณด์ด๋ฉฐ" ๊ฐ๊ฐ cuda:0
๊ณผ cuda:1
๋ก ๋งคํ๋ฉ๋๋ค.
์์๋ฅผ ๋ฐ๊พธ๋ ค๋ฉด (GPU 2๋ฅผ cuda:0
์ผ๋ก, GPU 0์ cuda:1
๋ก ์ฌ์ฉ):
CUDA_VISIBLE_DEVICES=2,0 torchrun trainer-program.py ...
GPU ์์ด ์คํํ๋ ค๋ฉด:
CUDA_VISIBLE_DEVICES= python trainer-program.py ...
CUDA_DEVICE_ORDER
๋ฅผ ์ฌ์ฉํ์ฌ CUDA ์ฅ์น ์์๋ฅผ ์ ์ดํ ์๋ ์์ต๋๋ค:
PCIe ๋ฒ์ค ID ์์๋ก ์ ๋ ฌ (
nvidia-smi
์ ์ผ์น):
$hf_i18n_placeholder21export CUDA_DEVICE_ORDER=PCI_BUS_ID ```
์ฐ์ฐ ์ฑ๋ฅ ์์๋ก ์ ๋ ฌ (๊ฐ์ฅ ๋น ๋ฅธ ๊ฒ๋ถํฐ):
export CUDA_DEVICE_ORDER=FASTEST_FIRST
ZE_AFFINITY_MASK=0,2 torchrun trainer-program.py ...
XPU 0๊ณผ 2๋ง PyTorch์ "๋ณด์ด๋ฉฐ" ๊ฐ๊ฐ xpu:0
๊ณผ xpu:1
๋ก ๋งคํ๋ฉ๋๋ค.
์์๋ฅผ ๋ฐ๊พธ๋ ค๋ฉด (XPU 2๋ฅผ xpu:0
์ผ๋ก, XPU 0์ xpu:1
๋ก ์ฌ์ฉ):
ZE_AFFINITY_MASK=2,0 torchrun trainer-program.py ...
๋ค์์ผ๋ก Intel XPU ์์๋ฅผ ์ ์ดํ ์๋ ์์ต๋๋ค:
export ZE_ENABLE_PCI_ID_DEVICE_ORDER=1
Intel XPU์ ์ฅ์น ์ด๊ฑฐ ๋ฐ ์ ๋ ฌ์ ๋ํ ์์ธํ ์ ๋ณด๋ Level Zero ๋ฌธ์๋ฅผ ์ฐธ์กฐํ์ธ์.
ํ๊ฒฝ ๋ณ์๋ ๋ช ๋ น์ค์ ์ถ๊ฐํ๋ ๋์ exportํ ์ ์์ต๋๋ค. ํ๊ฒฝ ๋ณ์๊ฐ ์ด๋ป๊ฒ ์ค์ ๋์๋์ง ์์ด๋ฒ๋ฆฌ๊ณ ๊ฒฐ๊ตญ ์๋ชป๋ ๊ฐ์๊ธฐ๋ฅผ ์ฌ์ฉํ๊ฒ ๋ ์ ์์ด ํผ๋์ค๋ฌ์ธ ์ ์์ผ๋ฏ๋ก ๊ถ์ฅํ์ง ์์ต๋๋ค. ๋์ , ๋์ผํ ๋ช ๋ น์ค์์ ํน์ ํ๋ จ ์คํ์ ๋ํด ํ๊ฒฝ ๋ณ์๋ฅผ ์ค์ ํ๋ ๊ฒ์ด ์ผ๋ฐ์ ์ธ ๊ด๋ก์ ๋๋ค. ```