Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: cc-by-sa-4.0
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
tags:
|
6 |
+
- text-generation-inference
|
7 |
+
pipeline_tag: text-generation
|
8 |
+
---
|
9 |
+
|
10 |
+
|
11 |
+
## Original model card
|
12 |
+
|
13 |
+
Buy me a coffee if you like this project ;)
|
14 |
+
<a href="https://www.buymeacoffee.com/s3nh"><img src="https://www.buymeacoffee.com/assets/img/guidelines/download-assets-sm-1.svg" alt=""></a>
|
15 |
+
|
16 |
+
#### Description
|
17 |
+
|
18 |
+
GGML Format model files for [This project](togethercomputer/LLaMA-2-7B-32K).
|
19 |
+
|
20 |
+
|
21 |
+
### inference
|
22 |
+
|
23 |
+
|
24 |
+
```python
|
25 |
+
|
26 |
+
import ctransformers
|
27 |
+
|
28 |
+
from ctransformers import AutoModelForCausalLM
|
29 |
+
|
30 |
+
model = AutoModelForCausalLM.from_pretrained(output_dir, ggml_file,
|
31 |
+
gpu_layers=32, model_type="llama")
|
32 |
+
|
33 |
+
manual_input: str = "Tell me about your last dream, please."
|
34 |
+
|
35 |
+
|
36 |
+
llm(manual_input,
|
37 |
+
max_new_tokens=256,
|
38 |
+
temperature=0.9,
|
39 |
+
top_p= 0.7)
|
40 |
+
|
41 |
+
```
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
# Original model card
|
46 |
+
|
47 |
+
## Model Description
|
48 |
+
|
49 |
+
LLaMA-2-7B-32K is an open-source, long context language model developed by Together, fine-tuned from Meta's original Llama-2 7B model.
|
50 |
+
This model represents our efforts to contribute to the rapid progress of the open-source ecosystem for large language models.
|
51 |
+
The model has been extended to a context length of 32K with position interpolation,
|
52 |
+
allowing applications on multi-document QA, long text summarization, etc.
|
53 |
+
|
54 |
+
## What's new?
|
55 |
+
|
56 |
+
This model introduces several improvements and new features:
|
57 |
+
|
58 |
+
1. **Extended Context:** The model has been trained to handle context lengths up to 32K, which is a significant improvement over the previous versions.
|
59 |
+
|
60 |
+
2. **Pre-training and Instruction Tuning:** We have shared our data recipe, which consists of a mixture of pre-training and instruction tuning data.
|
61 |
+
|
62 |
+
3. **Fine-tuning Examples:** We provide examples of how to fine-tune the model for specific applications, including book summarization and long context question and answering.
|
63 |
+
|
64 |
+
4. **Software Support:** We have updated both the inference and training stack to allow efficient inference and fine-tuning for 32K context.
|
65 |
+
|
66 |
+
## Model Architecture
|
67 |
+
|
68 |
+
The model follows the architecture of Llama-2-7B and extends it to handle a longer context. It leverages the recently released FlashAttention-2 and a range of other optimizations to improve the speed and efficiency of inference and training.
|
69 |
+
|
70 |
+
## Training and Fine-tuning
|
71 |
+
|
72 |
+
The model has been trained using a mixture of pre-training and instruction tuning data.
|
73 |
+
- In the first training phase of continued pre-training, our data mixture contains 25% RedPajama Book, 25% RedPajama ArXiv (including abstracts), 25% other data from RedPajama, and 25% from the UL2 Oscar Data, which is a part of OIG (Open-Instruction-Generalist), asking the model to fill in missing chunks, or complete the text.
|
74 |
+
To enhance the long-context ability, we exclude data shorter than 2K word. The inclusion of UL2 Oscar Data is effective in compelling the model to read and utilize long-range context.
|
75 |
+
- We then fine-tune the model to focus on its few shot capacity under long context, including 20% Natural Instructions (NI), 20% Public Pool of Prompts (P3), 20% the Pile. We decontaminated all data against HELM core scenarios . We teach the model to leverage the in-context examples by packing examples into one 32K-token sequence. To maintain the knowledge learned from the first piece of data, we incorporate 20% RedPajama-Data Book and 20% RedPajama-Data ArXiv.
|
76 |
+
|
77 |
+
Next, we provide examples of how to fine-tune the model for specific applications.
|
78 |
+
The example datasets are placed in [togethercomputer/Long-Data-Collections](https://huggingface.co/datasets/togethercomputer/Long-Data-Collections)
|
79 |
+
You can use the [OpenChatKit](https://github.com/togethercomputer/OpenChatKit) to fine-tune your own 32K model over LLaMA-2-7B-32K.
|
80 |
+
Please refer to [OpenChatKit](https://github.com/togethercomputer/OpenChatKit) for step-by-step illustrations.
|
81 |
+
|
82 |
+
1. Long Context QA.
|
83 |
+
|
84 |
+
We take as an example the multi-document question answering task from the paper “Lost in the Middle: How Language Models Use Long Contexts”. The input for the model consists of (i) a question that requires an answer and (ii) k documents, which are passages extracted from Wikipedia. Notably, only one of these documents contains the answer to the question, while the remaining k − 1 documents, termed as "distractor" documents, do not. To successfully perform this task, the model must identify and utilize the document containing the answer from its input context.
|
85 |
+
|
86 |
+
With OCK, simply run the following command to fine-tune:
|
87 |
+
```
|
88 |
+
bash training/finetune_llama-2-7b-32k-mqa.sh
|
89 |
+
```
|
90 |
+
|
91 |
+
2. Summarization.
|
92 |
+
|
93 |
+
Another example is BookSum, a unique dataset designed to address the challenges of long-form narrative summarization. This dataset features source documents from the literature domain, including novels, plays, and stories, and offers human-written, highly abstractive summaries. We here focus on chapter-level data. BookSum poses a unique set of challenges, necessitating that the model comprehensively read through each chapter.
|
94 |
+
|
95 |
+
With OCK, simply run the following command to fine-tune:
|
96 |
+
```
|
97 |
+
bash training/finetune_llama-2-7b-32k-booksum.sh
|
98 |
+
```
|
99 |
+
|
100 |
+
|
101 |
+
## Inference
|
102 |
+
|
103 |
+
You can use the [Together API](https://together.ai/blog/api-announcement) to try out LLaMA-2-7B-32K for inference.
|
104 |
+
The updated inference stack allows for efficient inference.
|
105 |
+
|
106 |
+
To run the model locally, we strongly recommend to install Flash Attention V2, which is necessary to obtain the best performance:
|
107 |
+
```
|
108 |
+
# Please update the path of `CUDA_HOME`
|
109 |
+
export CUDA_HOME=/usr/local/cuda-11.8
|
110 |
+
pip install transformers==4.31.0
|
111 |
+
pip install sentencepiece
|
112 |
+
pip install ninja
|
113 |
+
pip install flash-attn --no-build-isolation
|
114 |
+
pip install git+https://github.com/HazyResearch/flash-attention.git#subdirectory=csrc/rotary
|
115 |
+
```
|
116 |
+
|
117 |
+
You can use this model directly from the Hugging Face Model Hub or fine-tune it on your own data using the OpenChatKit.
|
118 |
+
|
119 |
+
```python
|
120 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
121 |
+
|
122 |
+
tokenizer = AutoTokenizer.from_pretrained("togethercomputer/LLaMA-2-7B-32K")
|
123 |
+
model = AutoModelForCausalLM.from_pretrained("togethercomputer/LLaMA-2-7B-32K", trust_remote_code=True, torch_dtype=torch.float16)
|
124 |
+
|
125 |
+
input_context = "Your text here"
|
126 |
+
input_ids = tokenizer.encode(input_context, return_tensors="pt")
|
127 |
+
output = model.generate(input_ids, max_length=128, temperature=0.7)
|
128 |
+
output_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
129 |
+
print(output_text)
|
130 |
+
```
|
131 |
+
|
132 |
+
Alternatively, you can set `trust_remote_code=False` if you prefer not to use flash attention.
|
133 |
+
|
134 |
+
|
135 |
+
## Limitations and Bias
|
136 |
+
|
137 |
+
As with all language models, LLaMA-2-7B-32K may generate incorrect or biased content. It's important to keep this in mind when using the model.
|
138 |
+
|
139 |
+
## Community
|
140 |
+
|
141 |
+
Join us on [Together Discord](https://discord.gg/6ZVDU8tTD4)
|