Skip to content
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

๐ŸŒ [i18n-KO] Translated model_doc/llama3.md to Korean #33635

Merged
merged 9 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/source/ko/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@
title: LLaMA
- local: model_doc/llama2
title: LLaMA2
- local: model_doc/llama3
title: LLaMA3
- local: in_translation
title: (๋ฒˆ์—ญ์ค‘) Longformer
- local: in_translation
Expand Down
80 changes: 80 additions & 0 deletions docs/source/ko/model_doc/llama3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<!--Copyright 2024 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.

-->

# Llama3[[llama3]]

```py3
import transformers
import torch

model_id = "meta-llama/Meta-Llama-3-8B"

pipeline = transformers.pipeline("text-generation", model=model_id, model_kwargs={"torch_dtype": torch.bfloat16}, device_map="auto")
pipeline("Hey how are you doing today?")
```

## ๊ฐœ์š”[[overview]]

๋ผ๋งˆ3 ๋ชจ๋ธ์€ Meta AI ํŒ€์ด ์ œ์•ˆํ•œ [๋ฉ”ํƒ€ ๋ผ๋งˆ3 ์†Œ๊ฐœ: ํ˜„์žฌ๊นŒ์ง€ ๊ฐ€์žฅ ์œ ๋Šฅํ•œ ๊ณต๊ฐœ ๊ฐ€๋Šฅ LLM](https://ai.meta.com/blog/meta-llama-3/)์—์„œ ์†Œ๊ฐœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

ํ•ด๋‹น ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ์˜ ์ดˆ๋ก์ž…๋‹ˆ๋‹ค:

*์˜ค๋Š˜, ๊ด‘๋ฒ”์œ„ํ•œ ์‚ฌ์šฉ์„ ์œ„ํ•ด ์ด์šฉ ๊ฐ€๋Šฅํ•œ ๋ผ๋งˆ์˜ ์ฐจ์„ธ๋Œ€ ๋ชจ๋ธ์ธ ๋ฉ”ํƒ€ ๋ผ๋งˆ3์˜ ์ฒซ ๋‘ ๋ชจ๋ธ์„ ๊ณต์œ ํ•˜๊ฒŒ ๋˜์–ด ๊ธฐ์ฉ๋‹ˆ๋‹ค. ์ด๋ฒˆ ์ถœ์‹œ๋Š” 8B์™€ 70B ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๊ฐ€์ง„ ์‚ฌ์ „ ํ›ˆ๋ จ ๋ฐ ์ง€์‹œ ๋ฏธ์„ธ ์กฐ์ •๋œ ์–ธ์–ด ๋ชจ๋ธ์„ ํŠน์ง•์œผ๋กœ ํ•˜๋ฉฐ, ๊ด‘๋ฒ”์œ„ํ•œ ์‚ฌ์šฉ ์‚ฌ๋ก€๋ฅผ ์ง€์›ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ผ๋งˆ์˜ ์ด ์ฐจ์„ธ๋Œ€ ๋ชจ๋ธ์€ ๋‹ค์–‘ํ•œ ์‚ฐ์—… ๋ฒค์น˜๋งˆํฌ์—์„œ ์ตœ์ฒจ๋‹จ์˜ ์„ฑ๋Šฅ์„ ๋ณด์—ฌ์ฃผ๋ฉฐ, ๊ฐœ์„ ๋œ ์ถ”๋ก  ๋Šฅ๋ ฅ์„ ํฌํ•จํ•œ ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๋Š” ์ด๊ฒƒ๋“ค์ด ๋‹จ์—ฐ์ฝ” ํ•ด๋‹น ํด๋ž˜์Šค์—์„œ ์ตœ๊ณ ์˜ ์˜คํ”ˆ ์†Œ์Šค ๋ชจ๋ธ์ด๋ผ๊ณ  ๋ฏฟ์Šต๋‹ˆ๋‹ค. ์˜ค๋žœ ๊ฐœ๋ฐฉ์  ์ ‘๊ทผ ๋ฐฉ์‹์„ ์ง€์ง€ํ•˜๋ฉฐ, ์šฐ๋ฆฌ๋Š” ๋ผ๋งˆ3๋ฅผ ์ปค๋ฎค๋‹ˆํ‹ฐ ๊ธฐ์—ฌ์ž๋“ค์—๊ฒŒ ๋งก๊ธฐ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๊ฐœ๋ฐœ์ž ๋„๊ตฌ, ํ‰๊ฐ€, ์ถ”๋ก  ์ตœ์ ํ™” ๋“ฑ์— ์ด๋ฅด๊ธฐ๊นŒ์ง€ AI ์Šคํƒ ์ „๋ฐ˜์— ๊ฑธ์นœ ๋‹ค์Œ ํ˜์‹ ์˜ ๋ฌผ๊ฒฐ์„ ์ด‰๋ฐœํ•˜๊ธธ ํฌ๋งํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ๋ถ„์ด ๋ฌด์—‡์„ ๋งŒ๋“ค์ง€ ๊ธฐ๋Œ€ํ•˜๋ฉฐ ์—ฌ๋Ÿฌ๋ถ„์˜ ํ”ผ๋“œ๋ฐฑ์„ ๊ณ ๋Œ€ํ•ฉ๋‹ˆ๋‹ค.*

๋ผ๋งˆ3 ๋ชจ๋ธ์˜ ๋ชจ๋“  ์ฒดํฌํฌ์ธํŠธ๋Š” [์ด๊ณณ](https://huggingface.co/models?search=llama3)์—์„œ ํ™•์ธํ•˜์„ธ์š”.
์›๋ณธ ์ฝ”๋“œ๋Š” [์ด๊ณณ](https://github.com/meta-llama/llama3)์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

## ์‚ฌ์šฉ ํŒ[[usage-tips]]

<Tip warning={true}>

`๋ผ๋งˆ3` ๋ชจ๋ธ๋“ค์€ `bfloat16`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ›ˆ๋ จ๋˜์—ˆ์ง€๋งŒ, ์›๋ž˜์˜ ์ถ”๋ก ์€ `float16`์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Hub์— ์—…๋กœ๋“œ๋œ ์ฒดํฌํฌ์ธํŠธ๋“ค์€ `torch_dtype = 'float16'`์„ ์‚ฌ์šฉํ•˜๋Š”๋ฐ, ์ด๋Š” `AutoModel` API๊ฐ€ ์ฒดํฌํฌ์ธํŠธ๋ฅผ `torch.float32`์—์„œ `torch.float16`์œผ๋กœ ๋ณ€ํ™˜ํ•˜๋Š”๋ฐ ์ด์šฉ๋ฉ๋‹ˆ๋‹ค.

`model = AutoModelForCausalLM.from_pretrained("path", torch_dtype = "auto")`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋ธ์„ ์ดˆ๊ธฐํ™”ํ•  ๋•Œ, ์˜จ๋ผ์ธ ๊ฐ€์ค‘์น˜์˜ `dtype`๋Š” `torch_dtype="auto"`๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ํ•œ ๋Œ€๋ถ€๋ถ„ ๋ฌด๊ด€ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ์ด์œ ๋Š” ๋ชจ๋ธ์ด ๋จผ์ € ๋‹ค์šด๋กœ๋“œ๋˜๊ณ (์˜จ๋ผ์ธ ์ฒดํฌํฌ์ธํŠธ์˜ `dtype`๋ฅผ ์‚ฌ์šฉ), ๊ทธ ๋‹ค์Œ `torch`์˜ `dtype`์œผ๋กœ ๋ณ€ํ™˜๋˜์–ด(`torch.float32`๊ฐ€ ๋จ), ๋งˆ์ง€๋ง‰์œผ๋กœ config์— `torch_dtype`์ด ์ œ๊ณต๋œ ๊ฒฝ์šฐ ๊ฐ€์ค‘์น˜๊ฐ€ ์‚ฌ์šฉ๋˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

`float16`์œผ๋กœ ๋ชจ๋ธ์„ ํ›ˆ๋ จํ•˜๋Š” ๊ฒƒ์€ ๊ถŒ์žฅ๋˜์ง€ ์•Š์œผ๋ฉฐ `nan`์„ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์•Œ๋ ค์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋ชจ๋“  ๋ชจ๋ธ์€ `bfloat16`์œผ๋กœ ํ›ˆ๋ จ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

</Tip>

ํŒ:

- ๋ผ๋งˆ3 ๋ชจ๋ธ์„ ์œ„ํ•œ ๊ฐ€์ค‘์น˜๋Š” [์ด ํผ](https://ai.meta.com/resources/models-and-libraries/llama-downloads/)์„ ์ฑ„์šฐ๋ฉด์„œ ์–ป์–ด์ ธ์•ผ ํ•ฉ๋‹ˆ๋‹ค.
- ์•„ํ‚คํ…์ฒ˜๋Š” ๋ผ๋งˆ2์™€ ์ •ํ™•ํžˆ ๊ฐ™์Šต๋‹ˆ๋‹ค.
- ํ† ํฌ๋‚˜์ด์ €๋Š” [tiktoken](https://github.com/openai/tiktoken) (sentencepiece ๊ตฌํ˜„์— ๊ธฐ๋ฐ˜ํ•œ ๋ผ๋งˆ2 ์™€๋Š” ๋‹ค๋ฅด๊ฒŒ)์— ๊ธฐ๋ฐ˜ํ•œ BPE ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค. tiktoken ๊ธฐ๋ฐ˜ ํ† ํฌ๋‚˜์ด์ €๊ฐ€ sebtencepiece ๊ธฐ๋ฐ˜ ๋ฐฉ์‹๊ณผ ๋‹ค๋ฅธ์ ์€ ์ž…๋ ฅ ํ† ํฐ์ด vocab์— ์ด๋ฏธ ์กด์žฌํ•  ๋•Œ BPE ๋ณ‘ํ•ฉ ๋ฃฐ์„ ๋ฌด์‹œํ•˜๊ณ  ์‹ฑ๊ธ€ ํ† ํฐ์œผ๋กœ ํ† ํฌ๋‚˜์ด์ง•ํ•œ๋‹ค๋Š” ์ ์—์„œ ๊ฐ€์žฅ ํฐ ์ฐจ์ด๋ฅผ ๋ณด์ž…๋‹ˆ๋‹ค. ์ž์„ธํžˆ ๋งํ•˜๋ฉด `"hugging"`์ด vocab์— ์กด์žฌํ•˜๊ณ  ๊ธฐ์กด์— ๋ณ‘ํ•ฉ์ด ์กด์žฌํ•˜์ง€ ์•Š์œผ๋ฉด, `["hug","ging"]` ์ฒ˜๋Ÿผ ๋‘ ํ† ํฐ์œผ๋กœ ๋” ์ž‘์€ ๋‹จ์œ„์˜ ๋‹จ์–ด๋ฅผ ๊ฐ€์ง€๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, ํ•˜๋‚˜์˜ ํ† ํฐ๋งŒ์„ ์ž๋™์œผ๋กœ ๋ฆฌํ„ดํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.
- ๊ธฐ๋ณธ ๋ชจ๋ธ์€ ํŒจ๋”ฉ ํ† ํฐ์ด ์—†๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•˜๋Š” `pad_id = -1`์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๊ฐ™์€ ๋กœ์ง์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์œผ๋‹ˆ `tokenizer.add_special_tokens({"pad_token":"<pad>"})`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ† ํฐ์„ ์ถ”๊ฐ€ํ•˜๊ณ  ์ž„๋ฒ ๋”ฉ ํฌ๊ธฐ๋„ ํ™•์‹คํžˆ ์กฐ์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. `model.config.pad_token_id`๋„ ์„ค์ •์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๋ชจ๋ธ์˜ `embed_tokens` ๋ ˆ์ด์–ด๋Š” `self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.config.padding_idx)`๋กœ ์ดˆ๊ธฐํ™”๋˜๋ฉฐ, ํŒจ๋”ฉ ํ† ํฐ์„ ์ธ์ฝ”๋”ฉํ•˜๋Š” ๊ฒƒ์ด 0(zero)๋ฅผ ์ถœ๋ ฅํ•˜๊ฒŒ ํ•  ๊ฒƒ์ธ์ง€ ๊ทธ๋ž˜์„œ ์ดˆ๊ธฐํ™”๊ฐ€ ์ถ”์ฒœ๋ ๋•Œ ์ด๋ฅผ ํ†ตํ™”์‹œํ‚ฌ ๊ฒƒ์ธ์ง€๋ฅผ ์ •ํ•˜๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.
- ์›๋ณธ ์ฒดํฌํฌ์ธํŠธ๋Š” ์ด [๋ณ€ํ™˜ ์Šคํฌ๋ฆฝํŠธ](https://github.com/huggingface/transformers/blob/main/src/transformers/models/llama/convert_llama_weights_to_hf.py)๋ฅผ ์ด์šฉํ•ด์„œ ๋ณ€ํ™˜ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์Šคํฌ๋ฆฝํŠธ๋Š” ๋‹ค์Œ ๋ช…๋ น์–ด๋กœ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

```bash
python src/transformers/models/llama/convert_llama_weights_to_hf.py \
--input_dir /path/to/downloaded/llama/weights --model_size 7B --output_dir /output/path --llama_version 3
```

- ๋ณ€ํ™˜ ํ›„, ๋ชจ๋ธ๊ณผ ํ† ํฌ๋‚˜์ด์ €๋Š” ๋‹ค์Œ์„ ํ†ตํ•ด ๋กœ๋“œ๋œ๋‹ค.

```python
from transformers import AutoModelForCausalLM, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("/output/path")
model = AutoModelForCausalLM.from_pretrained("/output/path")
```

์ด ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰์‹œํ‚ค๋ ค๋ฉด ๋ชจ๋ธ ์ „์ฒด๋ฅผ float16 ์ •๋ฐ€๋„๋กœ ํ˜ธ์ŠคํŒ…ํ•  ์ˆ˜ ์žˆ๋Š” ์ถฉ๋ถ„ํ•œ ๋ฉ”์ธ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ํ•„์š”ํ•˜๋‹ค๋Š” ์ ์„ ์œ ์˜ํ•˜์„ธ์š”. ๊ฐ€์žฅ ํฐ ๋ฒ„์ „์ด ์—ฌ๋Ÿฌ ์ฒดํฌํฌ์ธํŠธ๋กœ ๋‚˜๋‰˜์–ด ์žˆ๋”๋ผ๋„, ๊ฐ ์ฒดํฌํฌ์ธํŠธ๊ฐ€ ๋ชจ๋ธ์˜ ๊ฐ€์ค‘์น˜ ์ผ๋ถ€๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฅผ ๋ชจ๋‘ RAM์— ๋กœ๋“œํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. 75B ๋ชจ๋ธ์„ ์˜ˆ๋กœ ๋“ค๋ฉด ๋Œ€๋žต 145GB์˜ RAM์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

- `attn_implementation="flash_attention_2"`๋ฅผ ํ†ตํ•ด์„œ ํ”Œ๋ž˜์‹œ ์–ดํ…์…˜2๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ, `from_pretrained` ํด๋ž˜์Šค ๋ฉ”์„œ๋“œ์— `torch_dtype`๋ฅผ ์ „๋‹ฌํ•˜์ง€ ๋ง๊ณ  ์ž๋™ ํ˜ผํ•ฉ ์ •๋ฐ€๋„(Automatic Mixed-Precision) ํ•™์Šต์„ ์‚ฌ์šฉํ•˜์„ธ์š”. `Trainer`๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ๋Š” ๋‹จ์ˆœํžˆ `fp16` ๋˜๋Š” `bf16`์„ `True`๋กœ ์„ค์ •ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ๋ฐ˜๋“œ์‹œ `torch.autocast`๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ํ”Œ๋ž˜์‹œ ์–ดํ…์…˜์€ `fp16`๊ณผ `bf16` ๋ฐ์ดํ„ฐ ์œ ํ˜•๋งŒ ์ง€์›ํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

## ์ž๋ฃŒ[[resources]]

[๋ผ๋งˆ2](./llama2) ๋ฌธ์„œ ํŽ˜์ด์ง€์—์„œ๋Š” ์ด๋ฏธ ์ˆ˜ ๋งŽ์€ ๋ฉ‹์ง€๊ณ  ์œ ์ตํ•œ ์ž๋ฃŒ๋“ค์„ ์ œ๊ณตํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๊ณณ์— ๋ผ๋งˆ3์— ๋Œ€ํ•œ ์ƒˆ๋กœ์šด ์ž๋ฃŒ๋ฅผ ๋”ํ•ด์ฃผ์‹ค ์ปจํŠธ๋ฆฌ๋ทฐํ„ฐ๋“ค์„ ์ดˆ๋Œ€ํ•ฉ๋‹ˆ๋‹ค! ๐Ÿค—
Loading