Skip to content

Commit 45d5cfa

Browse files
hyeonseo2gabrielwithappysim-so
authored andcommitted
[i18n-KO] Translated accelerate.mdx to Korean (huggingface#22830)
* docs: ko: init: accelerate.mdx * docs: ko: translated: accelerate.mdx * docs: ko: revised: natural expression accelerate.mdx Co-Authored-By: Gabriel Yang <gabrielwithhappy@gmail.com> * docs: ko: revised: natural expression2 accelerate.mdx Co-authored-by: Sohyun Sim <96299403+sim-so@users.noreply.github.com> --------- Co-authored-by: Gabriel Yang <gabrielwithhappy@gmail.com> Co-authored-by: Sohyun Sim <96299403+sim-so@users.noreply.github.com>
1 parent be95305 commit 45d5cfa

File tree

2 files changed

+134
-2
lines changed

2 files changed

+134
-2
lines changed

docs/source/ko/_toctree.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
title: 전처리
1818
- local: training
1919
title: 사전 학습된 모델 미세 조정하기
20-
- local: in_translation
21-
title: (번역중) Distributed training with 🤗 Accelerate
20+
- local: accelerate
21+
title: 🤗 Accelerate를 활용한 분산 학습
2222
- local: in_translation
2323
title: (번역중) Share a model
2424
title: (번역중) 튜토리얼

docs/source/ko/accelerate.mdx

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License.
11+
-->
12+
13+
# 🤗 Accelerate를 활용한 분산 학습[[distributed-training-with-accelerate]]
14+
15+
모델이 커지면서 병렬 처리는 제한된 하드웨어에서 모델을 훈련하고 훈련 속도를 배로 가속화하기 위한 전략으로 등장했습니다. Hugging Face에서는 사용자가 하나의 머신에 여러 개의 GPU를 사용하든 여러 머신에 여러 개의 GPU를 사용하든 모든 유형의 분산 설정에서 🤗 Transformers 모델을 쉽게 훈련할 있도록 돕기 위해 [🤗 Accelerate](https://huggingface.co/docs/accelerate) 라이브러리를 만들었습니다. 튜토리얼에서는 분산 환경에서 훈련할 있도록 기본 PyTorch 훈련 루프를 커스터마이즈하는 방법을 알아봅시다.
16+
17+
## 설정[[setup]]
18+
19+
🤗 Accelerate 설치 시작하기:
20+
21+
```bash
22+
pip install accelerate
23+
```
24+
25+
다음, [`~accelerate.Accelerator`] 객체를 불러오고 생성합니다. [`~accelerate.Accelerator`]는 자동으로 분산 설정 유형을 감지하고 훈련에 필요한 모든 구성 요소를 초기화합니다. 장치에 모델을 명시적으로 배치할 필요는 없습니다.
26+
27+
```py
28+
>>> from accelerate import Accelerator
29+
30+
>>> accelerator = Accelerator()
31+
```
32+
33+
## 가속화를 위한 준비[[prepare-to-accelerate]]
34+
35+
다음 단계는 관련된 모든 훈련 객체를 [`~accelerate.Accelerator.prepare`] 메소드에 전달하는 것입니다. 여기에는 훈련 및 평가 데이터로더, 모델 및 옵티마이저가 포함됩니다:
36+
37+
```py
38+
>>> train_dataloader, eval_dataloader, model, optimizer = accelerator.prepare(
39+
... train_dataloader, eval_dataloader, model, optimizer
40+
... )
41+
```
42+
43+
## 백워드(Backward)[[backward]]
44+
45+
마지막으로 훈련 루프의 일반적인 `loss.backward()`를 🤗 Accelerate의 [`~accelerate.Accelerator.backward`] 메소드로 대체하기만 하면 됩니다:
46+
47+
```py
48+
>>> for epoch in range(num_epochs):
49+
... for batch in train_dataloader:
50+
... outputs = model(**batch)
51+
... loss = outputs.loss
52+
... accelerator.backward(loss)
53+
54+
... optimizer.step()
55+
... lr_scheduler.step()
56+
... optimizer.zero_grad()
57+
... progress_bar.update(1)
58+
```
59+
60+
다음 코드에서 볼 수 있듯이, 훈련 루프에 코드 네 줄만 추가하면 분산 학습을 활성화할 수 있습니다!
61+
62+
```diff
63+
+ from accelerate import Accelerator
64+
from transformers import AdamW, AutoModelForSequenceClassification, get_scheduler
65+
66+
+ accelerator = Accelerator()
67+
68+
model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=2)
69+
optimizer = AdamW(model.parameters(), lr=3e-5)
70+
71+
- device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
72+
- model.to(device)
73+
74+
+ train_dataloader, eval_dataloader, model, optimizer = accelerator.prepare(
75+
+ train_dataloader, eval_dataloader, model, optimizer
76+
+ )
77+
78+
num_epochs = 3
79+
num_training_steps = num_epochs * len(train_dataloader)
80+
lr_scheduler = get_scheduler(
81+
"linear",
82+
optimizer=optimizer,
83+
num_warmup_steps=0,
84+
num_training_steps=num_training_steps
85+
)
86+
87+
progress_bar = tqdm(range(num_training_steps))
88+
89+
model.train()
90+
for epoch in range(num_epochs):
91+
for batch in train_dataloader:
92+
- batch = {k: v.to(device) for k, v in batch.items()}
93+
outputs = model(**batch)
94+
loss = outputs.loss
95+
- loss.backward()
96+
+ accelerator.backward(loss)
97+
98+
optimizer.step()
99+
lr_scheduler.step()
100+
optimizer.zero_grad()
101+
progress_bar.update(1)
102+
```
103+
104+
## 학습[[train]]
105+
106+
관련 코드를 추가한 후에는 스크립트나 Colaboratory와 같은 노트북에서 훈련을 시작하세요.
107+
108+
### 스크립트로 학습하기[[train-with-a-script]]
109+
110+
스크립트에서 훈련을 실행하는 경우, 다음 명령을 실행하여 구성 파일을 생성하고 저장합니다:
111+
112+
```bash
113+
accelerate config
114+
```
115+
116+
Then launch your training with:
117+
118+
```bash
119+
accelerate launch train.py
120+
```
121+
122+
### 노트북으로 학습하기[[train-with-a-notebook]]
123+
124+
Collaboratory의 TPU를 사용하려는 경우, 노트북에서도 🤗 Accelerate를 실행할 수 있습니다. 훈련을 담당하는 모든 코드를 함수로 감싸서 [`~accelerate.notebook_launcher`]에 전달하세요:
125+
126+
```py
127+
>>> from accelerate import notebook_launcher
128+
129+
>>> notebook_launcher(training_function)
130+
```
131+
132+
🤗 Accelerate 및 다양한 기능에 대한 자세한 내용은 [documentation](https://huggingface.co/docs/accelerate)를 참조하세요.

0 commit comments

Comments
 (0)