BerenMillidge
commited on
Commit
•
75c575f
1
Parent(s):
ddba6ad
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,103 @@
|
|
1 |
-
---
|
2 |
-
license: apache-2.0
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
base_model:
|
4 |
+
- Zyphra/Zamba2-2.7B
|
5 |
+
library_name: transformers
|
6 |
+
---
|
7 |
+
# Model Card for Zamba2-7B-Instruct
|
8 |
+
|
9 |
+
Zamba2-7B-Instruct is obtained from [Zamba2-7B](https://huggingface.co/Zyphra/Zamba2-7B) by fine-tuning on instruction-following and chat datasets.
|
10 |
+
|
11 |
+
Zamba2-7B-Instruct is a hybrid model composed of state-space ([Mamba2](https://github.com/state-spaces/mamba)) and transformer blocks.
|
12 |
+
|
13 |
+
Zamba2-7B-Instruct long-context has been extended from 4k to 16k context by adjusting the rope frequency in the attention blocks.
|
14 |
+
|
15 |
+
## Quick start
|
16 |
+
|
17 |
+
### Prerequisites
|
18 |
+
|
19 |
+
To download Zamba2-2.7B-instruct, clone Zyphra's fork of transformers:
|
20 |
+
1. `git clone https://github.com/Zyphra/transformers_zamba2.git`
|
21 |
+
2. `cd transformers_zamba2`
|
22 |
+
3. Install the repository: `pip install -e .`
|
23 |
+
4. `pip install accelerate`
|
24 |
+
|
25 |
+
|
26 |
+
### Inference
|
27 |
+
|
28 |
+
```python
|
29 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
30 |
+
import torch
|
31 |
+
|
32 |
+
# Instantiate model and tokenizer
|
33 |
+
tokenizer = AutoTokenizer.from_pretrained("Zyphra/Zamba2-2.7B-instruct")
|
34 |
+
model = AutoModelForCausalLM.from_pretrained("Zyphra/Zamba2-2.7B-instruct", device_map="cuda", torch_dtype=torch.bfloat16)
|
35 |
+
|
36 |
+
# Format the input as a chat template
|
37 |
+
user_turn_1 = "In one season a flower blooms three times. In one year, there is one blooming season. How many times do two flowers bloom in two years? Please include your logic."
|
38 |
+
assistant_turn_1 = "In one season, a flower blooms three times. In one year, there is one blooming season. Therefore, in two years, there are two blooming seasons. Since each flower blooms three times in one season, in two blooming seasons, each flower will bloom six times. Since there are two flowers, the total number of times they will bloom in two years is 12."
|
39 |
+
user_turn_2 = "How many times do the two flowers blossom in three years?"
|
40 |
+
sample = [{'role': 'user', 'content': user_turn_1}, {'role': 'assistant', 'content': assistant_turn_1}, {'role': 'user', 'content': user_turn_2}]
|
41 |
+
chat_sample = tokenizer.apply_chat_template(sample, tokenize=False)
|
42 |
+
|
43 |
+
# Tokenize input and generate output
|
44 |
+
input_ids = tokenizer(chat_sample, return_tensors='pt', add_special_tokens=False).to("cuda")
|
45 |
+
outputs = model.generate(**input_ids, max_new_tokens=150, return_dict_in_generate=False, output_scores=False, use_cache=True, num_beams=1, do_sample=False)
|
46 |
+
print((tokenizer.decode(outputs[0])))
|
47 |
+
```
|
48 |
+
|
49 |
+
To use the context-extended version of Zamba, please load the model with `use_long_context=True`, i.e.:
|
50 |
+
|
51 |
+
```
|
52 |
+
model = AutoModelForCausalLM.from_pretrained("Zyphra/Zamba2-7B", device_map="cuda", torch_dtype=torch.bfloat16, use_long_context=True)
|
53 |
+
```
|
54 |
+
|
55 |
+
## Performance
|
56 |
+
|
57 |
+
Zamba2-7B-Instruct punches dramatically above its weight, achieving extremely strong instruction-following benchmark scores.
|
58 |
+
|
59 |
+
TODO
|
60 |
+
|
61 |
+
|
62 |
+
Moreover, due to its unique hybrid SSM architecture, Zamba2-7B-Instruct achieves extremely low inference latency and rapid generation with a significantly smaller memory footprint than comparable transformer-based models.
|
63 |
+
|
64 |
+
<center>
|
65 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/65bc13717c6ad1994b6619e9/WKTcYkhDgJCHyze4TDpLa.png" width="700" alt="Zamba performance">
|
66 |
+
</center>
|
67 |
+
|
68 |
+
|
69 |
+
Time to First Token (TTFT) | Output Generation
|
70 |
+
:-------------------------:|:-------------------------:
|
71 |
+
![](https://cdn-uploads.huggingface.co/production/uploads/65bc13717c6ad1994b6619e9/BmE8X6tDNVw5OJcbZt8sZ.png) | ![](https://cdn-uploads.huggingface.co/production/uploads/65bc13717c6ad1994b6619e9/wECc9cItK1FW1MOMGSLrp.png)
|
72 |
+
|
73 |
+
|
74 |
+
<center>
|
75 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/65bc13717c6ad1994b6619e9/nhoss41xlzfEBZzcQXI6z.png" width="700" alt="Zamba inference and memory cost">
|
76 |
+
</center>
|
77 |
+
|
78 |
+
Zamba2-7B-Instruct's high performance, strong instruction-following and reasoning capabilities for its size makes it an ideal generalist small model for a wide range of applications.
|
79 |
+
|
80 |
+
## Model Details
|
81 |
+
|
82 |
+
Zamba2-7B-Instruct utilizes and extends our original Zamba hybrid SSM-attention architecture. The core Zamba architecture consists of a backbone of Mamba2 layers interleaved with one or more shared attention layers (one shared attention in Zamba1, two in Zamba2). This attention has shared weights to minimize the parameter cost of the model. We find that concatenating the original model embeddings to the input to this attention block improves performance, likely due to better maintenance of information across depth. The Zamba2 architecture also applies LoRA projection matrices to the shared MLP to gain some additional expressivity in each block and allow each shared block to specialize slightly to its own unique position while keeping the additional parameter overhead small.
|
83 |
+
|
84 |
+
<center>
|
85 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/65c05e75c084467acab2f84a/XrEIEBxd0fqIgh3LyArAV.png" width="300" alt="Zamba architecture">
|
86 |
+
</center>
|
87 |
+
|
88 |
+
## Long Context
|
89 |
+
|
90 |
+
Our Zamba2-7B instruct features an experimental long-context mode which extends the context from 4k to 16k context. This was achieved by adjusting the rotation frequency of the rotary position embeddings.
|
91 |
+
|
92 |
+
In Needle-In-A-Haystack tests, we can observe that Zamba2-7B-Instruct can find the needle with an extremely high success rate up to and slightly beyond 16k context with performance falling off sharply at about 18k context. In future versions we aim to extend this context length significantly.
|
93 |
+
|
94 |
+
![image/png]()
|
95 |
+
|
96 |
+
<center>
|
97 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/65c05e75c084467acab2f84a/uP1sbXqF1mZAp1R6NYdCF.png" width="300" alt="Zamba long context performance">
|
98 |
+
</center>
|
99 |
+
|
100 |
+
|
101 |
+
Note: this is a temporary HuggingFace implementation of Zamba2-7B. It may not yet be fully compatible with all frameworks and tools intended to interface with HuggingFace models.
|
102 |
+
|
103 |
+
A standalone Pytorch implementation of Zamba2-7B may be found [here](https://github.com/Zyphra/Zamba2).
|