juewang commited on
Commit
30e8cff
1 Parent(s): 0a90abc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +88 -8
README.md CHANGED
@@ -9,28 +9,108 @@ language:
9
  library_name: transformers
10
  ---
11
 
12
- # Llama-2-7B-32KCtx
13
 
 
14
 
15
- # Install Flash Attention For Inference with 32K
 
 
 
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  ```
18
  export CUDA_HOME=/usr/local/cuda-11.8
19
  pip install ninja
20
  pip install flash-attn --no-build-isolation
21
  pip install git+https://github.com/HazyResearch/flash-attention.git#subdirectory=csrc/rotary
22
  ```
23
- Please revise the path of `CUDA_HOME`. `ninja` is needed to accelerate the process of compiling.
24
 
25
- And then:
26
- ```python
27
- model = AutoModelForCausalLM.from_pretrained('togethercomputer/Llama-2-7B-32KCtx-v0.1', trust_remote_code=True, torch_dtype=torch.float16)
28
- ```
29
 
30
  You can also use vanilla `transformers` to load this model:
31
  ```python
32
  model = AutoModelForCausalLM.from_pretrained('togethercomputer/Llama-2-7B-32KCtx-v0.1', torch_dtype=torch.float16)
33
  ```
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
- TODO
 
9
  library_name: transformers
10
  ---
11
 
12
+ # Llama-2-7B-32K-beta
13
 
14
+ ## Model Description
15
 
16
+ Llama-2-7B-32K-beta is an open-source, long context language model developed by Together, fine-tuned from Meta's original Llama-2 7B model.
17
+ This model represents our efforts to contribute to the rapid progress of the open-source ecosystem for large language models.
18
+ The model has been extended to a context length of 32K with position interpolation,
19
+ allowing applications on multi-document QA, long text summarization, etc.
20
 
21
+ ## What's new?
22
+
23
+ This model introduces several improvements and new features:
24
+
25
+ 1. **Extended Context:** The model has been trained to handle context lengths up to 32K, which is a significant improvement over the previous versions.
26
+
27
+ 2. **Pre-training and Instruction Tuning:** We have shared our data recipe, which consists of a mixture of pre-training and instruction tuning data.
28
+
29
+ 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.
30
+
31
+ 4. **Software Support:** We have updated both the inference and training stack to allow efficient inference and fine-tuning for 32K context.
32
+
33
+ ## Model Architecture
34
+
35
+ 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.
36
+
37
+ ## Training and Fine-tuning
38
+
39
+ The model has been trained using a mixture of pre-training and instruction tuning data.
40
+ - 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.
41
+ 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.
42
+ - 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 (see a precise protocol here). 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 with abstracts.
43
+
44
+
45
+ We provide examples of how to fine-tune the model for specific applications.
46
+ You can use the [OpenChatKit](https://github.com/togethercomputer/OpenChatKit) to fine-tune your own 32K model over Llama-2-7B-32K-beta.
47
+ Please refer to [OpenChatKit](https://github.com/togethercomputer/OpenChatKit) for step-by-step illustrations.
48
+
49
+ 1. Long Context QA.
50
+
51
+ 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.
52
+
53
+ With OCK, simply run the following command to fine-tune:
54
+ ```
55
+ bash training/finetune_llama-2-7b-32k-mqa.sh
56
+ ```
57
+
58
+ 2. Summarization.
59
+
60
+ 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.
61
+
62
+ With OCK, simply run the following command to fine-tune:
63
+ ```
64
+ bash training/finetune_llama-2-7b-32k-booksum.sh
65
+ ```
66
+
67
+
68
+ ## Inference
69
+
70
+ You can use the Together API to try out Llama-2-7B-32K-beta for inference.
71
+ The updated inference stack allows for efficient and speedy inference.
72
+
73
+ To use the model and benefit from the 32K context length, we strongly recommend to install Flash Attention V2:
74
  ```
75
  export CUDA_HOME=/usr/local/cuda-11.8
76
  pip install ninja
77
  pip install flash-attn --no-build-isolation
78
  pip install git+https://github.com/HazyResearch/flash-attention.git#subdirectory=csrc/rotary
79
  ```
80
+ (Please revise the path of `CUDA_HOME`. `ninja` is needed to accelerate the process of compiling.)
81
 
 
 
 
 
82
 
83
  You can also use vanilla `transformers` to load this model:
84
  ```python
85
  model = AutoModelForCausalLM.from_pretrained('togethercomputer/Llama-2-7B-32KCtx-v0.1', torch_dtype=torch.float16)
86
  ```
87
 
88
+ You can use this model directly from the Hugging Face Model Hub or fine-tune it on your own data using the OpenChatKit.
89
+
90
+ ```python
91
+ from transformers import AutoTokenizer, AutoModelForCausalLM
92
+
93
+ tokenizer = AutoTokenizer.from_pretrained("togethercomputer/Llama-2-7B-32K-beta")
94
+ model = AutoModelForCausalLM.from_pretrained("togethercomputer/Llama-2-7B-32K-beta", trust_remote_code=True, torch_dtype=torch.float16)
95
+
96
+ input_context = "Your text here"
97
+ input_ids = tokenizer.encode(input_context, return_tensors="pt")
98
+ output = model.generate(input_ids, max_length=128, temperature=0.7)
99
+ output_text = tokenizer.decode(output[0], skip_special_tokens=True)
100
+ print(output_text)
101
+ ```
102
+
103
+ You can set `trust_remote_code=False` if you prefer not to use flash attention.
104
+
105
+
106
+ ## Limitations and Bias
107
+
108
+ As with all language models, Llama-2-7B-32K-beta may generate incorrect or biased content. It's important to keep this in mind when using the model.
109
+
110
+ ## Try it out!
111
+
112
+ Feel free to try out the Llama-2-7B-32K-beta model on the Hugging Face Model Hub or via the Together API. We're excited to see what you'll build with it!
113
+
114
+ ## License
115
 
116
+ This model is released under the Apache 2.0 license.