Commit
·
6015b31
0
Parent(s):
Initial commit
Browse files- .gitattributes +35 -0
- README.md +117 -0
- added_tokens.json +3 -0
- config.json +191 -0
- configuration_hymba.py +116 -0
- generation_config.json +8 -0
- images/macro_arch.png +0 -0
- images/module.png +0 -0
- images/performance1.png +0 -0
- images/performance2.png +0 -0
- modeling_hymba.py +0 -0
- setup.sh +44 -0
- special_tokens_map.json +30 -0
- tokenizer.json +0 -0
- tokenizer.model +3 -0
- tokenizer_config.json +52 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: other
|
3 |
+
license_name: nvidia-open-model-license
|
4 |
+
license_link: https://developer.download.nvidia.com/licenses/nvidia-open-model-license-agreement-june-2024.pdf
|
5 |
+
---
|
6 |
+
|
7 |
+
# Hymba-1.5B-Base
|
8 |
+
|
9 |
+
## Model Overview
|
10 |
+
|
11 |
+
Hymba-1.5B-Base is a base text-to-text model that can be adopted for a variety of natural language generation tasks.
|
12 |
+
|
13 |
+
The model has hybrid architecture with Mamba and Attention heads running in parallel. Meta tokens, a set of learnable tokens prepended to every prompt, help improve the efficacy of the model. The model shares KV cache between 2 layers and between heads in a single layer. 90% of attention layers are sliding window attention.
|
14 |
+
|
15 |
+
This model is ready for commercial use.
|
16 |
+
|
17 |
+
**[Model Weights Coming Soon]**
|
18 |
+
|
19 |
+
**[Caution] During generation, the batch size needs to be 1. Our current implementation does not fully support padding of Meta tokens + SWA; this is a work in progress. Training and pre-filling support any batch size.**
|
20 |
+
|
21 |
+
|
22 |
+
**Model Developer:** NVIDIA
|
23 |
+
|
24 |
+
**Model Dates:** Hymba-1.5B-Base was trained between September 1, 2024 and November 10th, 2024.
|
25 |
+
|
26 |
+
**License:**
|
27 |
+
This model is released under the [NVIDIA Open Model License Agreement](https://developer.download.nvidia.com/licenses/nvidia-open-model-license-agreement-june-2024.pdf).
|
28 |
+
|
29 |
+
|
30 |
+
## Model Architecture
|
31 |
+
|
32 |
+
Hymba-1.5B-Base has a model embedding size of 1600, 25 attention heads, and an MLP intermediate dimension of 5504, with 32 layers in total, 16 SSM states, 3 full attention layers, the rest are sliding window attention. Unlike the standard Transformer, each attention layer in Hymba has a hybrid combination of standard attention heads and Mamba heads in parallel. Additionally, it uses Grouped-Query Attention (GQA) and Rotary Position Embeddings (RoPE).
|
33 |
+
|
34 |
+
Features of this architecture:
|
35 |
+
|
36 |
+
- Fuse attention heads and SSM heads within the same layer, offering parallel and complementary processing of the same inputs.
|
37 |
+
|
38 |
+
<div align="center">
|
39 |
+
<img src="https://huggingface.co/nvidia/Hymba-1.5B-Base/resolve/main/images/module.png" alt="Hymba Module" width="600">
|
40 |
+
</div>
|
41 |
+
|
42 |
+
- Introduce meta tokens that are prepended to the input sequences and interact with all subsequent tokens, thus storing important information and alleviating the burden of "forced-to-attend" in attention.
|
43 |
+
|
44 |
+
- Integrate with cross-layer KV sharing and global-local attention to further boost memory and computation efficiency.
|
45 |
+
|
46 |
+
<div align="center">
|
47 |
+
<img src="https://huggingface.co/nvidia/Hymba-1.5B-Base/resolve/main/images/macro_arch.png" alt="Hymba Model" width="600">
|
48 |
+
</div>
|
49 |
+
|
50 |
+
|
51 |
+
## Performance Highlights
|
52 |
+
- Hymba-1.5B-Base outperforms all sub-2B public models.
|
53 |
+
|
54 |
+
<div align="center">
|
55 |
+
<img src="https://huggingface.co/nvidia/Hymba-1.5B-Base/resolve/main/images/performance1.png" alt="Compare with SoTA Small LMs" width="800">
|
56 |
+
</div>
|
57 |
+
|
58 |
+
<div align="center">
|
59 |
+
<img src="https://huggingface.co/nvidia/Hymba-1.5B-Base/resolve/main/images/performance2.png" alt="Compare with SoTA Small LMs" width="800">
|
60 |
+
</div>
|
61 |
+
|
62 |
+
|
63 |
+
## Model Usage
|
64 |
+
|
65 |
+
|
66 |
+
### Step 1: Environment Setup
|
67 |
+
|
68 |
+
Since Hymba-1.5B-Instruct employs [FlexAttention](https://pytorch.org/blog/flexattention/), which relies on Pytorch2.5 and other related dependencies, please use the provided `setup.sh` (support CUDA 12.1/12.4) to install the related packages:
|
69 |
+
|
70 |
+
```
|
71 |
+
wget --header="Authorization: Bearer YOUR_HF_TOKEN" https://huggingface.co/nvidia/Hymba-1.5B-Base/resolve/main/setup.sh
|
72 |
+
bash setup.sh
|
73 |
+
```
|
74 |
+
|
75 |
+
|
76 |
+
### Step 2: Chat with Hymba-1.5B-Base
|
77 |
+
After setting up the environment, you can use the following script to chat with our Model
|
78 |
+
|
79 |
+
```
|
80 |
+
from transformers import LlamaTokenizer, AutoModelForCausalLM, AutoTokenizer, AutoModel
|
81 |
+
import torch
|
82 |
+
|
83 |
+
# Load the tokenizer and model
|
84 |
+
repo_name = "nvidia/Hymba-1.5B-Base"
|
85 |
+
|
86 |
+
tokenizer = AutoTokenizer.from_pretrained(repo_name, trust_remote_code=True)
|
87 |
+
model = AutoModelForCausalLM.from_pretrained(repo_name, trust_remote_code=True)
|
88 |
+
model = model.cuda().to(torch.bfloat16)
|
89 |
+
|
90 |
+
# Chat with Hymba
|
91 |
+
prompt = input()
|
92 |
+
inputs = tokenizer(prompt, return_tensors="pt").to('cuda')
|
93 |
+
outputs = model.generate(**inputs, max_length=64, do_sample=True, temperature=0.7, use_cache=True)
|
94 |
+
response = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True)
|
95 |
+
|
96 |
+
print(f"Model response: {response}")
|
97 |
+
|
98 |
+
```
|
99 |
+
|
100 |
+
## Limitations
|
101 |
+
The model was trained on data that contains toxic language, unsafe content, and societal biases originally crawled from the internet. Therefore, the model may amplify those biases and return toxic responses especially when prompted with toxic prompts. The model may generate answers that may be inaccurate, omit key information, or include irrelevant or redundant text producing socially unacceptable or undesirable text, even if the prompt itself does not include anything explicitly offensive.
|
102 |
+
|
103 |
+
## Ethical Considerations
|
104 |
+
NVIDIA believes Trustworthy AI is a shared responsibility and we have established policies and practices to enable development for a wide array of AI applications. When downloaded or used in accordance with our terms of service, developers should work with their internal model team to ensure this model meets requirements for the relevant industry and use case and addresses unforeseen product misuse.
|
105 |
+
Please report security vulnerabilities or NVIDIA AI Concerns [here](https://www.nvidia.com/en-us/support/submit-security-vulnerability/).
|
106 |
+
|
107 |
+
|
108 |
+
## Citation
|
109 |
+
```
|
110 |
+
@article{hymba2024,
|
111 |
+
title={A Hybrid-head Architecture for Small Language Models},
|
112 |
+
author={Xin Dong and Yonggan Fu and Shizhe Diao and Wonmin Byeon and Zijia Chen and Ameya Sunil Mahabaleshwarkar and Shih-Yang Liu and Matthijs Van Keirsbilck and Min-Hung Chen and Yoshi Suhara and Yingyan Celine Lin and Jan Kautz and Pavlo Molchanov},
|
113 |
+
journal={arXiv preprint arXiv:xxxx},
|
114 |
+
year={2024},
|
115 |
+
url={https://arxiv.org/abs/xxxx},
|
116 |
+
}
|
117 |
+
```
|
added_tokens.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"[PAD]": 32000
|
3 |
+
}
|
config.json
ADDED
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"HymbaForCausalLM"
|
4 |
+
],
|
5 |
+
"attention_dropout": 0.0,
|
6 |
+
"attn_hidden_size": -1,
|
7 |
+
"attn_implementation": "flex",
|
8 |
+
"attn_implementation_new": "flex",
|
9 |
+
"auto_map": {
|
10 |
+
"AutoConfig": "configuration_hymba.HymbaConfig",
|
11 |
+
"AutoModelForCausalLM": "modeling_hymba.HymbaForCausalLM"
|
12 |
+
},
|
13 |
+
"bos_token_id": 1,
|
14 |
+
"calc_logits_for_entire_prompt": false,
|
15 |
+
"conv_dim": {
|
16 |
+
"0": 3200,
|
17 |
+
"1": 3200,
|
18 |
+
"2": 3200,
|
19 |
+
"3": 3200,
|
20 |
+
"4": 3200,
|
21 |
+
"5": 3200,
|
22 |
+
"6": 3200,
|
23 |
+
"7": 3200,
|
24 |
+
"8": 3200,
|
25 |
+
"9": 3200,
|
26 |
+
"10": 3200,
|
27 |
+
"11": 3200,
|
28 |
+
"12": 3200,
|
29 |
+
"13": 3200,
|
30 |
+
"14": 3200,
|
31 |
+
"15": 3200,
|
32 |
+
"16": 3200,
|
33 |
+
"17": 3200,
|
34 |
+
"18": 3200,
|
35 |
+
"19": 3200,
|
36 |
+
"20": 3200,
|
37 |
+
"21": 3200,
|
38 |
+
"22": 3200,
|
39 |
+
"23": 3200,
|
40 |
+
"24": 3200,
|
41 |
+
"25": 3200,
|
42 |
+
"26": 3200,
|
43 |
+
"27": 3200,
|
44 |
+
"28": 3200,
|
45 |
+
"29": 3200,
|
46 |
+
"30": 3200,
|
47 |
+
"31": 3200
|
48 |
+
},
|
49 |
+
"eos_token_id": 2,
|
50 |
+
"global_attn_idx": [
|
51 |
+
0,
|
52 |
+
15,
|
53 |
+
31
|
54 |
+
],
|
55 |
+
"hidden_act": "silu",
|
56 |
+
"hidden_size": 1600,
|
57 |
+
"initializer_range": 0.02,
|
58 |
+
"intermediate_size": 5504,
|
59 |
+
"kq_head_dim": -1,
|
60 |
+
"kq_norm": "none",
|
61 |
+
"kv_reuse_every_i_layer": -1,
|
62 |
+
"kv_reuse_group": [
|
63 |
+
[
|
64 |
+
1,
|
65 |
+
2
|
66 |
+
],
|
67 |
+
[
|
68 |
+
3,
|
69 |
+
4
|
70 |
+
],
|
71 |
+
[
|
72 |
+
5,
|
73 |
+
6
|
74 |
+
],
|
75 |
+
[
|
76 |
+
7,
|
77 |
+
8
|
78 |
+
],
|
79 |
+
[
|
80 |
+
9,
|
81 |
+
10
|
82 |
+
],
|
83 |
+
[
|
84 |
+
11,
|
85 |
+
12
|
86 |
+
],
|
87 |
+
[
|
88 |
+
13,
|
89 |
+
14
|
90 |
+
],
|
91 |
+
[
|
92 |
+
16,
|
93 |
+
17,
|
94 |
+
18
|
95 |
+
],
|
96 |
+
[
|
97 |
+
19,
|
98 |
+
20
|
99 |
+
],
|
100 |
+
[
|
101 |
+
21,
|
102 |
+
22
|
103 |
+
],
|
104 |
+
[
|
105 |
+
23,
|
106 |
+
24
|
107 |
+
],
|
108 |
+
[
|
109 |
+
25,
|
110 |
+
26
|
111 |
+
],
|
112 |
+
[
|
113 |
+
27,
|
114 |
+
28
|
115 |
+
],
|
116 |
+
[
|
117 |
+
29,
|
118 |
+
30
|
119 |
+
]
|
120 |
+
],
|
121 |
+
"kv_weight_reuse": false,
|
122 |
+
"layer_type": [
|
123 |
+
"h",
|
124 |
+
"h",
|
125 |
+
"h",
|
126 |
+
"h",
|
127 |
+
"h",
|
128 |
+
"h",
|
129 |
+
"h",
|
130 |
+
"h",
|
131 |
+
"h",
|
132 |
+
"h",
|
133 |
+
"h",
|
134 |
+
"h",
|
135 |
+
"h",
|
136 |
+
"h",
|
137 |
+
"h",
|
138 |
+
"h",
|
139 |
+
"h",
|
140 |
+
"h",
|
141 |
+
"h",
|
142 |
+
"h",
|
143 |
+
"h",
|
144 |
+
"h",
|
145 |
+
"h",
|
146 |
+
"h",
|
147 |
+
"h",
|
148 |
+
"h",
|
149 |
+
"h",
|
150 |
+
"h",
|
151 |
+
"h",
|
152 |
+
"h",
|
153 |
+
"h",
|
154 |
+
"h"
|
155 |
+
],
|
156 |
+
"mamba_conv_bias": true,
|
157 |
+
"mamba_d_conv": 4,
|
158 |
+
"mamba_d_state": 16,
|
159 |
+
"mamba_dt_rank": 100,
|
160 |
+
"mamba_expand": 2,
|
161 |
+
"mamba_inner_layernorms": true,
|
162 |
+
"mamba_proj_bias": false,
|
163 |
+
"max_position_embeddings": 8192,
|
164 |
+
"memory_tokens_interspersed_every": 0,
|
165 |
+
"mlp_hidden_act": "silu",
|
166 |
+
"model_type": "hymba",
|
167 |
+
"num_attention_heads": 25,
|
168 |
+
"num_experts": 1,
|
169 |
+
"num_experts_per_tok": 1,
|
170 |
+
"num_hidden_layers": 32,
|
171 |
+
"num_key_value_heads": 5,
|
172 |
+
"num_mamba": 1,
|
173 |
+
"num_memory_tokens": 128,
|
174 |
+
"orig_max_position_embeddings": 2048,
|
175 |
+
"output_router_logits": false,
|
176 |
+
"pad_token_id": 0,
|
177 |
+
"rms_norm_eps": 1e-06,
|
178 |
+
"rope": true,
|
179 |
+
"rope_theta": 10000.0,
|
180 |
+
"rope_type": "ntk",
|
181 |
+
"router_aux_loss_coef": 0.001,
|
182 |
+
"seq_length": 8192,
|
183 |
+
"sliding_window": 1024,
|
184 |
+
"tie_word_embeddings": true,
|
185 |
+
"torch_dtype": "bfloat16",
|
186 |
+
"transformers_version": "4.44.0",
|
187 |
+
"use_cache": false,
|
188 |
+
"use_mamba_kernels": true,
|
189 |
+
"v_head_dim": 128,
|
190 |
+
"vocab_size": 32001
|
191 |
+
}
|
configuration_hymba.py
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
from transformers.configuration_utils import PretrainedConfig
|
3 |
+
|
4 |
+
|
5 |
+
class HymbaConfig(PretrainedConfig):
|
6 |
+
|
7 |
+
model_type = "hymba"
|
8 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
9 |
+
|
10 |
+
def __init__(
|
11 |
+
self,
|
12 |
+
vocab_size=65536,
|
13 |
+
tie_word_embeddings=False,
|
14 |
+
hidden_size=4096,
|
15 |
+
intermediate_size=14336,
|
16 |
+
num_hidden_layers=32,
|
17 |
+
num_attention_heads=32,
|
18 |
+
num_key_value_heads=8,
|
19 |
+
hidden_act="silu",
|
20 |
+
initializer_range=0.02,
|
21 |
+
rms_norm_eps=1e-6,
|
22 |
+
use_cache=True,
|
23 |
+
calc_logits_for_entire_prompt=False,
|
24 |
+
output_router_logits=False,
|
25 |
+
router_aux_loss_coef=0.001,
|
26 |
+
pad_token_id=0,
|
27 |
+
bos_token_id=1,
|
28 |
+
eos_token_id=2,
|
29 |
+
sliding_window=None,
|
30 |
+
max_position_embeddings=262144,
|
31 |
+
orig_max_position_embeddings=None,
|
32 |
+
attention_dropout=0.0,
|
33 |
+
num_experts_per_tok=2,
|
34 |
+
num_experts=16,
|
35 |
+
use_mamba_kernels=True,
|
36 |
+
mamba_d_state=16,
|
37 |
+
mamba_d_conv=4,
|
38 |
+
mamba_expand=2,
|
39 |
+
mamba_dt_rank="auto",
|
40 |
+
mamba_conv_bias=True,
|
41 |
+
mamba_proj_bias=False,
|
42 |
+
mamba_inner_layernorms=True,
|
43 |
+
kv_reuse_every_i_layer=-1,
|
44 |
+
kv_reuse_group=None,
|
45 |
+
kv_weight_reuse=False,
|
46 |
+
global_attn_idx=None,
|
47 |
+
num_mamba=1,
|
48 |
+
attn_implementation_new='sdpa',
|
49 |
+
rope_type=None,
|
50 |
+
**kwargs,
|
51 |
+
):
|
52 |
+
self.vocab_size = vocab_size
|
53 |
+
self.tie_word_embeddings = tie_word_embeddings
|
54 |
+
self.hidden_size = hidden_size
|
55 |
+
self.intermediate_size = intermediate_size
|
56 |
+
self.num_hidden_layers = num_hidden_layers
|
57 |
+
self.num_attention_heads = num_attention_heads
|
58 |
+
self.sliding_window = sliding_window
|
59 |
+
self.max_position_embeddings = max_position_embeddings
|
60 |
+
self.orig_max_position_embeddings = orig_max_position_embeddings
|
61 |
+
self.attention_dropout = attention_dropout
|
62 |
+
|
63 |
+
if num_key_value_heads is None:
|
64 |
+
num_key_value_heads = num_attention_heads
|
65 |
+
|
66 |
+
self.num_key_value_heads = num_key_value_heads
|
67 |
+
self.hidden_act = hidden_act
|
68 |
+
self.initializer_range = initializer_range
|
69 |
+
self.rms_norm_eps = rms_norm_eps
|
70 |
+
|
71 |
+
self.use_cache = use_cache
|
72 |
+
self.calc_logits_for_entire_prompt = calc_logits_for_entire_prompt
|
73 |
+
self.output_router_logits = output_router_logits
|
74 |
+
self.router_aux_loss_coef = router_aux_loss_coef
|
75 |
+
|
76 |
+
self.num_experts_per_tok = num_experts_per_tok
|
77 |
+
self.num_experts = num_experts
|
78 |
+
|
79 |
+
self.use_mamba_kernels = use_mamba_kernels
|
80 |
+
self.mamba_d_state = mamba_d_state
|
81 |
+
self.mamba_d_conv = mamba_d_conv
|
82 |
+
self.mamba_expand = mamba_expand
|
83 |
+
self.mamba_dt_rank = math.ceil(self.hidden_size / 16) if mamba_dt_rank == "auto" else mamba_dt_rank
|
84 |
+
self.mamba_conv_bias = mamba_conv_bias
|
85 |
+
self.mamba_proj_bias = mamba_proj_bias
|
86 |
+
self.mamba_inner_layernorms = mamba_inner_layernorms
|
87 |
+
|
88 |
+
self.attn_hidden_size = kwargs.pop("attn_hidden_size", -1)
|
89 |
+
self.kq_head_dim = kwargs.pop("kq_head_dim", -1)
|
90 |
+
self.v_head_dim = kwargs.pop("v_head_dim", -1)
|
91 |
+
self.kq_norm = kwargs.pop("kq_norm", None)
|
92 |
+
self.rope = kwargs.pop("rope", False)
|
93 |
+
self.rope_theta = kwargs.pop("rope_theta", 10000.0)
|
94 |
+
self.num_memory_tokens = kwargs.pop("num_memory_tokens", 0)
|
95 |
+
self.memory_tokens_interspersed_every = kwargs.pop("memory_tokens_interspersed_every", 0)
|
96 |
+
|
97 |
+
self.kv_reuse_every_i_layer = kv_reuse_every_i_layer
|
98 |
+
self.kv_reuse_group = kv_reuse_group
|
99 |
+
self.kv_weight_reuse = kv_weight_reuse
|
100 |
+
|
101 |
+
self.global_attn_idx = global_attn_idx
|
102 |
+
|
103 |
+
self.num_mamba = num_mamba
|
104 |
+
|
105 |
+
self.attn_implementation_new = attn_implementation_new
|
106 |
+
|
107 |
+
self.rope_type = rope_type
|
108 |
+
|
109 |
+
|
110 |
+
super().__init__(
|
111 |
+
pad_token_id=pad_token_id,
|
112 |
+
bos_token_id=bos_token_id,
|
113 |
+
eos_token_id=eos_token_id,
|
114 |
+
tie_word_embeddings=tie_word_embeddings,
|
115 |
+
**kwargs,
|
116 |
+
)
|
generation_config.json
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"bos_token_id": 1,
|
4 |
+
"eos_token_id": 2,
|
5 |
+
"pad_token_id": 0,
|
6 |
+
"transformers_version": "4.44.0",
|
7 |
+
"use_cache": false
|
8 |
+
}
|
images/macro_arch.png
ADDED
![]() |
images/module.png
ADDED
![]() |
images/performance1.png
ADDED
![]() |
images/performance2.png
ADDED
![]() |
modeling_hymba.py
ADDED
The diff for this file is too large to render.
See raw diff
|
|
setup.sh
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# Prompt user to specify CUDA version
|
4 |
+
read -p "Enter CUDA version (12.1 or 12.4): " cuda_version
|
5 |
+
|
6 |
+
# Verify CUDA version input
|
7 |
+
if [[ "$cuda_version" != "12.1" && "$cuda_version" != "12.4" ]]; then
|
8 |
+
echo "Invalid CUDA version specified. Please choose either 12.1 or 12.4."
|
9 |
+
exit 1
|
10 |
+
fi
|
11 |
+
|
12 |
+
# Install PyTorch with the specified CUDA version
|
13 |
+
conda install pytorch==2.5.0 torchvision==0.20.0 torchaudio==2.5.0 pytorch-cuda=$cuda_version -c pytorch -c nvidia
|
14 |
+
|
15 |
+
# Install other packages
|
16 |
+
pip install --upgrade transformers
|
17 |
+
pip install tiktoken
|
18 |
+
pip install sentencepiece
|
19 |
+
pip install protobuf
|
20 |
+
pip install ninja einops triton packaging
|
21 |
+
|
22 |
+
# Clone and install Mamba
|
23 |
+
git clone https://github.com/state-spaces/mamba.git
|
24 |
+
cd mamba
|
25 |
+
pip install -e .
|
26 |
+
cd ..
|
27 |
+
|
28 |
+
# Clone and install causal-conv1d with specified CUDA version
|
29 |
+
git clone https://github.com/Dao-AILab/causal-conv1d.git
|
30 |
+
cd causal-conv1d
|
31 |
+
export CUDA_HOME=/usr/local/cuda-$cuda_version
|
32 |
+
TORCH_CUDA_ARCH_LIST="7.0;7.5;8.0;8.6;8.9;9.0" python setup.py install
|
33 |
+
cd ..
|
34 |
+
|
35 |
+
# Clone and install attention-gym
|
36 |
+
git clone https://github.com/pytorch-labs/attention-gym.git
|
37 |
+
cd attention-gym
|
38 |
+
pip install .
|
39 |
+
cd ..
|
40 |
+
|
41 |
+
# Install Flash Attention
|
42 |
+
pip install flash_attn
|
43 |
+
|
44 |
+
echo "Installation completed with CUDA $cuda_version."
|
special_tokens_map.json
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": {
|
3 |
+
"content": "<s>",
|
4 |
+
"lstrip": false,
|
5 |
+
"normalized": false,
|
6 |
+
"rstrip": false,
|
7 |
+
"single_word": false
|
8 |
+
},
|
9 |
+
"eos_token": {
|
10 |
+
"content": "</s>",
|
11 |
+
"lstrip": false,
|
12 |
+
"normalized": false,
|
13 |
+
"rstrip": false,
|
14 |
+
"single_word": false
|
15 |
+
},
|
16 |
+
"pad_token": {
|
17 |
+
"content": "[PAD]",
|
18 |
+
"lstrip": false,
|
19 |
+
"normalized": false,
|
20 |
+
"rstrip": false,
|
21 |
+
"single_word": false
|
22 |
+
},
|
23 |
+
"unk_token": {
|
24 |
+
"content": "<unk>",
|
25 |
+
"lstrip": false,
|
26 |
+
"normalized": false,
|
27 |
+
"rstrip": false,
|
28 |
+
"single_word": false
|
29 |
+
}
|
30 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer.model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347
|
3 |
+
size 499723
|
tokenizer_config.json
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_bos_token": true,
|
3 |
+
"add_eos_token": false,
|
4 |
+
"add_prefix_space": true,
|
5 |
+
"added_tokens_decoder": {
|
6 |
+
"0": {
|
7 |
+
"content": "<unk>",
|
8 |
+
"lstrip": false,
|
9 |
+
"normalized": false,
|
10 |
+
"rstrip": false,
|
11 |
+
"single_word": false,
|
12 |
+
"special": true
|
13 |
+
},
|
14 |
+
"1": {
|
15 |
+
"content": "<s>",
|
16 |
+
"lstrip": false,
|
17 |
+
"normalized": false,
|
18 |
+
"rstrip": false,
|
19 |
+
"single_word": false,
|
20 |
+
"special": true
|
21 |
+
},
|
22 |
+
"2": {
|
23 |
+
"content": "</s>",
|
24 |
+
"lstrip": false,
|
25 |
+
"normalized": false,
|
26 |
+
"rstrip": false,
|
27 |
+
"single_word": false,
|
28 |
+
"special": true
|
29 |
+
},
|
30 |
+
"32000": {
|
31 |
+
"content": "[PAD]",
|
32 |
+
"lstrip": false,
|
33 |
+
"normalized": false,
|
34 |
+
"rstrip": false,
|
35 |
+
"single_word": false,
|
36 |
+
"special": true
|
37 |
+
}
|
38 |
+
},
|
39 |
+
"bos_token": "<s>",
|
40 |
+
"chat_template": "{{'<extra_id_0>System'}}{% for message in messages %}{% if message['role'] == 'system' %}{{'\n' + message['content'].strip()}}{% if tools or contexts %}{{'\n'}}{% endif %}{% endif %}{% endfor %}{% if tools %}{% for tool in tools %}{{ '\n<tool> ' + tool|tojson + ' </tool>' }}{% endfor %}{% endif %}{% if contexts %}{% if tools %}{{'\n'}}{% endif %}{% for context in contexts %}{{ '\n<context> ' + context.strip() + ' </context>' }}{% endfor %}{% endif %}{{'\n\n'}}{% for message in messages %}{% if message['role'] == 'user' %}{{ '<extra_id_1>User\n' + message['content'].strip() + '\n' }}{% elif message['role'] == 'assistant' %}{{ '<extra_id_1>Assistant\n' + message['content'].strip() + '\n' }}{% elif message['role'] == 'tool' %}{{ '<extra_id_1>Tool\n' + message['content'].strip() + '\n' }}{% endif %}{% endfor %}{%- if add_generation_prompt %}{{'<extra_id_1>Assistant\n'}}{%- endif %}",
|
41 |
+
"clean_up_tokenization_spaces": false,
|
42 |
+
"eos_token": "</s>",
|
43 |
+
"legacy": true,
|
44 |
+
"model_max_length": 1000000000000000019884624838656,
|
45 |
+
"pad_token": "[PAD]",
|
46 |
+
"padding_side": "left",
|
47 |
+
"sp_model_kwargs": {},
|
48 |
+
"spaces_between_special_tokens": false,
|
49 |
+
"tokenizer_class": "LlamaTokenizer",
|
50 |
+
"unk_token": "<unk>",
|
51 |
+
"use_default_system_prompt": false
|
52 |
+
}
|