d341b3cfb8d0468fcaaf37fd47d5fc115be7cae4b5a3e2678e7dabd2005eb41a
Browse files- README.md +89 -0
- config.json +57 -0
- configuration_mobilellm.py +79 -0
- qmodel.pt +3 -0
- smash_config.json +19 -0
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 |
+
[](https://twitter.com/PrunaAI)
|
24 |
+
[](https://github.com/PrunaAI)
|
25 |
+
[](https://www.linkedin.com/company/93832878/admin/feed/posts/?feedType=following)
|
26 |
+
[](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 |
+

|
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/facebook-MobileLLM-125M-HQQ-4bit-smashed", device_map='auto')
|
68 |
+
except:
|
69 |
+
model = AutoHQQHFModel.from_quantized("PrunaAI/facebook-MobileLLM-125M-HQQ-4bit-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,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_attn_implementation_autoset": true,
|
3 |
+
"_name_or_path": "/tmp/models/tmpxsktr9vt/tmpwpc4x_42",
|
4 |
+
"architectures": [
|
5 |
+
"MobileLLMForCausalLM"
|
6 |
+
],
|
7 |
+
"attention_bias": false,
|
8 |
+
"attention_dropout": 0.0,
|
9 |
+
"auto_map": {
|
10 |
+
"AutoConfig": "configuration_mobilellm.MobileLLMConfig",
|
11 |
+
"AutoModelForCausalLM": "facebook/MobileLLM-125M--modeling_mobilellm.MobileLLMForCausalLM"
|
12 |
+
},
|
13 |
+
"bos_token_id": 1,
|
14 |
+
"eos_token_id": 2,
|
15 |
+
"head_dim": 64,
|
16 |
+
"hidden_act": "silu",
|
17 |
+
"hidden_size": 576,
|
18 |
+
"initializer_range": 0.02,
|
19 |
+
"intermediate_size": 1536,
|
20 |
+
"layer_sharing": false,
|
21 |
+
"max_position_embeddings": 2048,
|
22 |
+
"mlp_bias": false,
|
23 |
+
"model_type": "mobilellm",
|
24 |
+
"num_attention_heads": 9,
|
25 |
+
"num_hidden_layers": 30,
|
26 |
+
"num_key_value_heads": 3,
|
27 |
+
"pretraining_tp": 1,
|
28 |
+
"quantization_config": {
|
29 |
+
"quant_config": {
|
30 |
+
"offload_meta": false,
|
31 |
+
"scale_quant_params": null,
|
32 |
+
"weight_quant_params": {
|
33 |
+
"axis": 1,
|
34 |
+
"channel_wise": true,
|
35 |
+
"group_size": 64,
|
36 |
+
"nbits": 4,
|
37 |
+
"optimize": true,
|
38 |
+
"round_zero": true,
|
39 |
+
"view_as_float": false
|
40 |
+
},
|
41 |
+
"zero_quant_params": null
|
42 |
+
},
|
43 |
+
"quant_method": "hqq",
|
44 |
+
"skip_modules": [
|
45 |
+
"lm_head"
|
46 |
+
]
|
47 |
+
},
|
48 |
+
"rms_norm_eps": 1e-05,
|
49 |
+
"rope_scaling": null,
|
50 |
+
"rope_theta": 10000.0,
|
51 |
+
"share_embedding": true,
|
52 |
+
"tie_word_embeddings": false,
|
53 |
+
"torch_dtype": "float16",
|
54 |
+
"transformers_version": "4.48.2",
|
55 |
+
"use_cache": true,
|
56 |
+
"vocab_size": 32000
|
57 |
+
}
|
configuration_mobilellm.py
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
2 |
+
# All rights reserved.
|
3 |
+
#
|
4 |
+
# This source code is licensed under the license found in the
|
5 |
+
# LICENSE file in the root directory of this source tree.
|
6 |
+
|
7 |
+
from transformers.configuration_utils import PretrainedConfig
|
8 |
+
|
9 |
+
|
10 |
+
class MobileLLMConfig(PretrainedConfig):
|
11 |
+
|
12 |
+
model_type = "mobilellm"
|
13 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
14 |
+
|
15 |
+
def __init__(
|
16 |
+
self,
|
17 |
+
vocab_size=32000,
|
18 |
+
hidden_size=4096,
|
19 |
+
intermediate_size=11008,
|
20 |
+
num_hidden_layers=32,
|
21 |
+
num_attention_heads=32,
|
22 |
+
num_key_value_heads=None,
|
23 |
+
hidden_act="silu",
|
24 |
+
max_position_embeddings=2048,
|
25 |
+
initializer_range=0.02,
|
26 |
+
rms_norm_eps=1e-6,
|
27 |
+
use_cache=True,
|
28 |
+
pad_token_id=None,
|
29 |
+
bos_token_id=1,
|
30 |
+
eos_token_id=2,
|
31 |
+
pretraining_tp=1,
|
32 |
+
tie_word_embeddings=False,
|
33 |
+
rope_theta=10000.0,
|
34 |
+
rope_scaling=None,
|
35 |
+
attention_bias=False,
|
36 |
+
attention_dropout=0.0,
|
37 |
+
mlp_bias=False,
|
38 |
+
head_dim=None,
|
39 |
+
share_embedding=True,
|
40 |
+
layer_sharing=False,
|
41 |
+
**kwargs,
|
42 |
+
):
|
43 |
+
self.vocab_size = vocab_size
|
44 |
+
self.max_position_embeddings = max_position_embeddings
|
45 |
+
self.hidden_size = hidden_size
|
46 |
+
self.intermediate_size = intermediate_size
|
47 |
+
self.num_hidden_layers = num_hidden_layers
|
48 |
+
self.num_attention_heads = num_attention_heads
|
49 |
+
|
50 |
+
# for backward compatibility
|
51 |
+
if num_key_value_heads is None:
|
52 |
+
num_key_value_heads = num_attention_heads
|
53 |
+
|
54 |
+
self.num_key_value_heads = num_key_value_heads
|
55 |
+
self.hidden_act = hidden_act
|
56 |
+
self.initializer_range = initializer_range
|
57 |
+
self.rms_norm_eps = rms_norm_eps
|
58 |
+
self.pretraining_tp = pretraining_tp
|
59 |
+
self.use_cache = use_cache
|
60 |
+
self.rope_theta = rope_theta
|
61 |
+
self.rope_scaling = rope_scaling
|
62 |
+
self.attention_bias = attention_bias
|
63 |
+
self.attention_dropout = attention_dropout
|
64 |
+
self.mlp_bias = mlp_bias
|
65 |
+
self.head_dim = head_dim if head_dim is not None else self.hidden_size // self.num_attention_heads
|
66 |
+
self.share_embedding = share_embedding
|
67 |
+
self.layer_sharing = layer_sharing
|
68 |
+
# Validate the correctness of rotary position embeddings parameters
|
69 |
+
# BC: if there is a 'type' field, copy it it to 'rope_type'.
|
70 |
+
if self.rope_scaling is not None and "type" in self.rope_scaling:
|
71 |
+
self.rope_scaling["rope_type"] = self.rope_scaling["type"]
|
72 |
+
|
73 |
+
super().__init__(
|
74 |
+
pad_token_id=pad_token_id,
|
75 |
+
bos_token_id=bos_token_id,
|
76 |
+
eos_token_id=eos_token_id,
|
77 |
+
tie_word_embeddings=tie_word_embeddings,
|
78 |
+
**kwargs,
|
79 |
+
)
|
qmodel.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8016e61a2c39f8e20bea6afe0cd77ecd476798ca93272bb8ac4d6f176d218907
|
3 |
+
size 140437970
|
smash_config.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"batchers": null,
|
3 |
+
"cachers": null,
|
4 |
+
"compilers": null,
|
5 |
+
"distillers": null,
|
6 |
+
"pruners": null,
|
7 |
+
"quantizers": "hqq",
|
8 |
+
"recoverers": null,
|
9 |
+
"quant_hqq_backend": "torchao_int4",
|
10 |
+
"quant_hqq_group_size": 64,
|
11 |
+
"quant_hqq_weight_bits": 4,
|
12 |
+
"max_batch_size": 1,
|
13 |
+
"device": "cuda",
|
14 |
+
"cache_dir": "/tmp/models/tmpxsktr9vt",
|
15 |
+
"task": "",
|
16 |
+
"save_load_fn": "hqq",
|
17 |
+
"save_load_fn_args": {},
|
18 |
+
"api_key": null
|
19 |
+
}
|