Safetensors
transformers_zamba2
zamba2
BerenMillidge commited on
Commit
24947ee
1 Parent(s): 575312f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +95 -3
README.md CHANGED
@@ -1,3 +1,95 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+
5
+ # Model Card for Zamba2-1.2B
6
+
7
+ Zamba2-1.2B is a hybrid model composed of state-space and transformer blocks. It broadly follows the [Zamba architecture](https://arxiv.org/abs/2405.16712) which consists of a Mamba backbone alternating with shared transformer blocks (see diagram in [Model Details](#model-details)). Zamba2-1.2B possesses three major improvements over Zamba1:
8
+
9
+ 1.) Mamba1 blocks have been replaced with Mamba2 blocks.
10
+
11
+ 2.) We apply a LoRA projector to each shared MLP and Attention block, which allows the network to specialize at each invocation of the shared transformer layer across depth. LoRA enables us to add depth-specialization for only a minimal increase in total parameter count.
12
+
13
+ 3.) We utilize rotary position embeddings in the shared attention layer.
14
+
15
+ Zamba2-1.2B differs from our [2.7B model](https://huggingface.co/Zyphra/Zamba2-2.7B) in two ways:
16
+
17
+ 1.) Rotary position embeddings
18
+
19
+ 2.) No alternating shared attention blocks
20
+
21
+ We found that while hybrid SSM-transformer models are perfectly capable of performing well without position embeddings, adding rotary embeddings to the shared attention block slightly improved performance. Secondly, we utilize a single attention block instead of alternating because this enables a higher flop count for the model at a given parameter budget and at smaller scales this becomes more important than the slightly faster latency.
22
+
23
+ Zamba2-1.2B uses the Mistral v0.1 tokenizer and was pre-trained on 3T tokens of text and code data sourced from open web-datasets, including [Zyda](https://arxiv.org/abs/2406.01981). Subsequently, in a second phase, Zamba2-1.2B was annealed on a mixture of 100B high-quality tokens.
24
+
25
+ Note: this is a temporary HuggingFace implementation of Zamba2-1.2B. It may not yet be fully compatible with all frameworks and tools intended to interface with HuggingFace models.
26
+
27
+ A standalone Pytorch implementation of Zamba2-1.2B may be found [here](https://github.com/Zyphra/Zamba2).
28
+
29
+ ## Quick start
30
+
31
+ ### Prerequisites
32
+
33
+ To download Zamba2-1.2B, clone Zyphra's fork of transformers:
34
+ 1. `git clone https://github.com/Zyphra/transformers_zamba2.git`
35
+ 2. `cd transformers_zamba2`
36
+ 3. Install the repository: `pip install -e .`
37
+ 4. `pip install accelerate`
38
+
39
+
40
+ You can run the model without using the optimized Mamba kernels, but it is **not** recommended as it will result in significantly higher latency and memory usage.
41
+
42
+ To run on CPU, please specify `use_mamba_kernels=False` when loading the model using ``AutoModelForCausalLM.from_pretrained``.
43
+
44
+
45
+ ### Inference
46
+
47
+ ```python
48
+ from transformers import AutoTokenizer, AutoModelForCausalLM
49
+ import torch
50
+
51
+ tokenizer = AutoTokenizer.from_pretrained("Zyphra/Zamba2-1.2B")
52
+ model = AutoModelForCausalLM.from_pretrained("Zyphra/Zamba2-1.2B", device_map="cuda", torch_dtype=torch.bfloat16)
53
+
54
+ input_text = "A funny prompt would be "
55
+ input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
56
+
57
+ outputs = model.generate(**input_ids, max_new_tokens=100)
58
+ print(tokenizer.decode(outputs[0]))
59
+ ```
60
+
61
+ ## Model Details
62
+
63
+ Zamba2-1.2B utilizes and extends our original Zamba hybrid SSM-attention architecture. The core Zamba architecture consists of a backbone of Mamba 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 transformer blocks 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.
64
+
65
+ <center>
66
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/65c05e75c084467acab2f84a/XrEIEBxd0fqIgh3LyArAV.png" width="300" alt="Zamba architecture">
67
+ </center>
68
+
69
+
70
+ ## Performance
71
+
72
+ Zamba2-1.2B achieves leading and state-of-the-art performance among models of <3B parameters and is competitive with some models of significantly greater size. Moreover, due to its unique hybrid SSM architecture, Zamba2-1.2B achieves extremely low inference latency and rapid generation with a significantly smaller memory footprint than comparable transformer based models.
73
+
74
+ Zamba2-1.2B's high performance and small inference compute and memory footprint renders it an ideal generalist model for on-device applications.
75
+
76
+ <center>
77
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/65c05e75c084467acab2f84a/U7VD9PYLj3XcEjgV08sP5.png" width="700" alt="Zamba performance">
78
+ </center>
79
+
80
+ <center>
81
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/65bc13717c6ad1994b6619e9/3u8k7tcRi-oC_ltGhdHAk.png" width="800" alt="Zamba performance">
82
+ </center>
83
+
84
+ Time to First Token (TTFT) | Output Generation
85
+ :-------------------------:|:-------------------------:
86
+ ![](https://cdn-uploads.huggingface.co/production/uploads/65bc13717c6ad1994b6619e9/BmE8X6tDNVw5OJcbZt8sZ.png) | ![](https://cdn-uploads.huggingface.co/production/uploads/65bc13717c6ad1994b6619e9/wECc9cItK1FW1MOMGSLrp.png)
87
+
88
+
89
+ <center>
90
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/65bc13717c6ad1994b6619e9/nhoss41xlzfEBZzcQXI6z.png" width="700" alt="Zamba inference and memory cost">
91
+ </center>
92
+
93
+ ## Notice
94
+
95
+ Zamba2-1.2B is a pretrained base model and therefore does not have any moderation mechanism and may output toxic or otherwise harmful language. In addition, one should not expect good instruct or chat performance, as this model was not fine-tuned for instruction following or chat.