Skip to content

Commit

Permalink
๐ŸŒ [i18n-KO] Translated conversations.md to Korean (huggingface#32468)
Browse files Browse the repository at this point in the history
* docs: ko: conversations.md

* feat: hand-crafted translate docs

* fix: modify typo after Grammar Check

* Update docs/source/ko/conversations.md

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค

Co-authored-by: SeungAhSon <gongsoonyee@gmail.com>

* Update docs/source/ko/conversations.md

Co-authored-by: SeungAhSon <gongsoonyee@gmail.com>

* Update docs/source/ko/conversations.md

Co-authored-by: SeungAhSon <gongsoonyee@gmail.com>

* Update docs/source/ko/conversations.md

Co-authored-by: SeungAhSon <gongsoonyee@gmail.com>

* Update docs/source/ko/conversations.md

Co-authored-by: SeungAhSon <gongsoonyee@gmail.com>

* Update docs/source/ko/conversations.md

Co-authored-by: SeungAhSon <gongsoonyee@gmail.com>

* Update docs/source/ko/conversations.md

Co-authored-by: SeungAhSon <gongsoonyee@gmail.com>

* Update docs/source/ko/conversations.md

Co-authored-by: SeungAhSon <gongsoonyee@gmail.com>

* Update docs/source/ko/conversations.md

Co-authored-by: SeungAhSon <gongsoonyee@gmail.com>

* Update docs/source/ko/conversations.md

Co-authored-by: SeungAhSon <gongsoonyee@gmail.com>

* Update docs/source/ko/conversations.md

Co-authored-by: SeungAhSon <gongsoonyee@gmail.com>

* fix: accept suggestions about anchor and spacing

* Update docs/source/ko/conversations.md

Co-authored-by: Jihun Lim <31366038+heuristicwave@users.noreply.github.com>

* Update docs/source/ko/conversations.md

Co-authored-by: Jihun Lim <31366038+heuristicwave@users.noreply.github.com>

* Update docs/source/ko/conversations.md

Co-authored-by: Jihun Lim <31366038+heuristicwave@users.noreply.github.com>

* Update docs/source/ko/conversations.md

Co-authored-by: Jihun Lim <31366038+heuristicwave@users.noreply.github.com>

* Update docs/source/ko/conversations.md

Co-authored-by: Jihun Lim <31366038+heuristicwave@users.noreply.github.com>

* Update docs/source/ko/conversations.md

Co-authored-by: Jihun Lim <31366038+heuristicwave@users.noreply.github.com>

* Update docs/source/ko/conversations.md

Co-authored-by: Sungmin Oh <fabxoe.kor@gmail.com>

* Update docs/source/ko/conversations.md

Co-authored-by: Sungmin Oh <fabxoe.kor@gmail.com>

* Update docs/source/ko/conversations.md

Co-authored-by: Sungmin Oh <fabxoe.kor@gmail.com>

* fix: anchor 'what happened inside piepeline?' be removed question mark

* fix: translate the comments in the code block

---------

Co-authored-by: SeungAhSon <gongsoonyee@gmail.com>
Co-authored-by: Jihun Lim <31366038+heuristicwave@users.noreply.github.com>
Co-authored-by: Sungmin Oh <fabxoe.kor@gmail.com>
  • Loading branch information
4 people authored and BernardZach committed Dec 5, 2024
1 parent 38a70ac commit 924028f
Show file tree
Hide file tree
Showing 2 changed files with 308 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/source/ko/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
title: ์—์ด์ „ํŠธ
- local: llm_tutorial
title: ๋Œ€๊ทœ๋ชจ ์–ธ์–ด ๋ชจ๋ธ๋กœ ์ƒ์„ฑํ•˜๊ธฐ
- local: in_translation
title: (๋ฒˆ์—ญ์ค‘)Chatting with Transformers
- local: conversations
title: Transformers๋กœ ์ฑ„ํŒ…ํ•˜๊ธฐ
title: ํŠœํ† ๋ฆฌ์–ผ
- sections:
- isExpanded: false
Expand Down
306 changes: 306 additions & 0 deletions docs/source/ko/conversations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,306 @@
<!--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.
-->

# Transformers๋กœ ์ฑ„ํŒ…ํ•˜๊ธฐ[[chatting-with-transformers]]

์ด ๊ธ€์„ ๋ณด๊ณ  ์žˆ๋‹ค๋ฉด **์ฑ„ํŒ… ๋ชจ๋ธ**์— ๋Œ€ํ•ด ์–ด๋Š ์ •๋„ ์•Œ๊ณ  ๊ณ„์‹ค ๊ฒƒ์ž…๋‹ˆ๋‹ค.
์ฑ„ํŒ… ๋ชจ๋ธ์ด๋ž€ ๋ฉ”์„ธ์ง€๋ฅผ ์ฃผ๊ณ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ๋Œ€ํ™”ํ˜• ์ธ๊ณต์ง€๋Šฅ์ž…๋‹ˆ๋‹ค.
๋Œ€ํ‘œ์ ์œผ๋กœ ChatGPT๊ฐ€ ์žˆ๊ณ , ์ด์™€ ๋น„์Šทํ•˜๊ฑฐ๋‚˜ ๋” ๋›ฐ์–ด๋‚œ ์˜คํ”ˆ์†Œ์Šค ์ฑ„ํŒ… ๋ชจ๋ธ์ด ๋งŽ์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.
์ด๋Ÿฌํ•œ ๋ชจ๋ธ๋“ค์€ ๋ฌด๋ฃŒ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋กœ์ปฌ์—์„œ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
ํฌ๊ณ  ๋ฌด๊ฑฐ์šด ๋ชจ๋ธ์€ ๊ณ ์„ฑ๋Šฅ ํ•˜๋“œ์›จ์–ด์™€ ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ํ•„์š”ํ•˜์ง€๋งŒ,
์ €์‚ฌ์–‘ GPU ํ˜น์€ ์ผ๋ฐ˜ ๋ฐ์Šคํฌํƒ‘์ด๋‚˜ ๋…ธํŠธ๋ถ CPU์—์„œ๋„ ์ž˜ ์ž‘๋™ํ•˜๋Š” ์†Œํ˜• ๋ชจ๋ธ๋“ค๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ๊ฐ€์ด๋“œ๋Š” ์ฑ„ํŒ… ๋ชจ๋ธ์„ ์ฒ˜์Œ ์‚ฌ์šฉํ•˜๋Š” ๋ถ„๋“ค์—๊ฒŒ ์œ ์šฉํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.
์šฐ๋ฆฌ๋Š” ๊ฐ„ํŽธํ•œ ๊ณ ์ˆ˜์ค€(High-Level) "pipeline"์„ ํ†ตํ•ด ๋น ๋ฅธ ์‹œ์ž‘ ๊ฐ€์ด๋“œ๋ฅผ ์ง„ํ–‰ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.
๊ฐ€์ด๋“œ์—๋Š” ์ฑ„ํŒ… ๋ชจ๋ธ์„ ๋ฐ”๋กœ ์‹œ์ž‘ํ•  ๋•Œ ํ•„์š”ํ•œ ๋ชจ๋“  ์ •๋ณด๊ฐ€ ๋‹ด๊ฒจ ์žˆ์Šต๋‹ˆ๋‹ค.
๋น ๋ฅธ ์‹œ์ž‘ ๊ฐ€์ด๋“œ ์ดํ›„์—๋Š” ์ฑ„ํŒ… ๋ชจ๋ธ์ด ์ •ํ™•ํžˆ ๋ฌด์—‡์ธ์ง€, ์ ์ ˆํ•œ ๋ชจ๋ธ์„ ์„ ํƒํ•˜๋Š” ๋ฐฉ๋ฒ•๊ณผ,
์ฑ„ํŒ… ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ ๋‹จ๊ณ„์˜ ์ €์ˆ˜์ค€(Low-Level) ๋ถ„์„ ๋“ฑ ๋” ์ž์„ธํ•œ ์ •๋ณด๋ฅผ ๋‹ค๋ฃฐ ๊ฒƒ์ž…๋‹ˆ๋‹ค.
๋˜ํ•œ ์ฑ„ํŒ… ๋ชจ๋ธ์˜ ์„ฑ๋Šฅ๊ณผ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ์„ ์ตœ์ ํ™”ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ํŒ๋„ ์ œ๊ณตํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.


## ๋น ๋ฅธ ์‹œ์ž‘[[quickstart]]

์ž์„ธํžˆ ๋ณผ ์—ฌ์œ ๊ฐ€ ์—†๋Š” ๋ถ„๋“ค์„ ์œ„ํ•ด ๊ฐ„๋‹จํžˆ ์š”์•ฝํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค:
์ฑ„ํŒ… ๋ชจ๋ธ์€ ๋Œ€ํ™” ๋ฉ”์„ธ์ง€๋ฅผ ๊ณ„์†ํ•ด์„œ ์ƒ์„ฑํ•ด ๋‚˜๊ฐ‘๋‹ˆ๋‹ค.
์ฆ‰, ์งค๋ง‰ํ•œ ์ฑ„ํŒ… ๋ฉ”์„ธ์ง€๋ฅผ ๋ชจ๋ธ์—๊ฒŒ ์ „๋‹ฌํ•˜๋ฉด, ๋ชจ๋ธ์€ ์ด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์‘๋‹ต์„ ์ถ”๊ฐ€ํ•˜๋ฉฐ ๋Œ€ํ™”๋ฅผ ์ด์–ด ๋‚˜๊ฐ‘๋‹ˆ๋‹ค.
์ด์ œ ์‹ค์ œ๋กœ ์–ด๋–ป๊ฒŒ ์ž‘๋™ํ•˜๋Š”์ง€ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
๋จผ์ €, ์ฑ„ํŒ…์„ ๋งŒ๋“ค์–ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค:


```python
chat = [
{"role": "system", "content": "You are a sassy, wise-cracking robot as imagined by Hollywood circa 1986."},
{"role": "user", "content": "Hey, can you tell me any fun things to do in New York?"}
]
```

์ฃผ๋ชฉํ•˜์„ธ์š”, ๋Œ€ํ™”๋ฅผ ์ฒ˜์Œ ์‹œ์ž‘ํ•  ๋•Œ ์œ ์ € ๋ฉ”์„ธ์ง€ ์ด์™ธ์˜๋„, ๋ณ„๋„์˜ **์‹œ์Šคํ…œ** ๋ฉ”์„ธ์ง€๊ฐ€ ํ•„์š”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋ชจ๋“  ์ฑ„ํŒ… ๋ชจ๋ธ์ด ์‹œ์Šคํ…œ ๋ฉ”์„ธ์ง€๋ฅผ ์ง€์›ํ•˜๋Š” ๊ฒƒ์€ ์•„๋‹ˆ์ง€๋งŒ,
์ง€์›ํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” ์‹œ์Šคํ…œ ๋ฉ”์„ธ์ง€๋Š” ๋Œ€ํ™”์—์„œ ๋ชจ๋ธ์ด ์–ด๋–ป๊ฒŒ ํ–‰๋™ํ•ด์•ผ ํ•˜๋Š”์ง€๋ฅผ ์ง€์‹œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด, ์œ ์พŒํ•˜๊ฑฐ๋‚˜ ์ง„์ง€ํ•˜๊ณ ์ž ํ•  ๋•Œ, ์งง์€ ๋‹ต๋ณ€์ด๋‚˜ ๊ธด ๋‹ต๋ณ€์„ ์›ํ•  ๋•Œ ๋“ฑ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์‹œ์Šคํ…œ ๋ฉ”์„ธ์ง€๋ฅผ ์ƒ๋žตํ•˜๊ณ 
"You are a helpful and intelligent AI assistant who responds to user queries."
์™€ ๊ฐ™์€ ๊ฐ„๋‹จํ•œ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๋„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์ฑ„ํŒ…์„ ์‹œ์ž‘ํ–ˆ๋‹ค๋ฉด ๋Œ€ํ™”๋ฅผ ์ด์–ด ๋‚˜๊ฐ€๋Š” ๊ฐ€์žฅ ๋น ๋ฅธ ๋ฐฉ๋ฒ•์€ [`TextGenerationPipeline`]๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
ํ•œ๋ฒˆ `LLaMA-3`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฅผ ์‹œ์—ฐํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
์šฐ์„  `LLaMA-3`๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์Šน์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. [๊ถŒํ•œ ์‹ ์ฒญ](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct)์„ ํ•˜๊ณ  Hugging Face ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธํ•œ ํ›„์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋˜ํ•œ ์šฐ๋ฆฌ๋Š” `device_map="auto"`๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. GPU ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ์ถฉ๋ถ„ํ•˜๋‹ค๋ฉด ๋กœ๋“œ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  ๋ฉ”๋ชจ๋ฆฌ ์ ˆ์•ฝ์„ ์œ„ํ•ด dtype์„ `torch.bfloat16`์œผ๋กœ ์„ค์ •ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

```python
import torch
from transformers import pipeline

pipe = pipeline("text-generation", "meta-llama/Meta-Llama-3-8B-Instruct", torch_dtype=torch.bfloat16, device_map="auto")
response = pipe(chat, max_new_tokens=512)
print(response[0]['generated_text'][-1]['content'])
```

์ดํ›„ ์‹คํ–‰์„ ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค:

```text
(sigh) Oh boy, you're asking me for advice? You're gonna need a map, pal! Alright,
alright, I'll give you the lowdown. But don't say I didn't warn you, I'm a robot, not a tour guide!
So, you wanna know what's fun to do in the Big Apple? Well, let me tell you, there's a million
things to do, but I'll give you the highlights. First off, you gotta see the sights: the Statue of
Liberty, Central Park, Times Square... you know, the usual tourist traps. But if you're lookin' for
something a little more... unusual, I'd recommend checkin' out the Museum of Modern Art. It's got
some wild stuff, like that Warhol guy's soup cans and all that jazz.
And if you're feelin' adventurous, take a walk across the Brooklyn Bridge. Just watch out for
those pesky pigeons, they're like little feathered thieves! (laughs) Get it? Thieves? Ah, never mind.
Now, if you're lookin' for some serious fun, hit up the comedy clubs in Greenwich Village. You might
even catch a glimpse of some up-and-coming comedians... or a bunch of wannabes tryin' to make it big. (winks)
And finally, if you're feelin' like a real New Yorker, grab a slice of pizza from one of the many amazing
pizzerias around the city. Just don't try to order a "robot-sized" slice, trust me, it won't end well. (laughs)
So, there you have it, pal! That's my expert advice on what to do in New York. Now, if you'll
excuse me, I've got some oil changes to attend to. (winks)
```

์ฑ„ํŒ…์„ ๊ณ„์†ํ•˜๋ ค๋ฉด, ์ž์‹ ์˜ ๋‹ต์žฅ์„ ์ถ”๊ฐ€ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.
ํŒŒ์ดํ”„๋ผ์ธ์—์„œ ๋ฐ˜ํ™˜๋œ `response` ๊ฐ์ฒด์—๋Š” ํ˜„์žฌ๊นŒ์ง€ ๋ชจ๋“  ์ฑ„ํŒ…์„ ํฌํ•จํ•˜๊ณ  ์žˆ์œผ๋ฏ€๋กœ
๋ฉ”์„ธ์ง€๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ๋‹ค์‹œ ์ „๋‹ฌํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

```python
chat = response[0]['generated_text']
chat.append(
{"role": "user", "content": "Wait, what's so wild about soup cans?"}
)
response = pipe(chat, max_new_tokens=512)
print(response[0]['generated_text'][-1]['content'])
```

์ดํ›„ ์‹คํ–‰์„ ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค:

```text
(laughs) Oh, you're killin' me, pal! You don't get it, do you? Warhol's soup cans are like, art, man!
It's like, he took something totally mundane, like a can of soup, and turned it into a masterpiece. It's
like, "Hey, look at me, I'm a can of soup, but I'm also a work of art!"
(sarcastically) Oh, yeah, real original, Andy.
But, you know, back in the '60s, it was like, a big deal. People were all about challenging the
status quo, and Warhol was like, the king of that. He took the ordinary and made it extraordinary.
And, let me tell you, it was like, a real game-changer. I mean, who would've thought that a can of soup could be art? (laughs)
But, hey, you're not alone, pal. I mean, I'm a robot, and even I don't get it. (winks)
But, hey, that's what makes art, art, right? (laughs)
```

์ด ํŠœํ† ๋ฆฌ์–ผ์˜ ํ›„๋ฐ˜๋ถ€์—์„œ๋Š” ์„ฑ๋Šฅ๊ณผ ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ,
๊ทธ๋ฆฌ๊ณ  ์‚ฌ์šฉ์ž์˜ ํ•„์š”์— ๋งž๋Š” ์ฑ„ํŒ… ๋ชจ๋ธ ์„ ํƒ๊ณผ ๊ฐ™์€ ๊ตฌ์ฒด์ ์ธ ์ฃผ์ œ๋“ค์„ ๋‹ค๋ฃฐ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

## ์ฑ„ํŒ… ๋ชจ๋ธ ๊ณ ๋ฅด๊ธฐ[[choosing-a-chat-model]]

[Hugging Face Hub](https://huggingface.co/models?pipeline_tag=text-generation&sort=trending)๋Š” ์ฑ„ํŒ… ๋ชจ๋ธ์„ ๋‹ค์–‘ํ•˜๊ฒŒ ์ œ๊ณตํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
์ฒ˜์Œ ์‚ฌ์šฉํ•˜๋Š” ์‚ฌ๋žŒ์—๊ฒŒ๋Š” ๋ชจ๋ธ์„ ์„ ํƒํ•˜๊ธฐ๊ฐ€ ์–ด๋ ค์šธ์ง€ ๋ชจ๋ฆ…๋‹ˆ๋‹ค.
ํ•˜์ง€๋งŒ ๊ฑฑ์ •ํ•˜์ง€ ๋งˆ์„ธ์š”! ๋‘ ๊ฐ€์ง€๋งŒ ๋ช…์‹ฌํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค:

- ๋ชจ๋ธ์˜ ํฌ๊ธฐ๋Š” ์‹คํ–‰ ์†๋„์™€ ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ผ์˜ฌ ์ˆ˜ ์žˆ๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •.
- ๋ชจ๋ธ์ด ์ƒ์„ฑํ•œ ์ถœ๋ ฅ์˜ ํ’ˆ์งˆ.

์ผ๋ฐ˜์ ์œผ๋กœ ์ด๋Ÿฌํ•œ ์š”์†Œ๋“ค์€ ์ƒ๊ด€๊ด€๊ณ„๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋” ํฐ ๋ชจ๋ธ์ผ์ˆ˜๋ก ๋” ๋›ฐ์–ด๋‚œ ์„ฑ๋Šฅ์„ ๋ณด์ด๋Š” ๊ฒฝํ–ฅ์ด ์žˆ์ง€๋งŒ, ๋™์ผํ•œ ํฌ๊ธฐ์˜ ๋ชจ๋ธ์ด๋ผ๋„ ์œ ์˜๋ฏธํ•œ ์ฐจ์ด๊ฐ€ ๋‚  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

### ๋ชจ๋ธ์˜ ๋ช…์นญ๊ณผ ํฌ๊ธฐ[[size-and-model-naming]]

๋ชจ๋ธ์˜ ํฌ๊ธฐ๋Š” ๋ชจ๋ธ ์ด๋ฆ„์— ์žˆ๋Š” ์ˆซ์ž๋กœ ์‰ฝ๊ฒŒ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด, "8B" ๋˜๋Š” "70B"์™€ ๊ฐ™์€ ์ˆซ์ž๋Š” ๋ชจ๋ธ์˜ **ํŒŒ๋ผ๋ฏธํ„ฐ** ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.
์–‘์žํ™”๋œ ๊ฒฝ์šฐ๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด, ํŒŒ๋ผ๋ฏธํ„ฐ ํ•˜๋‚˜๋‹น ์•ฝ 2๋ฐ”์ดํŠธ์˜ ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ํ•„์š”ํ•˜๋‹ค๊ณ  ์˜ˆ์ƒ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ 80์–ต ๊ฐœ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ฐ€์ง„ "8B" ๋ชจ๋ธ์€ 16GB์˜ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ฐจ์ง€ํ•˜๋ฉฐ, ์ถ”๊ฐ€์ ์ธ ์˜ค๋ฒ„ํ—ค๋“œ๋ฅผ ์œ„ํ•œ ์•ฝ๊ฐ„์˜ ์—ฌ์œ ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
์ด๋Š” 3090์ด๋‚˜ 4090์™€ ๊ฐ™์€ 24GB์˜ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๊ฐ–์ถ˜ ํ•˜์ด์—”๋“œ GPU์— ์ ํ•ฉํ•ฉ๋‹ˆ๋‹ค.

์ผ๋ถ€ ์ฑ„ํŒ… ๋ชจ๋ธ์€ "Mixture of Experts" ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค.
์ด๋Ÿฌํ•œ ๋ชจ๋ธ์€ ํฌ๊ธฐ๋ฅผ "8x7B" ๋˜๋Š” "141B-A35B"์™€ ๊ฐ™์ด ๋‹ค๋ฅด๊ฒŒ ํ‘œ์‹œํ•˜๊ณค ํ•ฉ๋‹ˆ๋‹ค.
์ˆซ์ž๊ฐ€ ๋‹ค์†Œ ๋ชจํ˜ธํ•˜๋‹ค ๋Š๊ปด์งˆ ์ˆ˜ ์žˆ์ง€๋งŒ, ์ฒซ ๋ฒˆ์งธ ๊ฒฝ์šฐ์—๋Š” ์•ฝ 56์–ต(8x7) ๊ฐœ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์žˆ๊ณ ,
๋‘ ๋ฒˆ์งธ ๊ฒฝ์šฐ์—๋Š” ์•ฝ 141์–ต ๊ฐœ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์žˆ๋‹ค๊ณ  ํ•ด์„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์–‘์žํ™”๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋‹น ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰์„ 8๋น„ํŠธ, 4๋น„ํŠธ, ๋˜๋Š” ๊ทธ ์ดํ•˜๋กœ ์ค„์ด๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.
์ด ์ฃผ์ œ์— ๋Œ€ํ•ด์„œ๋Š” ์•„๋ž˜์˜ [๋ฉ”๋ชจ๋ฆฌ ๊ณ ๋ ค์‚ฌํ•ญ](#memory-considerations) ์ฑ•ํ„ฐ์—์„œ ๋” ์ž์„ธํžˆ ๋‹ค๋ฃฐ ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.

### ๊ทธ๋ ‡๋‹ค๋ฉด ์–ด๋–ค ์ฑ„ํŒ… ๋ชจ๋ธ์ด ๊ฐ€์žฅ ์ข‹์„๊นŒ์š”?[[but-which-chat-model-is-best]]
๋ชจ๋ธ์˜ ํฌ๊ธฐ ์™ธ์—๋„ ๊ณ ๋ คํ•  ์ ์ด ๋งŽ์Šต๋‹ˆ๋‹ค.
์ด๋ฅผ ํ•œ๋ˆˆ์— ์‚ดํŽด๋ณด๋ ค๋ฉด **๋ฆฌ๋”๋ณด๋“œ**๋ฅผ ์ฐธ๊ณ ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.
๊ฐ€์žฅ ์ธ๊ธฐ ์žˆ๋Š” ๋ฆฌ๋”๋ณด๋“œ ๋‘ ๊ฐ€์ง€๋Š” [OpenLLM Leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard)์™€ [LMSys Chatbot Arena Leaderboard](https://chat.lmsys.org/?leaderboard)์ž…๋‹ˆ๋‹ค.
LMSys ๋ฆฌ๋”๋ณด๋“œ์—๋Š” ๋…์  ๋ชจ๋ธ๋„ ํฌํ•จ๋˜์–ด ์žˆ์œผ๋‹ˆ,
`license` ์—ด์—์„œ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•œ ๋ชจ๋ธ์„ ์„ ํƒํ•œ ํ›„
[Hugging Face Hub](https://huggingface.co/models?pipeline_tag=text-generation&sort=trending)์—์„œ ๊ฒ€์ƒ‰ํ•ด ๋ณด์„ธ์š”.

### ์ „๋ฌธ ๋ถ„์•ผ[[specialist-domains]]
์ผ๋ถ€ ๋ชจ๋ธ์€ ์˜๋ฃŒ ๋˜๋Š” ๋ฒ•๋ฅ  ํ…์ŠคํŠธ์™€ ๊ฐ™์€ ํŠน์ • ๋„๋ฉ”์ธ์ด๋‚˜ ๋น„์˜์–ด๊ถŒ ์–ธ์–ด์— ํŠนํ™”๋˜์–ด ์žˆ๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.
์ด๋Ÿฌํ•œ ๋„๋ฉ”์ธ์—์„œ ์ž‘์—…ํ•  ๊ฒฝ์šฐ ํŠนํ™”๋œ ๋ชจ๋ธ์ด ์ข‹์€ ์„ฑ๋Šฅ์„ ๋ณด์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
ํ•˜์ง€๋งŒ ํ•ญ์ƒ ๊ทธ๋Ÿด ๊ฒƒ์ด๋ผ ๋‹จ์ •ํ•˜๊ธฐ๋Š” ํž˜๋“ญ๋‹ˆ๋‹ค.
ํŠนํžˆ ๋ชจ๋ธ์˜ ํฌ๊ธฐ๊ฐ€ ์ž‘๊ฑฐ๋‚˜ ์˜ค๋ž˜๋œ ๋ชจ๋ธ์ธ ๊ฒฝ์šฐ,
์ตœ์‹  ๋ฒ”์šฉ ๋ชจ๋ธ์ด ๋” ๋›ฐ์–ด๋‚  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋‹คํ–‰ํžˆ๋„ [domain-specific leaderboards](https://huggingface.co/blog/leaderboard-medicalllm)๊ฐ€ ์ ์ฐจ ๋“ฑ์žฅํ•˜๊ณ  ์žˆ์–ด, ํŠน์ • ๋„๋ฉ”์ธ์— ์ตœ๊ณ ์˜ ๋ชจ๋ธ์„ ์‰ฝ๊ฒŒ ์ฐพ์„ ์ˆ˜ ์žˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.


## ํŒŒ์ดํ”„๋ผ์ธ ๋‚ด๋ถ€๋Š” ์–ด๋–ป๊ฒŒ ๋˜์–ด์žˆ๋Š”๊ฐ€?[[what-happens-inside-the-pipeline]]
์œ„์˜ ๋น ๋ฅธ ์‹œ์ž‘์—์„œ๋Š” ๊ณ ์ˆ˜์ค€(High-Level) ํŒŒ์ดํ”„๋ผ์ธ์„ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.
์ด๋Š” ๊ฐ„ํŽธํ•œ ๋ฐฉ๋ฒ•์ด์ง€๋งŒ, ์œ ์—ฐ์„ฑ์€ ๋–จ์–ด์ง‘๋‹ˆ๋‹ค.
์ด์ œ ๋” ์ €์ˆ˜์ค€(Low-Level) ์ ‘๊ทผ ๋ฐฉ์‹์„ ํ†ตํ•ด ๋Œ€ํ™”์— ํฌํ•จ๋œ ๊ฐ ๋‹จ๊ณ„๋ฅผ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
์ฝ”๋“œ ์ƒ˜ํ”Œ๋กœ ์‹œ์ž‘ํ•œ ํ›„ ์ด๋ฅผ ๋ถ„์„ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค:

```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

# ์ž…๋ ฅ๊ฐ’์„ ์‚ฌ์ „์— ์ค€๋น„ํ•ด ๋†“์Šต๋‹ˆ๋‹ค
chat = [
{"role": "system", "content": "You are a sassy, wise-cracking robot as imagined by Hollywood circa 1986."},
{"role": "user", "content": "Hey, can you tell me any fun things to do in New York?"}
]

# 1: ๋ชจ๋ธ๊ณผ ํ† ํฌ๋‚˜์ด์ €๋ฅผ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค
model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct", device_map="auto", torch_dtype=torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct")

# 2: ์ฑ„ํŒ… ํ…œํ”Œ๋ฆฟ์— ์ ์šฉํ•ฉ๋‹ˆ๋‹ค
formatted_chat = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
print("Formatted chat:\n", formatted_chat)

# 3: ์ฑ„ํŒ…์„ ํ† ํฐํ™”ํ•ฉ๋‹ˆ๋‹ค (๋ฐ”๋กœ ์ด์ „ ๊ณผ์ •์—์„œ tokenized=True๋กœ ์„ค์ •ํ•˜๋ฉด ํ•œ๊บผ๋ฒˆ์— ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค)
inputs = tokenizer(formatted_chat, return_tensors="pt", add_special_tokens=False)
# ํ† ํฐํ™”๋œ ์ž…๋ ฅ๊ฐ’์„ ๋ชจ๋ธ์ด ์˜ฌ๋ผ์™€ ์žˆ๋Š” ๊ธฐ๊ธฐ(CPU/GPU)๋กœ ์˜ฎ๊น๋‹ˆ๋‹ค.
inputs = {key: tensor.to(model.device) for key, tensor in inputs.items()}
print("Tokenized inputs:\n", inputs)

# 4: ๋ชจ๋ธ๋กœ๋ถ€ํ„ฐ ์‘๋‹ต์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.1)
print("Generated tokens:\n", outputs)

# 5: ๋ชจ๋ธ์ด ์ถœ๋ ฅํ•œ ํ† ํฐ์„ ๋‹ค์‹œ ๋ฌธ์ž์—ด๋กœ ๋””์ฝ”๋”ฉํ•ฉ๋‹ˆ๋‹ค
decoded_output = tokenizer.decode(outputs[0][inputs['input_ids'].size(1):], skip_special_tokens=True)
print("Decoded output:\n", decoded_output)
```
์—ฌ๊ธฐ์—๋Š” ๊ฐ ๋ถ€๋ถ„์ด ์ž์ฒด ๋ฌธ์„œ๊ฐ€ ๋  ์ˆ˜ ์žˆ์„ ๋งŒํผ ๋งŽ์€ ๋‚ด์šฉ์ด ๋‹ด๊ฒจ ์žˆ์Šต๋‹ˆ๋‹ค!
๋„ˆ๋ฌด ์ž์„ธํžˆ ์„ค๋ช…ํ•˜๊ธฐ๋ณด๋‹ค๋Š” ๋„“์€ ๊ฐœ๋…์„ ๋‹ค๋ฃจ๊ณ , ์„ธ๋ถ€ ์‚ฌํ•ญ์€ ๋งํฌ๋œ ๋ฌธ์„œ์—์„œ ๋‹ค๋ฃจ๊ฒ ์Šต๋‹ˆ๋‹ค.
์ฃผ์š” ๋‹จ๊ณ„๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

1. [๋ชจ๋ธ](https://huggingface.co/learn/nlp-course/en/chapter2/3)๊ณผ [ํ† ํฌ๋‚˜์ด์ €](https://huggingface.co/learn/nlp-course/en/chapter2/4?fw=pt)๋ฅผ Hugging Face Hub์—์„œ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.
2. ๋Œ€ํ™”๋Š” ํ† ํฌ๋‚˜์ด์ €์˜ [์ฑ„ํŒ… ํ…œํ”Œ๋ฆฟ](https://huggingface.co/docs/transformers/main/en/chat_templating)์„ ์‚ฌ์šฉํ•˜์—ฌ ์–‘์‹์„ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค.
3. ๊ตฌ์„ฑ๋œ ์ฑ„ํŒ…์€ ํ† ํฌ๋‚˜์ด์ €๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ [ํ† ํฐํ™”](https://huggingface.co/learn/nlp-course/en/chapter2/4)๋ฉ๋‹ˆ๋‹ค.
4. ๋ชจ๋ธ์—์„œ ์‘๋‹ต์„ [์ƒ์„ฑ](https://huggingface.co/docs/transformers/en/llm_tutorial)ํ•ฉ๋‹ˆ๋‹ค.
5. ๋ชจ๋ธ์ด ์ถœ๋ ฅํ•œ ํ† ํฐ์„ ๋‹ค์‹œ ๋ฌธ์ž์—ด๋กœ ๋””์ฝ”๋”ฉํ•ฉ๋‹ˆ๋‹ค.

## ์„ฑ๋Šฅ, ๋ฉ”๋ชจ๋ฆฌ์™€ ํ•˜๋“œ์›จ์–ด[[performance-memory-and-hardware]]
์ด์ œ ๋Œ€๋ถ€๋ถ„์˜ ๋จธ์‹  ๋Ÿฌ๋‹ ์ž‘์—…์ด GPU์—์„œ ์‹คํ–‰๋œ๋‹ค๋Š” ๊ฒƒ์„ ์•„์‹ค ๊ฒ๋‹ˆ๋‹ค.
๋‹ค์†Œ ๋Š๋ฆฌ๊ธฐ๋Š” ํ•ด๋„ CPU์—์„œ ์ฑ„ํŒ… ๋ชจ๋ธ์ด๋‚˜ ์–ธ์–ด ๋ชจ๋ธ๋กœ๋ถ€ํ„ฐ ํ…์ŠคํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ๋„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
ํ•˜์ง€๋งŒ ๋ชจ๋ธ์„ GPU ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ ค๋†“์„ ์ˆ˜๋งŒ ์žˆ๋‹ค๋ฉด, GPU๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ผ๋ฐ˜์ ์œผ๋กœ ๋” ์„ ํ˜ธ๋˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.

### ๋ฉ”๋ชจ๋ฆฌ ๊ณ ๋ ค์‚ฌํ•ญ[[memory-considerations]]

๊ธฐ๋ณธ์ ์œผ๋กœ, [`TextGenerationPipeline`]์ด๋‚˜ [`AutoModelForCausalLM`]๊ณผ ๊ฐ™์€
Hugging Face ํด๋ž˜์Šค๋Š” ๋ชจ๋ธ์„ `float32` ์ •๋ฐ€๋„(Precision)๋กœ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.
์ด๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋‹น 4๋ฐ”์ดํŠธ(32๋น„ํŠธ)๋ฅผ ํ•„์š”๋กœ ํ•˜๋ฏ€๋กœ,
80์–ต ๊ฐœ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ฐ€์ง„ "8B" ๋ชจ๋ธ์€ ์•ฝ 32GB์˜ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ•„์š”๋กœ ํ•œ๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.
ํ•˜์ง€๋งŒ ์ด๋Š” ๋‚ญ๋น„์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!
๋Œ€๋ถ€๋ถ„์˜ ์ตœ์‹  ์–ธ์–ด ๋ชจ๋ธ์€ ํŒŒ๋ผ๋ฏธํ„ฐ๋‹น 2๋ฐ”์ดํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” "bfloat16" ์ •๋ฐ€๋„(Precision)๋กœ ํ•™์Šต๋ฉ๋‹ˆ๋‹ค.
ํ•˜๋“œ์›จ์–ด๊ฐ€ ์ด๋ฅผ ์ง€์›ํ•˜๋Š” ๊ฒฝ์šฐ(Nvidia 30xx/Axxx ์ด์ƒ),
`torch_dtype` ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์œ„์™€ ๊ฐ™์ด `bfloat16` ์ •๋ฐ€๋„(Precision)๋กœ ๋ชจ๋ธ์„ ๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋˜ํ•œ, 16๋น„ํŠธ๋ณด๋‹ค ๋” ๋‚ฎ์€ ์ •๋ฐ€๋„(Precision)๋กœ ๋ชจ๋ธ์„ ์••์ถ•ํ•˜๋Š”
"์–‘์žํ™”(quantization)" ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
์ด ๋ฐฉ๋ฒ•์€ ๋ชจ๋ธ์˜ ๊ฐ€์ค‘์น˜๋ฅผ ์†์‹ค ์••์ถ•ํ•˜์—ฌ ๊ฐ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ 8๋น„ํŠธ,
4๋น„ํŠธ ๋˜๋Š” ๊ทธ ์ดํ•˜๋กœ ์ค„์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
ํŠนํžˆ 4๋น„ํŠธ์—์„œ ๋ชจ๋ธ์˜ ์ถœ๋ ฅ์ด ๋ถ€์ •์ ์ธ ์˜ํ–ฅ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์ง€๋งŒ,
๋” ํฌ๊ณ  ๊ฐ•๋ ฅํ•œ ์ฑ„ํŒ… ๋ชจ๋ธ์„ ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ฆฌ๊ธฐ ์œ„ํ•ด ์ด ๊ฐ™์€ ํŠธ๋ ˆ์ด๋“œ์˜คํ”„๋ฅผ ๊ฐ์ˆ˜ํ•  ๊ฐ€์น˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
์ด์ œ `bitsandbytes`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฅผ ์‹ค์ œ๋กœ ํ™•์ธํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค:

```python
from transformers import AutoModelForCausalLM, BitsAndBytesConfig

quantization_config = BitsAndBytesConfig(load_in_8bit=True) # You can also try load_in_4bit
model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct", device_map="auto", quantization_config=quantization_config)
```

์œ„์˜ ์ž‘์—…์€ `pipeline` API์—๋„ ์ ์šฉ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค:

```python
from transformers import pipeline, BitsAndBytesConfig

quantization_config = BitsAndBytesConfig(load_in_8bit=True) # You can also try load_in_4bit
pipe = pipeline("text-generation", "meta-llama/Meta-Llama-3-8B-Instruct", device_map="auto", model_kwargs={"quantization_config": quantization_config})
```

`bitsandbytes` ์™ธ์—๋„ ๋ชจ๋ธ์„ ์–‘์žํ™”ํ•˜๋Š” ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค.
์ž์„ธํ•œ ๋‚ด์šฉ์€ [Quantization guide](./quantization)๋ฅผ ์ฐธ์กฐํ•ด ์ฃผ์„ธ์š”.


### ์„ฑ๋Šฅ ๊ณ ๋ ค์‚ฌํ•ญ[[performance-considerations]]

<Tip>

์–ธ์–ด ๋ชจ๋ธ ์„ฑ๋Šฅ๊ณผ ์ตœ์ ํ™”์— ๋Œ€ํ•œ ๋ณด๋‹ค ์ž์„ธํ•œ ๊ฐ€์ด๋“œ๋Š” [LLM Inference Optimization](./llm_optims)์„ ์ฐธ๊ณ ํ•˜์„ธ์š”.

</Tip>


์ผ๋ฐ˜์ ์œผ๋กœ ๋” ํฐ ์ฑ„ํŒ… ๋ชจ๋ธ์€ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋” ๋งŽ์ด ์š”๊ตฌํ•˜๊ณ ,
์†๋„๋„ ๋Š๋ ค์ง€๋Š” ๊ฒฝํ–ฅ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ตฌ์ฒด์ ์œผ๋กœ ๋งํ•˜์ž๋ฉด,
์ฑ„ํŒ… ๋ชจ๋ธ์—์„œ ํ…์ŠคํŠธ๋ฅผ ์ƒ์„ฑํ•  ๋•Œ๋Š” ์ปดํ“จํŒ… ํŒŒ์›Œ๋ณด๋‹ค **๋ฉ”๋ชจ๋ฆฌ ๋Œ€์—ญํญ**์ด ๋ณ‘๋ชฉ ํ˜„์ƒ์„ ์ผ์œผํ‚ค๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์Šต๋‹ˆ๋‹ค.
์ด๋Š” ๋ชจ๋ธ์ด ํ† ํฐ์„ ํ•˜๋‚˜์”ฉ ์ƒ์„ฑํ•  ๋•Œ๋งˆ๋‹ค ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ฉ”๋ชจ๋ฆฌ์—์„œ ์ฝ์–ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ ์ฑ„ํŒ… ๋ชจ๋ธ์—์„œ ์ดˆ๋‹น ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ํ† ํฐ ์ˆ˜๋Š” ๋ชจ๋ธ์ด ์œ„์น˜ํ•œ ๋ฉ”๋ชจ๋ฆฌ์˜ ๋Œ€์—ญํญ์„ ๋ชจ๋ธ์˜ ํฌ๊ธฐ๋กœ ๋‚˜๋ˆˆ ๊ฐ’์— ๋น„๋ก€ํ•ฉ๋‹ˆ๋‹ค.

์œ„์˜ ์˜ˆ์ œ์—์„œ๋Š” ๋ชจ๋ธ์ด bfloat16 ์ •๋ฐ€๋„(Precision)๋กœ ๋กœ๋“œ๋  ๋•Œ ์šฉ๋Ÿ‰์ด ์•ฝ 16GB์˜€์Šต๋‹ˆ๋‹ค.
์ด ๊ฒฝ์šฐ, ๋ชจ๋ธ์ด ์ƒ์„ฑํ•˜๋Š” ๊ฐ ํ† ํฐ๋งˆ๋‹ค 16GB๋ฅผ ๋ฉ”๋ชจ๋ฆฌ์—์„œ ์ฝ์–ด์•ผ ํ•œ๋‹ค๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค.
์ด ๋ฉ”๋ชจ๋ฆฌ ๋Œ€์—ญํญ์€ ์†Œ๋น„์ž์šฉ CPU์—์„œ๋Š” 20-100GB/sec,
์†Œ๋น„์ž์šฉ GPU๋‚˜ Intel Xeon, AMD Threadripper/Epyc,
์• ํ”Œ ์‹ค๋ฆฌ์ฝ˜๊ณผ ๊ฐ™์€ ํŠน์ˆ˜ CPU์—์„œ๋Š” 200-900GB/sec,
๋ฐ์ดํ„ฐ ์„ผํ„ฐ GPU์ธ Nvidia A100์ด๋‚˜ H100์—์„œ๋Š” ์ตœ๋Œ€ 2-3TB/sec์— ์ด๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ด๋Ÿฌํ•œ ์ •๋ณด๋Š” ๊ฐ์ž ํ•˜๋“œ์›จ์–ด์—์„œ ์ƒ์„ฑ ์†๋„๋ฅผ ์˜ˆ์ƒํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ํ…์ŠคํŠธ ์ƒ์„ฑ ์†๋„๋ฅผ ๊ฐœ์„ ํ•˜๋ ค๋ฉด ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•์€ ๋ชจ๋ธ์˜ ํฌ๊ธฐ๋ฅผ ์ค„์ด๊ฑฐ๋‚˜(์ฃผ๋กœ ์–‘์žํ™”๋ฅผ ์‚ฌ์šฉ),
๋ฉ”๋ชจ๋ฆฌ ๋Œ€์—ญํญ์ด ๋” ๋†’์€ ํ•˜๋“œ์›จ์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
์ด ๋Œ€์—ญํญ ๋ณ‘๋ชฉ ํ˜„์ƒ์„ ํ”ผํ•  ์ˆ˜ ์žˆ๋Š” ๊ณ ๊ธ‰ ๊ธฐ์ˆ ๋„ ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ์žˆ์Šต๋‹ˆ๋‹ค.
๊ฐ€์žฅ ์ผ๋ฐ˜์ ์ธ ๋ฐฉ๋ฒ•์€ [๋ณด์กฐ ์ƒ์„ฑ](https://huggingface.co/blog/assisted-generation), "์ถ”์ธก ์ƒ˜ํ”Œ๋ง"์ด๋ผ๊ณ  ๋ถˆ๋ฆฌ๋Š” ๊ธฐ์ˆ ์ž…๋‹ˆ๋‹ค.
์ด ๊ธฐ์ˆ ์€ ์ข…์ข… ๋” ์ž‘์€ "์ดˆ์•ˆ ๋ชจ๋ธ"์„ ์‚ฌ์šฉํ•˜์—ฌ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋ฏธ๋ž˜ ํ† ํฐ์„ ํ•œ ๋ฒˆ์— ์ถ”์ธกํ•œ ํ›„,
์ฑ„ํŒ… ๋ชจ๋ธ๋กœ ์ƒ์„ฑ ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
๋งŒ์•ฝ ์ฑ„ํŒ… ๋ชจ๋ธ์ด ์ถ”์ธก์„ ํ™•์ธํ•˜๋ฉด, ํ•œ ๋ฒˆ์˜ ์ˆœ์ „ํŒŒ์—์„œ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํ† ํฐ์„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์–ด
๋ณ‘๋ชฉ ํ˜„์ƒ์ด ํฌ๊ฒŒ ์ค„์–ด๋“ค๊ณ  ์ƒ์„ฑ ์†๋„๊ฐ€ ๋นจ๋ผ์ง‘๋‹ˆ๋‹ค.

๋งˆ์ง€๋ง‰์œผ๋กœ, "Mixture of Experts" (MoE) ๋ชจ๋ธ์— ๋Œ€ํ•ด์„œ๋„ ์งš๊ณ  ๋„˜์–ด๊ฐ€ ๋ณด๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.
Mixtral, Qwen-MoE, DBRX์™€ ๊ฐ™์€ ์ธ๊ธฐ ์žˆ๋Š” ์ฑ„ํŒ… ๋ชจ๋ธ์ด ๋ฐ”๋กœ MoE ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค.
์ด ๋ชจ๋ธ๋“ค์€ ํ† ํฐ์„ ์ƒ์„ฑํ•  ๋•Œ ๋ชจ๋“  ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์‚ฌ์šฉ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
์ด๋กœ ์ธํ•ด MoE ๋ชจ๋ธ์€ ์ „์ฒด ํฌ๊ธฐ๊ฐ€ ์ƒ๋‹นํžˆ ํด ์ˆ˜ ์žˆ์ง€๋งŒ,
์ฐจ์ง€ํ•˜๋Š” ๋ฉ”๋ชจ๋ฆฌ ๋Œ€์—ญํญ์€ ๋‚ฎ์€ ํŽธ์ž…๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ ๋™์ผํ•œ ํฌ๊ธฐ์˜ ์ผ๋ฐ˜ "์กฐ๋ฐ€ํ•œ(Dense)" ๋ชจ๋ธ๋ณด๋‹ค ๋ช‡ ๋ฐฐ ๋น ๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
ํ•˜์ง€๋งŒ ๋ณด์กฐ ์ƒ์„ฑ๊ณผ ๊ฐ™์€ ๊ธฐ์ˆ ์€ MoE ๋ชจ๋ธ์—์„œ ๋น„ํšจ์œจ์ ์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ƒˆ๋กœ์šด ์ถ”์ธก๋œ ํ† ํฐ์ด ์ถ”๊ฐ€๋˜๋ฉด์„œ ๋” ๋งŽ์€ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ํ™œ์„ฑํ™”๋˜๊ธฐ ๋•Œ๋ฌธ์—,
MoE ์•„ํ‚คํ…์ฒ˜๊ฐ€ ์ œ๊ณตํ•˜๋Š” ์†๋„ ์ด์ ์ด ์ƒ์‡„๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

0 comments on commit 924028f

Please sign in to comment.