Skip to content

Commit 52a85e1

Browse files
committed
merge
2 parents 2f7001e + 3a99a54 commit 52a85e1

File tree

305 files changed

+35479
-99018
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

305 files changed

+35479
-99018
lines changed

scripts/check_copyright_header.py renamed to .github/scripts/check_copyright_header.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.\n\n"""
1212

1313
#Files in black list must be relative to main repo folder
14-
BLACKLIST = ["eval/open_llm_leaderboard/hellaswag_utils.py"]
14+
BLACKLIST = ["tools/benchmarks/llm_eval_harness/open_llm_leaderboard/hellaswag_utils.py"]
1515

1616
if __name__ == "__main__":
1717
for ext in ["*.py", "*.sh"]:

scripts/spellcheck.sh renamed to .github/scripts/spellcheck.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ done
1919
if [ ! "$sources_arg" ]; then
2020
echo "No files to spellcheck"
2121
else
22-
pyspelling -c scripts/spellcheck_conf/spellcheck.yaml --name Markdown $sources_arg
22+
pyspelling -c .github/scripts/spellcheck_conf/spellcheck.yaml --name Markdown $sources_arg
2323
fi

scripts/spellcheck_conf/spellcheck.yaml renamed to .github/scripts/spellcheck_conf/spellcheck.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ matrix:
55
d: en_US
66
dictionary:
77
wordlists:
8-
- scripts/spellcheck_conf/wordlist.txt
9-
output: scripts/spellcheck_conf/wordlist.dic
8+
- .github/scripts/spellcheck_conf/wordlist.txt
9+
output: .github/scripts/spellcheck_conf/wordlist.dic
1010
encoding: utf-8
1111
pipeline:
1212
- pyspelling.filters.context:

scripts/spellcheck_conf/wordlist.txt renamed to .github/scripts/spellcheck_conf/wordlist.txt

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,4 +1350,86 @@ SalesBot
13501350
Weaviate
13511351
MediaGen
13521352
SDXL
1353-
SVD
1353+
SVD
1354+
QLORA
1355+
Agentic
1356+
AutoGen
1357+
DeepLearning
1358+
Deeplearning
1359+
Llamaindex
1360+
KV
1361+
KVs
1362+
XSUM
1363+
contrains
1364+
knowlege
1365+
kv
1366+
prefilling
1367+
DataFrame
1368+
DuckDB
1369+
Groq
1370+
GroqCloud
1371+
Replit
1372+
Teslas
1373+
duckdb
1374+
teslas
1375+
Groqs
1376+
groq
1377+
schemas
1378+
Pinecone
1379+
Pinecone's
1380+
Repl
1381+
docsearch
1382+
presidental
1383+
CrewAI
1384+
kickstart
1385+
DataFrames
1386+
Groqing
1387+
Langchain
1388+
Plotly
1389+
dfs
1390+
yfinance
1391+
Groq's
1392+
LlamaChat
1393+
chatbot's
1394+
ConversationBufferWindowMemory
1395+
chatbot's
1396+
Lamini
1397+
lamini
1398+
nba
1399+
sqlite
1400+
customerservice
1401+
fn
1402+
ExecuTorch
1403+
LLMScore
1404+
RecursiveCharacterTextSplitter
1405+
TPD
1406+
TPM
1407+
Tianjun
1408+
Zhang
1409+
distractor
1410+
distractors
1411+
frac
1412+
numRefusal
1413+
totalQA
1414+
DirectoryLoader
1415+
SitemapLoader
1416+
nf
1417+
quant
1418+
DLAI
1419+
agentic
1420+
containts
1421+
dlai
1422+
Prerequirements
1423+
tp
1424+
QLoRA
1425+
ntasks
1426+
srun
1427+
xH
1428+
unquantized
1429+
eom
1430+
ipython
1431+
CPUs
1432+
modelUpgradeExample
1433+
guardrailing
1434+
MaaS
1435+
MFU

.github/workflows/spellcheck.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ jobs:
2020
uses: gaurav-nelson/[email protected]
2121
with:
2222
use-verbose-mode: 'yes'
23-
config-file: "scripts/markdown_link_check_config.json"
23+
config-file: ".github/scripts/markdown_link_check_config.json"
2424

2525
- name: Get changed files
2626
id: changed-files
27-
uses: tj-actions/changed-files@v29.0.4
27+
uses: tj-actions/changed-files@v41.0.0
2828
with:
2929

3030
files: |
@@ -42,7 +42,7 @@ jobs:
4242
4343
- name: Get changed files
4444
id: changed-files
45-
uses: tj-actions/changed-files@v29.0.4
45+
uses: tj-actions/changed-files@v41.0.0
4646
with:
4747
files: |
4848
**/*.md
@@ -56,11 +56,11 @@ jobs:
5656
if [ ! "$sources" ]; then
5757
echo "No files to spellcheck"
5858
else
59-
pyspelling -c $GITHUB_WORKSPACE/scripts/spellcheck_conf/spellcheck.yaml --name Markdown $sources
59+
pyspelling -c $GITHUB_WORKSPACE/.github/scripts/spellcheck_conf/spellcheck.yaml --name Markdown $sources
6060
fi
6161
6262
- name: In the case of misspellings
6363
if: ${{ failure() }}
6464
run: |
6565
echo "Please fix the misspellings. If you are sure about some of them, "
66-
echo "so append those to scripts/spellcheck_conf/wordlist.txt"
66+
echo "so append those to .github/scripts/spellcheck_conf/wordlist.txt"

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ For development and contributing to llama-recipes please install from source wit
4343
pip install -U pip setuptools
4444
pip install --extra-index-url https://download.pytorch.org/whl/test/cu118 -e .[tests,auditnlg,vllm]
4545
```
46-
The unit tests can be found in the [tests](./tests/) folder and you can run them from the main directory using:
46+
The unit tests can be found in the [src/tests](./src/tests/) folder and you can run them from the main directory using:
4747
```
48-
python -m pytest tests/
48+
python -m pytest src/tests/
4949
```
5050
To run all tests of a single file you can give the filename directly:
5151
```
52-
python -m pytest tests/test_finetuning.py
52+
python -m pytest src/tests/test_finetuning.py
5353
```
5454
To run a specific test you can filter for its name with
5555
```
56-
python -m pytest tests/test_finetuning.py -k test_finetuning_peft
56+
python -m pytest src/tests/test_finetuning.py -k test_finetuning_peft
5757
```
5858
To add a new test simply create a new test file under the tests folder (filename has to start with `test_`).
5959
Group tests spanning the same feature in the same file and create a subfolder if the tests are very extensive.

README.md

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
# Llama Recipes: Examples to get started using the Llama models from Meta
22
<!-- markdown-link-check-disable -->
3-
The 'llama-recipes' repository is a companion to the [Meta Llama 3](https://github.com/meta-llama/llama3) models. The goal of this repository 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 Meta Llama and other tools in the LLM ecosystem. The examples here showcase how to run Meta Llama locally, in the cloud, and on-prem. [Meta Llama 2](https://github.com/meta-llama/llama) is also supported in this repository. We highly recommend everyone to utilize [Meta Llama 3](https://github.com/meta-llama/llama3) due to its enhanced capabilities.
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.
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.
@@ -49,6 +55,7 @@ The 'llama-recipes' repository is a companion to the [Meta Llama 3](https://gith
4955
- [Repository Organization](#repository-organization)
5056
- [`recipes/`](#recipes)
5157
- [`src/`](#src)
58+
- [Supported Features](#supported-features)
5259
- [Contributing](#contributing)
5360
- [License](#license)
5461
@@ -136,14 +143,10 @@ Contains examples are organized in folders by topic:
136143
| Subfolder | Description |
137144
|---|---|
138145
[quickstart](./recipes/quickstart) | The "Hello World" of using Llama, start here if you are new to using Llama.
139-
[finetuning](./recipes/finetuning)|Scripts to finetune Llama on single-GPU and multi-GPU setups
140-
[inference](./recipes/inference)|Scripts to deploy Llama for inference locally and using model servers
141146
[use_cases](./recipes/use_cases)|Scripts showing common applications of Meta Llama3
147+
[3p_integrations](./recipes/3p_integrations)|Partner owned folder showing common applications of Meta Llama3
142148
[responsible_ai](./recipes/responsible_ai)|Scripts to use PurpleLlama for safeguarding model outputs
143-
[llama_api_providers](./recipes/llama_api_providers)|Scripts to run inference on Llama via hosted endpoints
144-
[benchmarks](./recipes/benchmarks)|Scripts to benchmark Llama models inference on various backends
145-
[code_llama](./recipes/code_llama)|Scripts to run inference with the Code Llama models
146-
[evaluation](./recipes/evaluation)|Scripts to evaluate fine-tuned Llama models using `lm-evaluation-harness` from `EleutherAI`
149+
[experimental](./recipes/experimental)|Meta Llama implementations of experimental LLM techniques
147150

148151
### `src/`
149152

@@ -158,14 +161,40 @@ Contains modules which support the example recipes:
158161
| [utils](src/llama_recipes/utils/) | Utility files for:<br/> - `train_utils.py` provides training/eval loop and more train utils.<br/> - `dataset_utils.py` to get preprocessed datasets.<br/> - `config_utils.py` to override the configs received from CLI.<br/> - `fsdp_utils.py` provides FSDP wrapping policy for PEFT methods.<br/> - `memory_utils.py` context manager to track different memory stats in train loop. |
159162

160163

164+
## Supported Features
165+
The recipes and modules in this repository support the following features:
166+
167+
| Feature | |
168+
| ---------------------------------------------- | - |
169+
| HF support for inference ||
170+
| HF support for finetuning ||
171+
| PEFT ||
172+
| Deferred initialization ( meta init) ||
173+
| Low CPU mode for multi GPU ||
174+
| Mixed precision ||
175+
| Single node quantization ||
176+
| Flash attention ||
177+
| Activation checkpointing FSDP ||
178+
| Hybrid Sharded Data Parallel (HSDP) ||
179+
| Dataset packing & padding ||
180+
| BF16 Optimizer (Pure BF16) ||
181+
| Profiling & MFU tracking ||
182+
| Gradient accumulation ||
183+
| CPU offloading ||
184+
| FSDP checkpoint conversion to HF for inference ||
185+
| W&B experiment tracker ||
186+
187+
161188
## Contributing
162189

163190
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
164191

165192
## License
166193
<!-- markdown-link-check-disable -->
167194

168-
See the License file for Meta Llama 3 [here](https://llama.meta.com/llama3/license/) and Acceptable Use Policy [here](https://llama.meta.com/llama3/use-policy/)
195+
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+
197+
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)
169198

170-
See the License file for Meta Llama 2 [here](https://llama.meta.com/llama2/license/) and Acceptable Use Policy [here](https://llama.meta.com/llama2/use-policy/)
199+
See the License file for Meta Llama 2 [here](https://github.com/meta-llama/llama-models/blob/main/models/llama2/LICENSE) and Acceptable Use Policy [here](https://github.com/meta-llama/llama-models/blob/main/models/llama2/USE_POLICY.md)
171200
<!-- markdown-link-check-enable -->

UPDATES.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
## System Prompt Update
22

33
### Observed Issue
4-
We received feedback from the community on our prompt template and we are providing an update to reduce the false refusal rates seen. False refusals occur when the model incorrectly refuses to answer a question that it should, for example due to overly broad instructions to be cautious in how it provides responses.
4+
We received feedback from the community on our prompt template and we are providing an update to reduce the false refusal rates seen. False refusals occur when the model incorrectly refuses to answer a question that it should, for example due to overly broad instructions to be cautious in how it provides responses.
55

66
### Updated approach
7-
Based on evaluation and analysis, we recommend the removal of the system prompt as the default setting. Pull request [#626](https://github.com/facebookresearch/llama/pull/626) removes the system prompt as the default option, but still provides an example to help enable experimentation for those using it.
7+
Based on evaluation and analysis, we recommend the removal of the system prompt as the default setting. Pull request [#626](https://github.com/facebookresearch/llama/pull/626) removes the system prompt as the default option, but still provides an example to help enable experimentation for those using it.
88

99
## Token Sanitization Update
1010

1111
### Observed Issue
12-
The PyTorch scripts currently provided for tokenization and model inference allow for direct prompt injection via string concatenation. Prompt injections allow for the addition of special system and instruction prompt strings from user-provided prompts.
12+
The PyTorch scripts currently provided for tokenization and model inference allow for direct prompt injection via string concatenation. Prompt injections allow for the addition of special system and instruction prompt strings from user-provided prompts.
1313

14-
As noted in the documentation, these strings are required to use the fine-tuned chat models. However, prompt injections have also been used for manipulating or abusing models by bypassing their safeguards, allowing for the creation of content or behaviors otherwise outside the bounds of acceptable use.
14+
As noted in the documentation, these strings are required to use the fine-tuned chat models. However, prompt injections have also been used for manipulating or abusing models by bypassing their safeguards, allowing for the creation of content or behaviors otherwise outside the bounds of acceptable use.
1515

1616
### Updated approach
17-
We recommend sanitizing [these strings](https://github.com/meta-llama/llama?tab=readme-ov-file#fine-tuned-chat-models) from any user provided prompts. Sanitization of user prompts mitigates malicious or accidental abuse of these strings. The provided scripts have been updated to do this.
17+
We recommend sanitizing [these strings](https://github.com/meta-llama/llama?tab=readme-ov-file#fine-tuned-chat-models) from any user provided prompts. Sanitization of user prompts mitigates malicious or accidental abuse of these strings. The provided scripts have been updated to do this.
1818

19-
Note: even with this update safety classifiers should still be applied to catch unsafe behaviors or content produced by the model. An [example](./recipes/inference/local_inference/inference.py) of how to deploy such a classifier can be found in the llama-recipes repository.
19+
Note: even with this update safety classifiers should still be applied to catch unsafe behaviors or content produced by the model. An [example](./recipes/quickstart/inference/local_inference/inference.py) of how to deploy such a classifier can be found in the llama-recipes repository.

docs/FAQ.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Here we discuss frequently asked questions that may occur and we found useful al
1616

1717
4. Can I add custom datasets?
1818

19-
Yes, you can find more information on how to do that [here](../recipes/finetuning/datasets/README.md).
19+
Yes, you can find more information on how to do that [here](../recipes/quickstart/finetuning/datasets/README.md).
2020

2121
5. What are the hardware SKU requirements for deploying these models?
2222

0 commit comments

Comments
 (0)