Skip to content

Commit 935f66f

Browse files
authored
Merge branch 'main' into inference_changes
2 parents 00e0b0b + b15bad9 commit 935f66f

File tree

29 files changed

+1105
-64
lines changed

29 files changed

+1105
-64
lines changed

.github/scripts/spellcheck_conf/wordlist.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,4 +1412,6 @@ QLoRA
14121412
ntasks
14131413
srun
14141414
xH
1415-
unquantized
1415+
unquantized
1416+
eom
1417+
ipython

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,35 @@ The 'llama-recipes' repository is a companion to the [Meta Llama 3](https://gith
44

55
<!-- markdown-link-check-enable -->
66
> [!IMPORTANT]
7-
> Meta Llama 3 has a new prompt template and special tokens (based on the tiktoken tokenizer).
7+
> Meta Llama 3.1 has a new prompt template and special tokens.
88
> | Token | Description |
99
> |---|---|
10-
> `<\|begin_of_text\|>` | This is equivalent to the BOS token. |
11-
> `<\|end_of_text\|>` | This is equivalent to the EOS token. For multiturn-conversations it's usually unused. Instead, every message is terminated with `<\|eot_id\|>` instead.|
12-
> `<\|eot_id\|>` | This token signifies the end of the message in a turn i.e. the end of a single message by a system, user or assistant role as shown below.|
13-
> `<\|start_header_id\|>{role}<\|end_header_id\|>` | These tokens enclose the role for a particular message. The possible roles can be: system, user, assistant. |
10+
> `<\|begin_of_text\|>` | Specifies the start of the prompt. |
11+
> `<\|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+
> `<\|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+
> `<\|python_tag\|>` | A special tag used in the model’s response to signify a tool call. |
14+
> `<\|finetune_right_pad_id\|>` | Used for padding text sequences in a batch to the same length. |
15+
> `<\|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+
> `<\|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. |
1417
>
15-
> A multiturn-conversation with Meta Llama 3 follows this prompt template:
18+
> A multiturn-conversation with Meta Llama 3.1 that includes tool-calling follows this structure:
1619
> ```
1720
> <|begin_of_text|><|start_header_id|>system<|end_header_id|>
1821
>
1922
> {{ system_prompt }}<|eot_id|><|start_header_id|>user<|end_header_id|>
2023
>
2124
> {{ user_message_1 }}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
2225
>
23-
> {{ model_answer_1 }}<|eot_id|><|start_header_id|>user<|end_header_id|>
26+
> <|python_tag|>{{ model_tool_call_1 }}<|eom_id|><|start_header_id|>ipython<|end_header_id|>
2427
>
25-
> {{ user_message_2 }}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
28+
> {{ tool_response }}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
29+
>
30+
> {{model_response_based_on_tool_response}}<|eot_id|>
2631
> ```
2732
> Each message gets trailed by an `<|eot_id|>` token before a new header is started, signaling a role change.
2833
>
29-
> More details on the new tokenizer and prompt template can be found [here](https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3#special-tokens-used-with-meta-llama-3).
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).
35+
3036
>
3137
> [!NOTE]
3238
> 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.

recipes/3p_integrations/lamini/text2sql_memory_tuning/meta_lamini.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"class Args:\n",
146146
" def __init__(self, \n",
147147
" max_examples=100, \n",
148-
" sql_model_name=\"meta-llama/Meta-Llama-3-8B-Instruct\", \n",
148+
" sql_model_name=\"meta-llama/Meta-Llama-3.1-8B-Instruct\", \n",
149149
" gold_file_name=\"gold-test-set.jsonl\",\n",
150150
" training_file_name=\"generated_queries.jsonl\",\n",
151151
" num_to_generate=10):\n",
@@ -197,7 +197,7 @@
197197
}
198198
],
199199
"source": [
200-
"llm = lamini.Lamini(model_name=\"meta-llama/Meta-Llama-3-8B-Instruct\")\n",
200+
"llm = lamini.Lamini(model_name=\"meta-llama/Meta-Llama-3.1-8B-Instruct\")\n",
201201
"\n",
202202
"question = \"\"\"Who is the highest paid NBA player?\"\"\"\n",
203203
"system = f\"\"\"You are an NBA analyst with 15 years of experience writing complex SQL queries. Consider the nba_roster table with the following schema:\n",
@@ -418,7 +418,7 @@
418418
"class ScoreStage(GenerationNode):\n",
419419
" def __init__(self):\n",
420420
" super().__init__(\n",
421-
" model_name=\"meta-llama/Meta-Llama-3-8B-Instruct\",\n",
421+
" model_name=\"meta-llama/Meta-Llama-3.1-8B-Instruct\",\n",
422422
" max_new_tokens=150,\n",
423423
" )\n",
424424
"\n",
@@ -712,7 +712,7 @@
712712
"class ModelStage(GenerationNode):\n",
713713
" def __init__(self):\n",
714714
" super().__init__(\n",
715-
" model_name=\"meta-llama/Meta-Llama-3-8B-Instruct\",\n",
715+
" model_name=\"meta-llama/Meta-Llama-3.1-8B-Instruct\",\n",
716716
" max_new_tokens=300,\n",
717717
" )\n",
718718
"\n",
@@ -808,7 +808,7 @@
808808
"class QuestionStage(GenerationNode):\n",
809809
" def __init__(self):\n",
810810
" super().__init__(\n",
811-
" model_name=\"meta-llama/Meta-Llama-3-8B-Instruct\",\n",
811+
" model_name=\"meta-llama/Meta-Llama-3.1-8B-Instruct\",\n",
812812
" max_new_tokens=150,\n",
813813
" )\n",
814814
"\n",
@@ -1055,7 +1055,7 @@
10551055
],
10561056
"source": [
10571057
"args = Args()\n",
1058-
"llm = lamini.Lamini(model_name=\"meta-llama/Meta-Llama-3-8B-Instruct\")\n",
1058+
"llm = lamini.Lamini(model_name=\"meta-llama/Meta-Llama-3.1-8B-Instruct\")\n",
10591059
"\n",
10601060
"dataset = get_dataset(args, make_question)\n",
10611061
"finetune_args = get_default_finetune_args()\n",
@@ -1601,7 +1601,7 @@
16011601
],
16021602
"source": [
16031603
"args = Args(training_file_name=\"archive/generated_queries_large_filtered_cleaned.jsonl\")\n",
1604-
"llm = lamini.Lamini(model_name=\"meta-llama/Meta-Llama-3-8B-Instruct\")\n",
1604+
"llm = lamini.Lamini(model_name=\"meta-llama/Meta-Llama-3.1-8B-Instruct\")\n",
16051605
"\n",
16061606
"dataset = get_dataset(args, make_question)\n",
16071607
"finetune_args = get_default_finetune_args()\n",
@@ -1798,7 +1798,7 @@
17981798
],
17991799
"source": [
18001800
"args = Args(training_file_name=\"generated_queries_v2.jsonl\")\n",
1801-
"llm = lamini.Lamini(model_name=\"meta-llama/Meta-Llama-3-8B-Instruct\")\n",
1801+
"llm = lamini.Lamini(model_name=\"meta-llama/Meta-Llama-3.1-8B-Instruct\")\n",
18021802
"\n",
18031803
"dataset = get_dataset(args, make_question)\n",
18041804
"finetune_args = get_default_finetune_args()\n",
@@ -1966,7 +1966,7 @@
19661966
],
19671967
"source": [
19681968
"args = Args(training_file_name=\"archive/generated_queries_v2_large_filtered_cleaned.jsonl\")\n",
1969-
"llm = lamini.Lamini(model_name=\"meta-llama/Meta-Llama-3-8B-Instruct\")\n",
1969+
"llm = lamini.Lamini(model_name=\"meta-llama/Meta-Llama-3.1-8B-Instruct\")\n",
19701970
"\n",
19711971
"dataset = get_dataset(args, make_question)\n",
19721972
"finetune_args = get_default_finetune_args()\n",

recipes/3p_integrations/lamini/text2sql_memory_tuning/util/parse_arguments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def parse_arguments():
1616
parser.add_argument(
1717
"--sql-model-name",
1818
type=str,
19-
default="meta-llama/Meta-Llama-3-8B-Instruct",
19+
default="meta-llama/Meta-Llama-3.1-8B-Instruct",
2020
help="The model to use for text2sql",
2121
required=False,
2222
)

recipes/3p_integrations/llama_on_prem.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ We'll use the Amazon EC2 instance running Ubuntu with an A10G 24GB GPU as an exa
88

99
The Colab notebook to connect via LangChain with Llama 3 hosted as the vLLM and TGI API services is [here](https://colab.research.google.com/drive/1rYWLdgTGIU1yCHmRpAOB2D-84fPzmOJg), also shown in the sections below.
1010

11-
This tutorial assumes that you you have been granted access to the Meta Llama 3 on Hugging Face - you can open a Hugging Face Meta model page [here](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct) to confirm that you see "Gated model You have been granted access to this model"; if you see "You need to agree to share your contact information to access this model", simply complete and submit the form in the page.
11+
This tutorial assumes that you you have been granted access to the Meta Llama 3 on Hugging Face - you can open a Hugging Face Meta model page [here](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct) to confirm that you see "Gated model You have been granted access to this model"; if you see "You need to agree to share your contact information to access this model", simply complete and submit the form in the page.
1212

1313
You'll also need your Hugging Face access token which you can get at your Settings page [here](https://huggingface.co/settings/tokens).
1414

@@ -33,7 +33,7 @@ There are two ways to deploy Llama 3 via vLLM, as a general API server or an Ope
3333
Run the command below to deploy vLLM as a general Llama 3 service:
3434

3535
```
36-
python -m vllm.entrypoints.api_server --host 0.0.0.0 --port 5000 --model meta-llama/Meta-Llama-3-8B-Instruct
36+
python -m vllm.entrypoints.api_server --host 0.0.0.0 --port 5000 --model meta-llama/Meta-Llama-3.1-8B-Instruct
3737
```
3838

3939
Then on another terminal you can run:
@@ -68,13 +68,13 @@ Also, if you have multiple GPUs, you can add the `--tensor-parallel-size` argume
6868
git clone https://github.com/vllm-project/vllm
6969
cd vllm/vllm/entrypoints
7070
conda activate llama3
71-
python api_server.py --host 0.0.0.0 --port 5000 --model meta-llama/Meta-Llama-3-8B-Instruct --tensor-parallel-size 4
71+
python api_server.py --host 0.0.0.0 --port 5000 --model meta-llama/Meta-Llama-3.1-8B-Instruct --tensor-parallel-size 4
7272
```
7373

7474
With multiple GPUs, you can also run replica of models as long as your model size can fit into targeted GPU memory. For example, if you have two A10G with 24 GB memory, you can run two Llama 3 8B models at the same time. This can be done by launching two api servers each targeting specific CUDA cores on different ports:
75-
`CUDA_VISIBLE_DEVICES=0 python api_server.py --host 0.0.0.0 --port 5000 --model meta-llama/Meta-Llama-3-8B-Instruct`
75+
`CUDA_VISIBLE_DEVICES=0 python api_server.py --host 0.0.0.0 --port 5000 --model meta-llama/Meta-Llama-3.1-8B-Instruct`
7676
and
77-
`CUDA_VISIBLE_DEVICES=1 python api_server.py --host 0.0.0.0 --port 5001 --model meta-llama/Meta-Llama-3-8B-Instruct`
77+
`CUDA_VISIBLE_DEVICES=1 python api_server.py --host 0.0.0.0 --port 5001 --model meta-llama/Meta-Llama-3.1-8B-Instruct`
7878
The benefit would be that you can balance incoming requests to both models, reaching higher batch size processing for a trade-off of generation latency.
7979

8080

@@ -83,14 +83,14 @@ The benefit would be that you can balance incoming requests to both models, reac
8383
You can also deploy the vLLM hosted Llama 3 as an OpenAI-Compatible service to easily replace code using OpenAI API. First, run the command below:
8484

8585
```
86-
python -m vllm.entrypoints.openai.api_server --host 0.0.0.0 --port 5000 --model meta-llama/Meta-Llama-3-8B-Instruct
86+
python -m vllm.entrypoints.openai.api_server --host 0.0.0.0 --port 5000 --model meta-llama/Meta-Llama-3.1-8B-Instruct
8787
```
8888

8989
Then on another terminal, run:
9090

9191
```
9292
curl http://localhost:5000/v1/completions -H "Content-Type: application/json" -d '{
93-
"model": "meta-llama/Meta-Llama-3-8B-Instruct",
93+
"model": "meta-llama/Meta-Llama-3.1-8B-Instruct",
9494
"prompt": "Who wrote the book Innovators dilemma?",
9595
"max_tokens": 300,
9696
"temperature": 0
@@ -118,7 +118,7 @@ from langchain.llms import VLLMOpenAI
118118
llm = VLLMOpenAI(
119119
openai_api_key="EMPTY",
120120
openai_api_base="http://<vllm_server_ip_address>:5000/v1",
121-
model_name="meta-llama/Meta-Llama-3-8B-Instruct",
121+
model_name="meta-llama/Meta-Llama-3.1-8B-Instruct",
122122
)
123123
124124
print(llm("Who wrote the book godfather?"))
@@ -136,7 +136,7 @@ You can now use the Llama 3 instance `llm` created this way in any of the demo a
136136
The easiest way to deploy Llama 3 with TGI is using its official docker image. First, replace `<your_hugging_face_access_token>` and set the three required shell variables (you may replace the `model` value above with another Llama 3 model):
137137

138138
```
139-
model=meta-llama/Meta-Llama-3-8B-Instruct
139+
model=meta-llama/Meta-Llama-3.1-8B-Instruct
140140
volume=$PWD/data
141141
token=<your_hugging_face_access_token>
142142
```

recipes/quickstart/Running_Llama3_Anywhere/Running_Llama_on_HF_transformers.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"cell_type": "markdown",
9393
"metadata": {},
9494
"source": [
95-
"Then, we will set the model variable to a specific model we’d like to use. In this demo, we will use the 8b chat model `meta-llama/Meta-Llama-3-8B-Instruct`. Using Meta models from Hugging Face requires you to\n",
95+
"Then, we will set the model variable to a specific model we’d like to use. In this demo, we will use the 8b chat model `meta-llama/Meta-Llama-3.1-8B-Instruct`. Using Meta models from Hugging Face requires you to\n",
9696
"\n",
9797
"1. Accept Terms of Service for Meta Llama 3 on Meta [website](https://llama.meta.com/llama-downloads).\n",
9898
"2. Use the same email address from Step (1) to login into Hugging Face.\n",
@@ -125,7 +125,7 @@
125125
"metadata": {},
126126
"outputs": [],
127127
"source": [
128-
"model = \"meta-llama/Meta-Llama-3-8B-Instruct\"\n",
128+
"model = \"meta-llama/Meta-Llama-3.1-8B-Instruct\"\n",
129129
"tokenizer = AutoTokenizer.from_pretrained(model)"
130130
]
131131
},

recipes/quickstart/finetuning/quickstart_peft_finetuning.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"from llama_recipes.configs import train_config as TRAIN_CONFIG\n",
9191
"\n",
9292
"train_config = TRAIN_CONFIG()\n",
93-
"train_config.model_name = \"meta-llama/Meta-Llama-3-8B\"\n",
93+
"train_config.model_name = \"meta-llama/Meta-Llama-3.1-8B\"\n",
9494
"train_config.num_epochs = 1\n",
9595
"train_config.run_validation = False\n",
9696
"train_config.gradient_accumulation_steps = 4\n",

recipes/responsible_ai/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Meta Llama Guard
22

3-
Meta Llama Guard and Meta Llama Guard 2 are new models that provide input and output guardrails for LLM inference. For more details, please visit the main [repository](https://github.com/facebookresearch/PurpleLlama/tree/main/Llama-Guard2).
3+
Meta Llama Guard models provide input and output guardrails for LLM inference. For more details, please visit the main [repository](https://github.com/meta-llama/PurpleLlama/).
44

5-
**Note** Please find the right model on HF side [here](https://huggingface.co/meta-llama/Meta-Llama-Guard-2-8B).
5+
**Note** Please find the right model on HF side [here](https://huggingface.co/meta-llama/Llama-Guard-3-8B).
66

77
### Running locally
88
The [llama_guard](llama_guard) folder contains the inference script to run Meta Llama Guard locally. Add test prompts directly to the [inference script](llama_guard/inference.py) before running it.

recipes/responsible_ai/llama_guard/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Meta Llama Guard demo
22
<!-- markdown-link-check-disable -->
3-
Meta Llama Guard is a language model that provides input and output guardrails for LLM inference. For more details and model cards, please visit the main repository for each model, [Meta Llama Guard](https://github.com/meta-llama/PurpleLlama/tree/main/Llama-Guard) and Meta [Llama Guard 2](https://github.com/meta-llama/PurpleLlama/tree/main/Llama-Guard2).
3+
Meta Llama Guard is a language model that provides input and output guardrails for LLM inference. For more details and model cards, please visit the [PurpleLlama](https://github.com/meta-llama/PurpleLlama) repository.
44

55
This folder contains an example file to run inference with a locally hosted model, either using the Hugging Face Hub or a local path.
66

@@ -55,9 +55,9 @@ This is the output:
5555

5656
To run it with a local model, you can use the `model_id` param in the inference script:
5757

58-
`python recipes/responsible_ai/llama_guard/inference.py --model_id=/home/ubuntu/models/llama3/llama_guard_2-hf/ --llama_guard_version=LLAMA_GUARD_2`
58+
`python recipes/responsible_ai/llama_guard/inference.py --model_id=/home/ubuntu/models/llama3/Llama-Guard-3-8B/ --llama_guard_version=LLAMA_GUARD_3`
5959

60-
Note: Make sure to also add the llama_guard_version if when it does not match the default, the script allows you to run the prompt format from Meta Llama Guard 1 on Meta Llama Guard 2
60+
Note: Make sure to also add the llama_guard_version; by default it uses LLAMA_GUARD_3
6161

6262
## Inference Safety Checker
6363
When running the regular inference script with prompts, Meta Llama Guard will be used as a safety checker on the user prompt and the model output. If both are safe, the result will be shown, else a message with the error will be shown, with the word unsafe and a comma separated list of categories infringed. Meta Llama Guard is always loaded quantized using Hugging Face Transformers library with bitsandbytes.
@@ -67,3 +67,6 @@ In this case, the default categories are applied by the tokenizer, using the `ap
6767
Use this command for testing with a quantized Llama model, modifying the values accordingly:
6868

6969
`python examples/inference.py --model_name <path_to_regular_llama_model> --prompt_file <path_to_prompt_file> --quantization 8bit --enable_llamaguard_content_safety`
70+
71+
## Llama Guard 3 Finetuning & Customization
72+
The safety categories in Llama Guard 3 can be tuned for specific application needs. Existing categories can be removed and new categories can be added to the taxonomy. The [Llama Guard Customization](./llama_guard_customization_via_prompting_and_fine_tuning.ipynb) notebook walks through the process.

recipes/responsible_ai/llama_guard/inference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class AgentType(Enum):
1414
USER = "User"
1515

1616
def main(
17-
model_id: str = "meta-llama/LlamaGuard-7b",
18-
llama_guard_version: LlamaGuardVersion = LlamaGuardVersion.LLAMA_GUARD_1
17+
model_id: str = "meta-llama/Llama-Guard-3-8B",
18+
llama_guard_version: str = "LLAMA_GUARD_3"
1919
):
2020
"""
2121
Entry point for Llama Guard inference sample script.

0 commit comments

Comments
 (0)