Spaces:
Sleeping
Sleeping
MekkCyber
commited on
Commit
Β·
d619e33
1
Parent(s):
ca0db66
update
Browse files
app.py
CHANGED
@@ -50,7 +50,9 @@ base_model:
|
|
50 |
# {model_name} (Quantized)
|
51 |
|
52 |
## Description
|
53 |
-
This model is a quantized version of the original model `{model_name}
|
|
|
|
|
54 |
|
55 |
## Quantization Details
|
56 |
- **Quantization Type**: int4
|
@@ -59,12 +61,7 @@ This model is a quantized version of the original model `{model_name}`. It has b
|
|
59 |
- **bnb_4bit_compute_dtype**: {compute_type_4}
|
60 |
- **bnb_4bit_quant_storage**: {quant_storage_4}
|
61 |
|
62 |
-
|
63 |
-
You can use this model in your applications by loading it directly from the Hugging Face Hub:
|
64 |
-
```python
|
65 |
-
from transformers import AutoModel
|
66 |
-
|
67 |
-
model = AutoModel.from_pretrained("{model_name}")"""
|
68 |
|
69 |
return model_card
|
70 |
|
@@ -153,7 +150,7 @@ def save_model(
|
|
153 |
repo_name = f"{username}/{model_name.split('/')[-1]}-bnb-4bit"
|
154 |
|
155 |
model_card = create_model_card(
|
156 |
-
|
157 |
)
|
158 |
with open(os.path.join(tmpdirname, "README.md"), "w") as f:
|
159 |
f.write(model_card)
|
@@ -198,30 +195,6 @@ def save_model(
|
|
198 |
</div>
|
199 |
"""
|
200 |
|
201 |
-
code = f"""
|
202 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
203 |
-
import torch
|
204 |
-
|
205 |
-
model = AutoModelForCausalLM.from_pretrained(
|
206 |
-
"{repo_name}",
|
207 |
-
device_map="auto"
|
208 |
-
)
|
209 |
-
|
210 |
-
tokenizer = AutoTokenizer.from_pretrained("{model_name}")
|
211 |
-
|
212 |
-
inputs = tokenizer("Hello, my name is", return_tensors="pt").to(model.device)
|
213 |
-
outputs = model.generate(inputs.input_ids, max_length=50)
|
214 |
-
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
215 |
-
"""
|
216 |
-
# First replace newlines in the code
|
217 |
-
code_html = code.replace("\n", "<br/>")
|
218 |
-
|
219 |
-
usage_example = f"""
|
220 |
-
<div class="usage-example" style="margin-top: 20px; margin-bottom: 20px; background-color: #f8f9fa; padding: 15px; border-radius: 8px; border-left: 4px solid #4CAF50;">
|
221 |
-
<h3 style="margin-top: 0; color: #2E7D32;">π How to use this model</h3>
|
222 |
-
<div class="model-architecture" style="max-height: 500px; overflow-y: auto; overflow-x: auto; background-color: #f5f5f5; padding: 5px; border-radius: 8px; font-family: monospace; font-size: 0.75em; white-space: pre-wrap;">{code_html}</div>
|
223 |
-
</div>
|
224 |
-
"""
|
225 |
model_size_info = f"""
|
226 |
<div class="model-size-info" style="margin-top: 20px; margin-bottom: 20px; background-color: #f8f9fa; padding: 15px; border-radius: 8px; border-left: 4px solid #4CAF50;">
|
227 |
<h3 style="margin-top: 0; color: #2E7D32;">π¦ Model Size</h3>
|
@@ -235,7 +208,7 @@ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
|
235 |
<p>Find your repo here: <a href="https://huggingface.co/{repo_name}" target="_blank" style="text-decoration:underline">{repo_name}</a></p>
|
236 |
</div>
|
237 |
"""
|
238 |
-
return f'<h1>π Quantization Completed</h1><br/>{repo_link}{
|
239 |
|
240 |
|
241 |
def quantize_and_save(
|
|
|
50 |
# {model_name} (Quantized)
|
51 |
|
52 |
## Description
|
53 |
+
This model is a quantized version of the original model [`{model_name}`](https://huggingface.co/{model_name}).
|
54 |
+
|
55 |
+
It's quantized using the BitsAndBytes library to 4-bit using the [bnb-my-repo](https://huggingface.co/spaces/HF-Quantization/bnb-my-repo) space.
|
56 |
|
57 |
## Quantization Details
|
58 |
- **Quantization Type**: int4
|
|
|
61 |
- **bnb_4bit_compute_dtype**: {compute_type_4}
|
62 |
- **bnb_4bit_quant_storage**: {quant_storage_4}
|
63 |
|
64 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
return model_card
|
67 |
|
|
|
150 |
repo_name = f"{username}/{model_name.split('/')[-1]}-bnb-4bit"
|
151 |
|
152 |
model_card = create_model_card(
|
153 |
+
model_name, quant_type_4, double_quant_4, compute_type_4, quant_storage_4
|
154 |
)
|
155 |
with open(os.path.join(tmpdirname, "README.md"), "w") as f:
|
156 |
f.write(model_card)
|
|
|
195 |
</div>
|
196 |
"""
|
197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
model_size_info = f"""
|
199 |
<div class="model-size-info" style="margin-top: 20px; margin-bottom: 20px; background-color: #f8f9fa; padding: 15px; border-radius: 8px; border-left: 4px solid #4CAF50;">
|
200 |
<h3 style="margin-top: 0; color: #2E7D32;">π¦ Model Size</h3>
|
|
|
208 |
<p>Find your repo here: <a href="https://huggingface.co/{repo_name}" target="_blank" style="text-decoration:underline">{repo_name}</a></p>
|
209 |
</div>
|
210 |
"""
|
211 |
+
return f'<h1>π Quantization Completed</h1><br/>{repo_link}{model_size_info}{model_architecture_info}'
|
212 |
|
213 |
|
214 |
def quantize_and_save(
|