sharpenb commited on
Commit
d313d75
·
verified ·
1 Parent(s): 87daad6

Upload folder using huggingface_hub (#1)

Browse files

- 23cb32daec9d6d01097f7325924348731fdf524d693c0c840e02d6b3ebde2e75 (34f91893d5fd38be3b778c2a8abaf980596292b0)

Files changed (5) hide show
  1. LMConfig.py +58 -0
  2. README.md +89 -0
  3. config.json +186 -0
  4. qmodel.pt +3 -0
  5. smash_config.json +34 -0
LMConfig.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig
2
+ from typing import List
3
+
4
+
5
+ class LMConfig(PretrainedConfig):
6
+ model_type = "minimind"
7
+
8
+ def __init__(
9
+ self,
10
+ dim: int = 512,
11
+ n_layers: int = 8,
12
+ n_heads: int = 16,
13
+ n_kv_heads: int = 8,
14
+ vocab_size: int = 6400,
15
+ hidden_dim: int = None,
16
+ multiple_of: int = 64,
17
+ norm_eps: float = 1e-5,
18
+ max_seq_len: int = 512,
19
+ dropout: float = 0.0,
20
+ flash_attn: bool = True,
21
+ ####################################################
22
+ # Here are the specific configurations of MOE
23
+ # When use_moe is false, the following is invalid
24
+ ####################################################
25
+ use_moe: bool = False,
26
+ num_experts_per_tok=2,
27
+ n_routed_experts=4,
28
+ n_shared_experts: bool = True,
29
+ scoring_func='softmax',
30
+ aux_loss_alpha=0.01,
31
+ seq_aux=True,
32
+ norm_topk_prob=True,
33
+ **kwargs,
34
+ ):
35
+ self.dim = dim
36
+ self.n_layers = n_layers
37
+ self.n_heads = n_heads
38
+ self.n_kv_heads = n_kv_heads
39
+ self.vocab_size = vocab_size
40
+ self.hidden_dim = hidden_dim
41
+ self.multiple_of = multiple_of
42
+ self.norm_eps = norm_eps
43
+ self.max_seq_len = max_seq_len
44
+ self.dropout = dropout
45
+ self.flash_attn = flash_attn
46
+ ####################################################
47
+ # Here are the specific configurations of MOE
48
+ # When use_moe is false, the following is invalid
49
+ ####################################################
50
+ self.use_moe = use_moe
51
+ self.num_experts_per_tok = num_experts_per_tok # 每个token选择的专家数量
52
+ self.n_routed_experts = n_routed_experts # 总的专家数量
53
+ self.n_shared_experts = n_shared_experts # 共享专家
54
+ self.scoring_func = scoring_func # 评分函数,默认为'softmax'
55
+ self.aux_loss_alpha = aux_loss_alpha # 辅助损失的alpha参数
56
+ self.seq_aux = seq_aux # 是否在序列级别上计算辅助损失
57
+ self.norm_topk_prob = norm_topk_prob # 是否标准化top-k概率
58
+ super().__init__(**kwargs)
README.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ thumbnail: "https://assets-global.website-files.com/646b351987a8d8ce158d1940/64ec9e96b4334c0e1ac41504_Logo%20with%20white%20text.svg"
3
+ base_model: ORIGINAL_REPO_NAME
4
+ metrics:
5
+ - memory_disk
6
+ - memory_inference
7
+ - inference_latency
8
+ - inference_throughput
9
+ - inference_CO2_emissions
10
+ - inference_energy_consumption
11
+ tags:
12
+ - pruna-ai
13
+ ---
14
+ <!-- header start -->
15
+ <!-- 200823 -->
16
+ <div style="width: auto; margin-left: auto; margin-right: auto">
17
+ <a href="https://www.pruna.ai/" target="_blank" rel="noopener noreferrer">
18
+ <img src="https://i.imgur.com/eDAlcgk.png" alt="PrunaAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
19
+ </a>
20
+ </div>
21
+ <!-- header end -->
22
+
23
+ [![Twitter](https://img.shields.io/twitter/follow/PrunaAI?style=social)](https://twitter.com/PrunaAI)
24
+ [![GitHub](https://img.shields.io/github/followers/PrunaAI?label=Follow%20%40PrunaAI&style=social)](https://github.com/PrunaAI)
25
+ [![LinkedIn](https://img.shields.io/badge/LinkedIn-Connect-blue)](https://www.linkedin.com/company/93832878/admin/feed/posts/?feedType=following)
26
+ [![Discord](https://img.shields.io/badge/Discord-Join%20Us-blue?style=social&logo=discord)](https://discord.gg/rskEr4BZJx)
27
+
28
+ # Simply make AI models cheaper, smaller, faster, and greener!
29
+
30
+ - Give a thumbs up if you like this model!
31
+ - Contact us and tell us which model to compress next [here](https://www.pruna.ai/contact).
32
+ - Request access to easily compress your *own* AI models [here](https://z0halsaff74.typeform.com/pruna-access?typeform-source=www.pruna.ai).
33
+ - Read the documentations to know more [here](https://pruna-ai-pruna.readthedocs-hosted.com/en/latest/)
34
+ - Join Pruna AI community on Discord [here](https://discord.gg/CP4VSgck) to share feedback/suggestions or get help.
35
+
36
+ ## Results
37
+
38
+ ![image info](./plots.png)
39
+
40
+ **Frequently Asked Questions**
41
+ - ***How does the compression work?*** The model is compressed with hqq.
42
+ - ***How does the model quality change?*** The quality of the model output might vary compared to the base model.
43
+ - ***How is the model efficiency evaluated?*** These results were obtained with configuration described in `model/smash_config.json` and are obtained after a hardware warmup. The smashed model is directly compared to the original base model. Efficiency results may vary in other settings (e.g. other hardware, image size, batch size, ...). We recommend to directly run them in the use-case conditions to know if the smashed model can benefit you.
44
+ - ***What is the model format?*** We use safetensors.
45
+ - ***What calibration data has been used?*** If needed by the compression method, we used WikiText as the calibration data.
46
+ - ***What is the naming convention for Pruna Huggingface models?*** We take the original model name and append "turbo", "tiny", or "green" if the smashed model has a measured inference speed, inference memory, or inference energy consumption which is less than 90% of the original base model.
47
+ - ***How to compress my own models?*** You can request premium access to more compression methods and tech support for your specific use-cases [here](https://z0halsaff74.typeform.com/pruna-access?typeform-source=www.pruna.ai).
48
+ - ***What are "first" metrics?*** Results mentioning "first" are obtained after the first run of the model. The first run might take more memory or be slower than the subsequent runs due cuda overheads.
49
+ - ***What are "Sync" and "Async" metrics?*** "Sync" metrics are obtained by syncing all GPU processes and stop measurement when all of them are executed. "Async" metrics are obtained without syncing all GPU processes and stop when the model output can be used by the CPU. We provide both metrics since both could be relevant depending on the use-case. We recommend to test the efficiency gains directly in your use-cases.
50
+
51
+ ## Setup
52
+
53
+ You can run the smashed model with these steps:
54
+
55
+ 0. Check requirements from the original repo ORIGINAL_REPO_NAME installed. In particular, check python, cuda, and transformers versions.
56
+ 1. Make sure that you have installed quantization related packages.
57
+ ```bash
58
+ pip install hqq
59
+ ```
60
+ 2. Load & run the model.
61
+ ```python
62
+ from transformers import AutoModelForCausalLM, AutoTokenizer
63
+ from hqq.engine.hf import HQQModelForCausalLM
64
+ from hqq.models.hf.base import AutoHQQHFModel
65
+
66
+ try:
67
+ model = HQQModelForCausalLM.from_quantized("PrunaAI/tclh123-minimind-v1-small-HQQ-8bit-smashed", device_map='auto')
68
+ except:
69
+ model = AutoHQQHFModel.from_quantized("PrunaAI/tclh123-minimind-v1-small-HQQ-8bit-smashed")
70
+ tokenizer = AutoTokenizer.from_pretrained("ORIGINAL_REPO_NAME")
71
+
72
+ input_ids = tokenizer("What is the color of prunes?,", return_tensors='pt').to(model.device)["input_ids"]
73
+
74
+ outputs = model.generate(input_ids, max_new_tokens=216)
75
+ tokenizer.decode(outputs[0])
76
+ ```
77
+
78
+ ## Configurations
79
+
80
+ The configuration info are in `smash_config.json`.
81
+
82
+ ## Credits & License
83
+
84
+ The license of the smashed model follows the license of the original model. Please check the license of the original model ORIGINAL_REPO_NAME before using this model which provided the base model. The license of the `pruna-engine` is [here](https://pypi.org/project/pruna-engine/) on Pypi.
85
+
86
+ ## Want to compress other models?
87
+
88
+ - Contact us and tell us which model to compress next [here](https://www.pruna.ai/contact).
89
+ - Request access to easily compress your own AI models [here](https://z0halsaff74.typeform.com/pruna-access?typeform-source=www.pruna.ai).
config.json ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/tmp/models/tmpyhad2wc0/tmpf1vx39wn",
3
+ "architectures": [
4
+ "Transformer"
5
+ ],
6
+ "auto_map": {
7
+ "AutoConfig": "LMConfig.LMConfig",
8
+ "AutoModelForCausalLM": "tclh123/minimind-v1-small--model.Transformer"
9
+ },
10
+ "aux_loss_alpha": 0.01,
11
+ "dim": 512,
12
+ "dropout": 0.0,
13
+ "flash_attn": true,
14
+ "hidden_dim": null,
15
+ "max_seq_len": 512,
16
+ "model_type": "minimind",
17
+ "multiple_of": 64,
18
+ "n_heads": 16,
19
+ "n_kv_heads": 8,
20
+ "n_layers": 8,
21
+ "n_routed_experts": 4,
22
+ "n_shared_experts": true,
23
+ "norm_eps": 1e-05,
24
+ "norm_topk_prob": true,
25
+ "num_experts_per_tok": 2,
26
+ "quantization_config": {
27
+ "attention.wk": {
28
+ "offload_meta": false,
29
+ "scale_quant_params": null,
30
+ "weight_quant_params": {
31
+ "axis": 0,
32
+ "channel_wise": true,
33
+ "group_size": 64,
34
+ "nbits": 8,
35
+ "optimize": true,
36
+ "round_zero": false,
37
+ "view_as_float": false
38
+ },
39
+ "zero_quant_params": {
40
+ "channel_wise": false,
41
+ "group_size": null,
42
+ "nbits": 8,
43
+ "optimize": false
44
+ }
45
+ },
46
+ "attention.wo": {
47
+ "offload_meta": false,
48
+ "scale_quant_params": null,
49
+ "weight_quant_params": {
50
+ "axis": 0,
51
+ "channel_wise": true,
52
+ "group_size": 64,
53
+ "nbits": 8,
54
+ "optimize": true,
55
+ "round_zero": false,
56
+ "view_as_float": false
57
+ },
58
+ "zero_quant_params": {
59
+ "channel_wise": false,
60
+ "group_size": null,
61
+ "nbits": 8,
62
+ "optimize": false
63
+ }
64
+ },
65
+ "attention.wq": {
66
+ "offload_meta": false,
67
+ "scale_quant_params": null,
68
+ "weight_quant_params": {
69
+ "axis": 0,
70
+ "channel_wise": true,
71
+ "group_size": 64,
72
+ "nbits": 8,
73
+ "optimize": true,
74
+ "round_zero": false,
75
+ "view_as_float": false
76
+ },
77
+ "zero_quant_params": {
78
+ "channel_wise": false,
79
+ "group_size": null,
80
+ "nbits": 8,
81
+ "optimize": false
82
+ }
83
+ },
84
+ "attention.wv": {
85
+ "offload_meta": false,
86
+ "scale_quant_params": null,
87
+ "weight_quant_params": {
88
+ "axis": 0,
89
+ "channel_wise": true,
90
+ "group_size": 64,
91
+ "nbits": 8,
92
+ "optimize": true,
93
+ "round_zero": false,
94
+ "view_as_float": false
95
+ },
96
+ "zero_quant_params": {
97
+ "channel_wise": false,
98
+ "group_size": null,
99
+ "nbits": 8,
100
+ "optimize": false
101
+ }
102
+ },
103
+ "feed_forward.w1": {
104
+ "offload_meta": false,
105
+ "scale_quant_params": null,
106
+ "weight_quant_params": {
107
+ "axis": 0,
108
+ "channel_wise": true,
109
+ "group_size": 64,
110
+ "nbits": 8,
111
+ "optimize": true,
112
+ "round_zero": false,
113
+ "view_as_float": false
114
+ },
115
+ "zero_quant_params": {
116
+ "channel_wise": false,
117
+ "group_size": null,
118
+ "nbits": 8,
119
+ "optimize": false
120
+ }
121
+ },
122
+ "feed_forward.w2": {
123
+ "offload_meta": false,
124
+ "scale_quant_params": null,
125
+ "weight_quant_params": {
126
+ "axis": 0,
127
+ "channel_wise": true,
128
+ "group_size": 64,
129
+ "nbits": 8,
130
+ "optimize": true,
131
+ "round_zero": false,
132
+ "view_as_float": false
133
+ },
134
+ "zero_quant_params": {
135
+ "channel_wise": false,
136
+ "group_size": null,
137
+ "nbits": 8,
138
+ "optimize": false
139
+ }
140
+ },
141
+ "feed_forward.w3": {
142
+ "offload_meta": false,
143
+ "scale_quant_params": null,
144
+ "weight_quant_params": {
145
+ "axis": 0,
146
+ "channel_wise": true,
147
+ "group_size": 64,
148
+ "nbits": 8,
149
+ "optimize": true,
150
+ "round_zero": false,
151
+ "view_as_float": false
152
+ },
153
+ "zero_quant_params": {
154
+ "channel_wise": false,
155
+ "group_size": null,
156
+ "nbits": 8,
157
+ "optimize": false
158
+ }
159
+ },
160
+ "output": {
161
+ "offload_meta": false,
162
+ "scale_quant_params": null,
163
+ "weight_quant_params": {
164
+ "axis": 0,
165
+ "channel_wise": true,
166
+ "group_size": 64,
167
+ "nbits": 8,
168
+ "optimize": true,
169
+ "round_zero": false,
170
+ "view_as_float": false
171
+ },
172
+ "zero_quant_params": {
173
+ "channel_wise": false,
174
+ "group_size": null,
175
+ "nbits": 8,
176
+ "optimize": false
177
+ }
178
+ }
179
+ },
180
+ "scoring_func": "softmax",
181
+ "seq_aux": true,
182
+ "torch_dtype": "float32",
183
+ "transformers_version": "4.44.0",
184
+ "use_moe": false,
185
+ "vocab_size": 6400
186
+ }
qmodel.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6eb710ef4813b09bb61a8be582dc3676af3a2f6899935c21d31b907541f2775d
3
+ size 43424119
smash_config.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "comp_cgenerate_active": false,
3
+ "comp_ctranslate_active": false,
4
+ "comp_cwhisper_active": false,
5
+ "comp_diffusers2_active": false,
6
+ "comp_flux_caching_active": false,
7
+ "comp_ifw_active": false,
8
+ "comp_onediff_active": false,
9
+ "comp_step_caching_active": false,
10
+ "comp_torch_compile_active": false,
11
+ "comp_ws2t_active": false,
12
+ "comp_x-fast_active": false,
13
+ "prune_torch-structured_active": false,
14
+ "prune_torch-unstructured_active": false,
15
+ "quant_aqlm_active": false,
16
+ "quant_awq_active": false,
17
+ "quant_gptq_active": false,
18
+ "quant_half_active": false,
19
+ "quant_hqq_active": true,
20
+ "quant_llm-int8_active": false,
21
+ "quant_quanto_active": false,
22
+ "quant_torch_dynamic_active": false,
23
+ "quant_torch_static_active": false,
24
+ "quant_hqq_backend": "torchao_int4",
25
+ "quant_hqq_group_size": 64,
26
+ "quant_hqq_weight_bits": 8,
27
+ "max_batch_size": 1,
28
+ "device": "cuda",
29
+ "cache_dir": "/tmp/models/tmpyhad2wc0",
30
+ "task": "",
31
+ "save_load_fn": "hqq",
32
+ "save_load_fn_args": {},
33
+ "api_key": null
34
+ }