-
Notifications
You must be signed in to change notification settings - Fork 31k
[i18n-KO] Translated accelerate.mdx to Korean
#22830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| <!--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. | ||
| --> | ||
|
|
||
| # 🤗 Accelerate를 활용한 분산 학습[[distributed-training-with-accelerate]] | ||
|
|
||
| 모델이 커지면서 병렬 처리는 제한된 하드웨어에서 더 큰 모델을 훈련하고 훈련 속도를 몇 배로 가속화하기 위한 전략으로 등장했습니다. Hugging Face에서는 사용자가 하나의 머신에 여러 개의 GPU를 사용하든 여러 머신에 여러 개의 GPU를 사용하든 모든 유형의 분산 설정에서 🤗 Transformers 모델을 쉽게 훈련할 수 있도록 돕기 위해 [🤗 Accelerate](https://huggingface.co/docs/accelerate) 라이브러리를 만들었습니다. 이 튜토리얼에서는 분산 환경에서 훈련할 수 있도록 기본 PyTorch 훈련 루프를 커스터마이즈하는 방법을 알아봅시다. | ||
|
|
||
| ## 설정[[setup]] | ||
|
|
||
| 🤗 Accelerate 설치 시작하기: | ||
|
|
||
| ```bash | ||
| pip install accelerate | ||
| ``` | ||
|
|
||
| 그 다음, [`~accelerate.Accelerator`] 객체를 불러오고 생성합니다. [`~accelerate.Accelerator`]는 자동으로 분산 설정 유형을 감지하고 훈련에 필요한 모든 구성 요소를 초기화합니다. 장치에 모델을 명시적으로 배치할 필요는 없습니다. | ||
|
|
||
| ```py | ||
| >>> from accelerate import Accelerator | ||
|
|
||
| >>> accelerator = Accelerator() | ||
| ``` | ||
|
|
||
| ## 가속화를 위한 준비[[prepare-to-accelerate]] | ||
|
|
||
| 다음 단계는 관련된 모든 훈련 객체를 [`~accelerate.Accelerator.prepare`] 메소드에 전달하는 것입니다. 여기에는 훈련 및 평가 데이터로더, 모델 및 옵티마이저가 포함됩니다: | ||
|
|
||
| ```py | ||
| >>> train_dataloader, eval_dataloader, model, optimizer = accelerator.prepare( | ||
| ... train_dataloader, eval_dataloader, model, optimizer | ||
| ... ) | ||
| ``` | ||
|
|
||
| ## 백워드(Backward)[[backward]] | ||
|
|
||
| 마지막으로 훈련 루프의 일반적인 `loss.backward()`를 🤗 Accelerate의 [`~accelerate.Accelerator.backward`] 메소드로 대체하기만 하면 됩니다: | ||
|
|
||
| ```py | ||
| >>> for epoch in range(num_epochs): | ||
| ... for batch in train_dataloader: | ||
| ... outputs = model(**batch) | ||
| ... loss = outputs.loss | ||
| ... accelerator.backward(loss) | ||
|
|
||
| ... optimizer.step() | ||
| ... lr_scheduler.step() | ||
| ... optimizer.zero_grad() | ||
| ... progress_bar.update(1) | ||
| ``` | ||
|
|
||
| 다음 코드에서 볼 수 있듯이, 훈련 루프에 코드 네 줄만 추가하면 분산 학습을 활성화할 수 있습니다! | ||
|
|
||
| ```diff | ||
| + from accelerate import Accelerator | ||
| from transformers import AdamW, AutoModelForSequenceClassification, get_scheduler | ||
|
|
||
| + accelerator = Accelerator() | ||
|
|
||
| model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=2) | ||
| optimizer = AdamW(model.parameters(), lr=3e-5) | ||
|
|
||
| - device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu") | ||
| - model.to(device) | ||
|
|
||
| + train_dataloader, eval_dataloader, model, optimizer = accelerator.prepare( | ||
| + train_dataloader, eval_dataloader, model, optimizer | ||
| + ) | ||
|
|
||
| num_epochs = 3 | ||
| num_training_steps = num_epochs * len(train_dataloader) | ||
| lr_scheduler = get_scheduler( | ||
| "linear", | ||
| optimizer=optimizer, | ||
| num_warmup_steps=0, | ||
| num_training_steps=num_training_steps | ||
| ) | ||
|
|
||
| progress_bar = tqdm(range(num_training_steps)) | ||
|
|
||
| model.train() | ||
| for epoch in range(num_epochs): | ||
| for batch in train_dataloader: | ||
| - batch = {k: v.to(device) for k, v in batch.items()} | ||
| outputs = model(**batch) | ||
| loss = outputs.loss | ||
| - loss.backward() | ||
| + accelerator.backward(loss) | ||
|
|
||
| optimizer.step() | ||
| lr_scheduler.step() | ||
| optimizer.zero_grad() | ||
| progress_bar.update(1) | ||
| ``` | ||
|
|
||
| ## 학습[[train]] | ||
|
|
||
| 관련 코드를 추가한 후에는 스크립트나 Colaboratory와 같은 노트북에서 훈련을 시작하세요. | ||
|
|
||
| ### 스크립트로 학습하기[[train-with-a-script]] | ||
|
|
||
| 스크립트에서 훈련을 실행하는 경우, 다음 명령을 실행하여 구성 파일을 생성하고 저장합니다: | ||
|
|
||
| ```bash | ||
| accelerate config | ||
| ``` | ||
|
|
||
| Then launch your training with: | ||
|
|
||
| ```bash | ||
| accelerate launch train.py | ||
| ``` | ||
|
|
||
| ### 노트북으로 학습하기[[train-with-a-notebook]] | ||
|
|
||
| Collaboratory의 TPU를 사용하려는 경우, 노트북에서도 🤗 Accelerate를 실행할 수 있습니다. 훈련을 담당하는 모든 코드를 함수로 감싸서 [`~accelerate.notebook_launcher`]에 전달하세요: | ||
|
|
||
| ```py | ||
| >>> from accelerate import notebook_launcher | ||
|
|
||
| >>> notebook_launcher(training_function) | ||
| ``` | ||
|
|
||
| 🤗 Accelerate 및 다양한 기능에 대한 자세한 내용은 [documentation](https://huggingface.co/docs/accelerate)를 참조하세요. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.