|
1 | 1 | # Llama Recipes: Examples to get started using the Llama models from Meta
|
2 | 2 | <!-- markdown-link-check-disable -->
|
3 |
| -The 'llama-recipes' repository is a companion to the [Meta Llama](https://github.com/meta-llama/llama-models) models. We support the latest version, [Llama 3.1](https://github.com/meta-llama/llama-models/blob/main/models/llama3_1/MODEL_CARD.md), in this repository. The goal is to provide a scalable library for fine-tuning Meta Llama models, along with some example scripts and notebooks to quickly get started with using the models in a variety of use-cases, including fine-tuning for domain adaptation and building LLM-based applications with Llama and other tools in the LLM ecosystem. The examples here showcase how to run Llama locally, in the cloud, and on-prem. |
| 3 | +The 'llama-recipes' repository is a companion to the [Meta Llama](https://github.com/meta-llama/llama-models) models. We support the latest version, [Llama 3.2 Vision](https://github.com/meta-llama/llama-models/blob/main/models/llama3_2/MODEL_CARD_VISION.md) and [Llama 3.2 Text](https://github.com/meta-llama/llama-models/blob/main/models/llama3_2/MODEL_CARD.md), in this repository. This repository contains example scripts and notebooks to get started with the models in a variety of use-cases, including fine-tuning for domain adaptation and building LLM-based applications with Llama and other tools in the LLM ecosystem. The examples here use Llama locally, in the cloud, and on-prem. |
4 | 4 |
|
5 | 5 | <!-- markdown-link-check-enable -->
|
6 | 6 | > [!IMPORTANT]
|
7 |
| -> Meta Llama 3.1 has a new prompt template and special tokens. |
| 7 | +> Llama 3.2 follows the same prompt template as Llama 3.1, with a new special token `<|image|>` representing the input image for the multimodal models. |
| 8 | +> |
8 | 9 | > | Token | Description |
|
9 | 10 | > |---|---|
|
10 | 11 | > `<\|begin_of_text\|>` | Specifies the start of the prompt. |
|
| 12 | +> `<\|image\|>` | Represents the image tokens passed as an input to Llama. | |
11 | 13 | > `<\|eot_id\|>` | This token signifies the end of a turn i.e. the end of the model's interaction either with the user or tool executor. |
|
12 | 14 | > `<\|eom_id\|>` | End of Message. A message represents a possible stopping point where the model can inform the execution environment that a tool call needs to be made. |
|
13 | 15 | > `<\|python_tag\|>` | A special tag used in the model’s response to signify a tool call. |
|
14 | 16 | > `<\|finetune_right_pad_id\|>` | Used for padding text sequences in a batch to the same length. |
|
15 | 17 | > `<\|start_header_id\|>{role}<\|end_header_id\|>` | These tokens enclose the role for a particular message. The possible roles can be: system, user, assistant and ipython. |
|
16 | 18 | > `<\|end_of_text\|>` | This is equivalent to the EOS token. For multiturn-conversations it's usually unused, this token is expected to be generated only by the base models. |
|
17 | 19 | >
|
18 |
| -> A multiturn-conversation with Meta Llama 3.1 that includes tool-calling follows this structure: |
19 |
| -> ``` |
20 |
| -> <|begin_of_text|><|start_header_id|>system<|end_header_id|> |
21 |
| -> |
22 |
| -> {{ system_prompt }}<|eot_id|><|start_header_id|>user<|end_header_id|> |
23 |
| -> |
24 |
| -> {{ user_message_1 }}<|eot_id|><|start_header_id|>assistant<|end_header_id|> |
25 |
| -> |
26 |
| -> <|python_tag|>{{ model_tool_call_1 }}<|eom_id|><|start_header_id|>ipython<|end_header_id|> |
27 |
| -> |
28 |
| -> {{ tool_response }}<|eot_id|><|start_header_id|>assistant<|end_header_id|> |
29 |
| -> |
30 |
| -> {{model_response_based_on_tool_response}}<|eot_id|> |
31 |
| -> ``` |
32 |
| -> Each message gets trailed by an `<|eot_id|>` token before a new header is started, signaling a role change. |
33 |
| -> |
34 |
| -> More details on the new tokenizer and prompt template can be found [here](https://llama.meta.com/docs/model-cards-and-prompt-formats/llama3_1). |
| 20 | +> More details on the prompt templates for image reasoning, tool-calling and code interpreter can be found [on the documentation website](https://llama.meta.com/docs/model-cards-and-prompt-formats/llama3_2). |
| 21 | +
|
35 | 22 |
|
36 |
| -> |
37 |
| -> [!NOTE] |
38 |
| -> The llama-recipes repository was recently refactored to promote a better developer experience of using the examples. Some files have been moved to new locations. The `src/` folder has NOT been modified, so the functionality of this repo and package is not impacted. |
39 |
| -> |
40 |
| -> Make sure you update your local clone by running `git pull origin main` |
41 | 23 |
|
42 | 24 | ## Table of Contents
|
43 | 25 |
|
44 |
| -- [Llama Recipes: Examples to get started using the Meta Llama models from Meta](#llama-recipes-examples-to-get-started-using-the-llama-models-from-meta) |
| 26 | +- [Llama Recipes: Examples to get started using the Llama models from Meta](#llama-recipes-examples-to-get-started-using-the-llama-models-from-meta) |
45 | 27 | - [Table of Contents](#table-of-contents)
|
46 | 28 | - [Getting Started](#getting-started)
|
47 | 29 | - [Prerequisites](#prerequisites)
|
@@ -113,23 +95,21 @@ pip install -e .[tests,auditnlg,vllm]
|
113 | 95 | ```
|
114 | 96 |
|
115 | 97 |
|
116 |
| -### Getting the Meta Llama models |
117 |
| -You can find Meta Llama models on Hugging Face hub [here](https://huggingface.co/meta-llama), **where models with `hf` in the name are already converted to Hugging Face checkpoints so no further conversion is needed**. The conversion step below is only for original model weights from Meta that are hosted on Hugging Face model hub as well. |
| 98 | +### Getting the Llama models |
| 99 | +You can find Llama models on Hugging Face hub [here](https://huggingface.co/meta-llama), **where models with `hf` in the name are already converted to Hugging Face checkpoints so no further conversion is needed**. The conversion step below is only for original model weights from Meta that are hosted on Hugging Face model hub as well. |
118 | 100 |
|
119 | 101 | #### Model conversion to Hugging Face
|
120 |
| -The recipes and notebooks in this folder are using the Meta Llama model definition provided by Hugging Face's transformers library. |
121 |
| -
|
122 |
| -Given that the original checkpoint resides under models/7B you can install all requirements and convert the checkpoint with: |
| 102 | +If you have the model checkpoints downloaded from the Meta website, you can convert it to the Hugging Face format with: |
123 | 103 |
|
124 | 104 | ```bash
|
125 | 105 | ## Install Hugging Face Transformers from source
|
126 |
| -pip freeze | grep transformers ## verify it is version 4.31.0 or higher |
| 106 | +pip freeze | grep transformers ## verify it is version 4.45.0 or higher |
127 | 107 |
|
128 | 108 | git clone [email protected]:huggingface/transformers.git
|
129 | 109 | cd transformers
|
130 | 110 | pip install protobuf
|
131 | 111 | python src/transformers/models/llama/convert_llama_weights_to_hf.py \
|
132 |
| - --input_dir /path/to/downloaded/llama/weights --model_size 7B --output_dir /output/path |
| 112 | + --input_dir /path/to/downloaded/llama/weights --model_size 3B --output_dir /output/path |
133 | 113 | ```
|
134 | 114 |
|
135 | 115 |
|
@@ -192,6 +172,8 @@ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduc
|
192 | 172 | ## License
|
193 | 173 | <!-- markdown-link-check-disable -->
|
194 | 174 |
|
| 175 | +See the License file for Meta Llama 3.2 [here](https://github.com/meta-llama/llama-models/blob/main/models/llama3_2/LICENSE) and Acceptable Use Policy [here](https://github.com/meta-llama/llama-models/blob/main/models/llama3_2/USE_POLICY.md) |
| 176 | + |
195 | 177 | See the License file for Meta Llama 3.1 [here](https://github.com/meta-llama/llama-models/blob/main/models/llama3_1/LICENSE) and Acceptable Use Policy [here](https://github.com/meta-llama/llama-models/blob/main/models/llama3_1/USE_POLICY.md)
|
196 | 178 |
|
197 | 179 | See the License file for Meta Llama 3 [here](https://github.com/meta-llama/llama-models/blob/main/models/llama3/LICENSE) and Acceptable Use Policy [here](https://github.com/meta-llama/llama-models/blob/main/models/llama3/USE_POLICY.md)
|
|
0 commit comments