Update README.md
Browse files
README.md
CHANGED
@@ -1,199 +1,79 @@
|
|
1 |
---
|
2 |
-
|
3 |
-
|
|
|
|
|
4 |
---
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
-
|
21 |
-
|
22 |
-
|
23 |
-
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
### Training Data
|
79 |
-
|
80 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
81 |
-
|
82 |
-
[More Information Needed]
|
83 |
-
|
84 |
-
### Training Procedure
|
85 |
-
|
86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
87 |
-
|
88 |
-
#### Preprocessing [optional]
|
89 |
-
|
90 |
-
[More Information Needed]
|
91 |
-
|
92 |
-
|
93 |
-
#### Training Hyperparameters
|
94 |
-
|
95 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
96 |
-
|
97 |
-
#### Speeds, Sizes, Times [optional]
|
98 |
-
|
99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
100 |
-
|
101 |
-
[More Information Needed]
|
102 |
-
|
103 |
-
## Evaluation
|
104 |
-
|
105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
106 |
-
|
107 |
-
### Testing Data, Factors & Metrics
|
108 |
-
|
109 |
-
#### Testing Data
|
110 |
-
|
111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
112 |
-
|
113 |
-
[More Information Needed]
|
114 |
-
|
115 |
-
#### Factors
|
116 |
-
|
117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
-
|
119 |
-
[More Information Needed]
|
120 |
-
|
121 |
-
#### Metrics
|
122 |
-
|
123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
-
|
125 |
-
[More Information Needed]
|
126 |
-
|
127 |
-
### Results
|
128 |
-
|
129 |
-
[More Information Needed]
|
130 |
-
|
131 |
-
#### Summary
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
-
|
139 |
-
[More Information Needed]
|
140 |
-
|
141 |
-
## Environmental Impact
|
142 |
-
|
143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
-
|
145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
-
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
-
|
153 |
-
## Technical Specifications [optional]
|
154 |
-
|
155 |
-
### Model Architecture and Objective
|
156 |
-
|
157 |
-
[More Information Needed]
|
158 |
-
|
159 |
-
### Compute Infrastructure
|
160 |
-
|
161 |
-
[More Information Needed]
|
162 |
-
|
163 |
-
#### Hardware
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
-
## Citation [optional]
|
172 |
-
|
173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
-
|
175 |
-
**BibTeX:**
|
176 |
-
|
177 |
-
[More Information Needed]
|
178 |
-
|
179 |
-
**APA:**
|
180 |
-
|
181 |
-
[More Information Needed]
|
182 |
-
|
183 |
-
## Glossary [optional]
|
184 |
-
|
185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
-
|
187 |
-
[More Information Needed]
|
188 |
-
|
189 |
-
## More Information [optional]
|
190 |
-
|
191 |
-
[More Information Needed]
|
192 |
-
|
193 |
-
## Model Card Authors [optional]
|
194 |
-
|
195 |
-
[More Information Needed]
|
196 |
-
|
197 |
-
## Model Card Contact
|
198 |
-
|
199 |
-
[More Information Needed]
|
|
|
1 |
---
|
2 |
+
license: apache-2.0
|
3 |
+
train: false
|
4 |
+
inference: false
|
5 |
+
pipeline_tag: text-generation
|
6 |
---
|
7 |
+
This is an <a href="https://github.com/mobiusml/hqq/">HQQ</a> all 4-bit (group-size=64) quantized <a href="https://huggingface.co/Qwen/Qwen2.5-7B-Instruct"> Qwen2.5-7B-Instruct</a> model.
|
8 |
+
|
9 |
+
|
10 |
+
## Usage
|
11 |
+
First, install the dependecies:
|
12 |
+
```
|
13 |
+
pip install git+https://github.com/mobiusml/hqq.git;
|
14 |
+
pip install git+https://github.com/mobiusml/gemlite.git; #to use the gemlite backend
|
15 |
+
pip install bitblas #to use the bitblas backend
|
16 |
+
```
|
17 |
+
|
18 |
+
Then you can use the sample code below:
|
19 |
+
``` Python
|
20 |
+
import torch
|
21 |
+
device = 'cuda:0'
|
22 |
+
backend = 'torchao_int4' #'torchao_int4' #"torchao_int4" (4-bit only) or "bitblas" (4-bit + 2-bit) or "gemlite" (8-bit, 4-bit, 2-bit, 1-bit)
|
23 |
+
compute_dtype = torch.bfloat16 if backend=="torchao_int4" else torch.float16
|
24 |
+
cache_dir = None
|
25 |
+
model_id = 'mobiuslabsgmbh/Qwen2.5-7B-Instruct-1M_4bitgs64_hqq_hf'
|
26 |
+
|
27 |
+
is_prequantized = 'hqq_hf' in model_id
|
28 |
+
########################################################################
|
29 |
+
#Load model
|
30 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, HqqConfig
|
31 |
+
|
32 |
+
model = AutoModelForCausalLM.from_pretrained(
|
33 |
+
model_id,
|
34 |
+
torch_dtype=compute_dtype,
|
35 |
+
cache_dir=cache_dir,
|
36 |
+
device_map=device,
|
37 |
+
attn_implementation="sdpa",
|
38 |
+
low_cpu_mem_usage=True,
|
39 |
+
)
|
40 |
+
|
41 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, cache_dir=cache_dir)
|
42 |
+
|
43 |
+
#Save model before patching
|
44 |
+
# model.save_pretrained(saved_quant_model)
|
45 |
+
# tokenizer.save_pretrained(saved_quant_model)
|
46 |
+
|
47 |
+
#Patching
|
48 |
+
from hqq.utils.patching import prepare_for_inference
|
49 |
+
prepare_for_inference(model, backend=backend, verbose=True)
|
50 |
+
|
51 |
+
#Load GemLite cache
|
52 |
+
if(backend == 'gemlite'):
|
53 |
+
import gemlite
|
54 |
+
gemlite.core.GEMLITE_TRITON_RESTRICT_M = True
|
55 |
+
gemlite.core.GemLiteLinear.load_config('/tmp/gemlite_config.json')
|
56 |
+
|
57 |
+
########################################################################
|
58 |
+
# ##Inference Using a custom hqq generator - currently manual compile breaks with pre-quantized llama models :(
|
59 |
+
# from hqq.utils.generation_hf import HFGenerator
|
60 |
+
# gen = HFGenerator(model, tokenizer, max_new_tokens=1000, do_sample=True, compile=False).enable_cuda_graph()
|
61 |
+
|
62 |
+
# out = gen.generate("Write an essay about large language models.", print_tokens=True)
|
63 |
+
|
64 |
+
########################################################################
|
65 |
+
#Inference with model,generate()
|
66 |
+
from hqq.utils.generation_hf import patch_model_for_compiled_runtime
|
67 |
+
|
68 |
+
patch_model_for_compiled_runtime(model, tokenizer)
|
69 |
+
|
70 |
+
prompt = "Write an essay about large language models."
|
71 |
+
inputs = tokenizer.apply_chat_template([{"role":"user", "content":prompt}], tokenize=True, add_generation_prompt=True, return_tensors="pt", return_dict=True)
|
72 |
+
outputs = model.generate(**inputs.to(model.device), max_new_tokens=1000, cache_implementation="static", pad_token_id=tokenizer.pad_token_id)
|
73 |
+
#print(tokenizer.decode(outputs[0])
|
74 |
+
|
75 |
+
########################################################################
|
76 |
+
#Save gemlite cache
|
77 |
+
if(backend == 'gemlite'):
|
78 |
+
gemlite.core.GemLiteLinear.cache_config('/tmp/gemlite_config.json')
|
79 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|