| <!--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. | |
| โ ๏ธ 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. | |
| --> | |
| # LLaMA [[llama]] | |
| ## ๊ฐ์ [[overview]] | |
| LLaMA ๋ชจ๋ธ์ Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothรฉe Lacroix, Baptiste Roziรจre, Naman Goyal, Eric Hambro, Faisal Azhar, Aurelien Rodriguez, Armand Joulin, Edouard Grave, Guillaume Lample์ ์ํด ์ ์๋ [LLaMA: Open and Efficient Foundation Language Models](https://arxiv.org/abs/2302.13971)์์ ์๊ฐ๋์์ต๋๋ค. ์ด ๋ชจ๋ธ์ 7B์์ 65B๊ฐ์ ํ๋ผ๋ฏธํฐ๊น์ง ๋ค์ํ ํฌ๊ธฐ์ ๊ธฐ์ด ์ธ์ด ๋ชจ๋ธ์ ๋ชจ์๋์ ๊ฒ์ ๋๋ค. | |
| ๋ ผ๋ฌธ์ ์ด๋ก์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค: | |
| *"LLaMA๋ 7B์์ 65B๊ฐ์ ํ๋ผ๋ฏธํฐ ์๋ฅผ ๊ฐ์ง ๊ธฐ์ด ์ธ์ด ๋ชจ๋ธ์ ๋ชจ์์ ๋๋ค. ์ฐ๋ฆฌ๋ ์์กฐ ๊ฐ์ ํ ํฐ์ผ๋ก ๋ชจ๋ธ์ ํ๋ จ์์ผฐ๊ณ , ๊ณต๊ฐ์ ์ผ๋ก ์ด์ฉ ๊ฐ๋ฅํ ๋ฐ์ดํฐ์ ๋ง์ ์ฌ์ฉํ์ฌ ์ต๊ณ ์์ค์ ๋ชจ๋ธ์ ํ๋ จ์ํฌ ์ ์์์ ๋ณด์ฌ์ค๋๋ค. ํนํ, LLaMA-13B ๋ชจ๋ธ์ ๋๋ถ๋ถ์ ๋ฒค์น๋งํฌ์์ GPT-3 (175B)๋ฅผ ๋ฅ๊ฐํ๋ฉฐ, LLaMA-65B๋ ์ต๊ณ ์์ค์ ๋ชจ๋ธ์ธ Chinchilla-70B์ PaLM-540B์ ๋ฒ๊ธ๊ฐ๋ ์ฑ๋ฅ์ ๋ณด์ ๋๋ค. ์ฐ๋ฆฌ๋ ๋ชจ๋ ๋ชจ๋ธ์ ์ฐ๊ตฌ ์ปค๋ฎค๋ํฐ์ ๊ณต๊ฐํฉ๋๋ค."* | |
| ํ: | |
| - LLaMA ๋ชจ๋ธ์ ๊ฐ์ค์น๋ [์ด ์์](https://docs.google.com/forms/d/e/1FAIpQLSfqNECQnMkycAp2jP4Z9TFX0cGR4uf7b_fBxjY_OjhJILlKGA/viewform?usp=send_form)์ ์์ฑํ์ฌ ์ป์ ์ ์์ต๋๋ค. | |
| - ๊ฐ์ค์น๋ฅผ ๋ค์ด๋ก๋ํ ํ์๋ ์ด๋ฅผ [๋ณํ ์คํฌ๋ฆฝํธ](https://github.com/huggingface/transformers/blob/main/src/transformers/models/llama/convert_llama_weights_to_hf.py)๋ฅผ ์ฌ์ฉํ์ฌ Hugging Face Transformers ํ์์ผ๋ก ๋ณํํด์ผํฉ๋๋ค. ๋ณํ ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ๋ ค๋ฉด ์๋์ ์์ ๋ช ๋ น์ด๋ฅผ ์ฐธ๊ณ ํ์ธ์: | |
| ```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 | |
| ``` | |
| - ๋ณํ์ ํ์๋ค๋ฉด ๋ชจ๋ธ๊ณผ ํ ํฌ๋์ด์ ๋ ๋ค์๊ณผ ๊ฐ์ด ๋ก๋ํ ์ ์์ต๋๋ค: | |
| ```python | |
| from transformers import LlamaForCausalLM, LlamaTokenizer | |
| tokenizer = LlamaTokenizer.from_pretrained("/output/path") | |
| model = LlamaForCausalLM.from_pretrained("/output/path") | |
| ``` | |
| ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ๊ธฐ ์ํด์๋ ๋ชจ๋ธ์ float16 ์ ๋ฐ๋๋ก ์ ๋ถ ๋ก๋ํ ์ ์์ ๋งํผ์ ์ถฉ๋ถํ CPU RAM์ด ํ์ํฉ๋๋ค. (๊ฐ์ฅ ํฐ ๋ฒ์ ์ ๋ชจ๋ธ์ด ์ฌ๋ฌ ์ฒดํฌํฌ์ธํธ๋ก ๋๋์ด ์๋๋ผ๋, ๊ฐ ์ฒดํฌํฌ์ธํธ๋ ๋ชจ๋ธ์ ๊ฐ ๊ฐ์ค์น์ ์ผ๋ถ๋ฅผ ํฌํจํ๊ณ ์๊ธฐ ๋๋ฌธ์ ๋ชจ๋ ์ฒดํฌํฌ์ธํธ๋ฅผ RAM์ ๋ก๋ํด์ผ ํฉ๋๋ค) 65B ๋ชจ๋ธ์ ๊ฒฝ์ฐ, ์ด 130GB์ RAM์ด ํ์ํฉ๋๋ค. | |
| - LLaMA ํ ํฌ๋์ด์ ๋ [sentencepiece](https://github.com/google/sentencepiece)๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ๋ BPE ๋ชจ๋ธ์ ๋๋ค. sentencepiece์ ํน์ง ์ค ํ๋๋ ์ํ์ค๋ฅผ ๋์ฝ๋ฉํ ๋ ์ฒซ ํ ํฐ์ด ๋จ์ด์ ์์์ด๋ผ๋ฉด (์๋ฅผ ๋ค์ด "Banana"), ํ ํฌ๋์ด์ ๋ ๋ฌธ์์ด ์์ ๊ณต๋ฐฑ์ ์ถ๊ฐํ์ง ์๋๋ค๋ ๊ฒ์ ๋๋ค. | |
| ์ด ๋ชจ๋ธ์ [BlackSamorez](https://huggingface.co/BlackSamorez)์ ๊ธฐ์ฌ์ ํจ๊ป, [zphang](https://huggingface.co/zphang)์ ์ํด ์ ๊ณต๋์์ต๋๋ค. Hugging Face์์์ ๊ตฌํ ์ฝ๋๋ GPT-NeoX๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ๋ฉฐ [์ฌ๊ธฐ](https://github.com/EleutherAI/gpt-neox)์์ ์ฐพ์ ์ ์๊ณ , ์ ์์ ์ฝ๋ ์๋ณธ์ [์ฌ๊ธฐ](https://github.com/facebookresearch/llama)์์ ํ์ธํ ์ ์์ต๋๋ค. | |
| ์๋ LLaMA ๋ชจ๋ธ์ ๊ธฐ๋ฐ์ผ๋ก Meta AI์์ ๋ช ๊ฐ์ง ํ์ ์์ ์ ๋ฐํํ์ต๋๋ค: | |
| - **Llama2**: Llama2๋ ๊ตฌ์กฐ์ ์ธ ๋ช ๊ฐ์ง ์์ (Grouped Query Attention)์ ํตํด ๊ฐ์ ๋ ๋ฒ์ ์ด๋ฉฐ, 2์กฐ ๊ฐ์ ํ ํฐ์ผ๋ก ์ฌ์ ํ๋ จ์ด ๋์ด ์์ต๋๋ค. Llama2์ ๋ํ ์์ธํ ๋ด์ฉ์ [์ด ๋ฌธ์](llama2)๋ฅผ ์ฐธ๊ณ ํ์ธ์. | |
| ## ๋ฆฌ์์ค [[resources]] | |
| LLaMA๋ฅผ ์์ํ๋ ๋ฐ ๋์์ด ๋ Hugging Face ๋ฐ ์ปค๋ฎค๋ํฐ(๐๋ก ํ์)์ ๊ณต์ ์๋ฃ ๋ชฉ๋ก์ ๋๋ค. ์ฌ๊ธฐ์ ์๋ฃ๋ฅผ ์ ์ถํ๊ณ ์ถ๋ค๋ฉด Pull Request๋ฅผ ์ฌ๋ ค์ฃผ์ธ์! ์ถ๊ฐํ ์๋ฃ๋ ๊ธฐ์กด์ ์๋ฃ์ ์ค๋ณต๋์ง ์๊ณ ์๋ก์ด ๋ด์ฉ์ ๋ณด์ฌ์ฃผ๋ ๊ฒ์ด ์ข์ต๋๋ค. | |
| <PipelineTag pipeline="text-classification"/> | |
| - LLaMA ๋ชจ๋ธ์ ํ ์คํธ ๋ถ๋ฅ ์์ ์ ์ ์ฉํ๊ธฐ ์ํ ํ๋กฌํํธ ํ๋ ๋ฐฉ๋ฒ์ ๋ํ [๋ ธํธ๋ถ](https://colab.research.google.com/github/bigscience-workshop/petals/blob/main/examples/prompt-tuning-sst2.ipynb#scrollTo=f04ba4d2) ๐ | |
| <PipelineTag pipeline="question-answering"/> | |
| - [Stack Exchange](https://stackexchange.com/)์์ ์ง๋ฌธ์ ๋ตํ๋ LLaMA๋ฅผ ํ๋ จํ๋ ๋ฐฉ๋ฒ์ ์ํ [StackLLaMA: RLHF๋ก LLaMA๋ฅผ ํ๋ จํ๋ ์ค์ ๊ฐ์ด๋](https://huggingface.co/blog/stackllama#stackllama-a-hands-on-guide-to-train-llama-with-rlhf) ๐ | |
| โ๏ธ ์ต์ ํ | |
| - ์ ํ๋ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๊ฐ์ง GPU์์ xturing ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ LLaMA ๋ชจ๋ธ์ ๋ฏธ์ธ ์กฐ์ ํ๋ ๋ฐฉ๋ฒ์ ๋ํ [๋ ธํธ๋ถ](https://colab.research.google.com/drive/1SQUXq1AMZPSLD4mk3A3swUIc6Y2dclme?usp=sharing) ๐ | |
| โก๏ธ ์ถ๋ก | |
| - ๐ค PEFT ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ PeftModel์ ์ฌ์ฉํ์ฌ LLaMA ๋ชจ๋ธ์ ์คํํ๋ ๋ฐฉ๋ฒ์ ๋ํ [๋ ธํธ๋ถ](https://colab.research.google.com/github/DominguesM/alpaca-lora-ptbr-7b/blob/main/notebooks/02%20-%20Evaluate.ipynb) ๐ | |
| - LangChain์ ์ฌ์ฉํ์ฌ PEFT ์ด๋ํฐ LLaMA ๋ชจ๋ธ์ ๋ก๋ํ๋ ๋ฐฉ๋ฒ์ ๋ํ [๋ ธํธ๋ถ](https://colab.research.google.com/drive/1l2GiSSPbajVyp2Nk3CFT4t3uH6-5TiBe?usp=sharing) ๐ | |
| ๐ ๋ฐฐํฌ | |
| - ๐ค PEFT ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ์ฌ์ฉ์ ์นํ์ ์ธ UI๋ก LLaMA ๋ชจ๋ธ์ ๋ฏธ์ธ ์กฐ์ ํ๋ ๋ฐฉ๋ฒ์ ๋ํ [๋ ธํธ๋ถ](https://colab.research.google.com/github/lxe/simple-llama-finetuner/blob/master/Simple_LLaMA_FineTuner.ipynb#scrollTo=3PM_DilAZD8T) ๐ | |
| - Amazon SageMaker์์ ํ ์คํธ ์์ฑ์ ์ํด Open-LLaMA ๋ชจ๋ธ์ ๋ฐฐํฌํ๋ ๋ฐฉ๋ฒ์ ๋ํ [๋ ธํธ๋ถ](https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart-foundation-models/text-generation-open-llama.ipynb) ๐ | |
| ## LlamaConfig [[llamaconfig]] | |
| [[autodoc]] LlamaConfig | |
| ## LlamaTokenizer [[llamatokenizer]] | |
| [[autodoc]] LlamaTokenizer | |
| - build_inputs_with_special_tokens | |
| - get_special_tokens_mask | |
| - create_token_type_ids_from_sequences | |
| - save_vocabulary | |
| ## LlamaTokenizerFast [[llamatokenizerfast]] | |
| [[autodoc]] LlamaTokenizerFast | |
| - build_inputs_with_special_tokens | |
| - get_special_tokens_mask | |
| - create_token_type_ids_from_sequences | |
| - update_post_processor | |
| - save_vocabulary | |
| ## LlamaModel [[llamamodel]] | |
| [[autodoc]] LlamaModel | |
| - forward | |
| ## LlamaForCausalLM [[llamaforcausallm]] | |
| [[autodoc]] LlamaForCausalLM | |
| - forward | |
| ## LlamaForSequenceClassification [[llamaforsequenceclassification]] | |
| [[autodoc]] LlamaForSequenceClassification | |
| - forward | |