Spaces:
Sleeping
Sleeping
Commit ·
24ef55b
1
Parent(s): 4f79537
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,20 @@ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
|
| 6 |
from functools import partial
|
| 7 |
import gc
|
| 8 |
|
|
|
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# core quantization method (simulated quantization)
|
| 12 |
def pseudo_quantize_tensor(w, n_bit=4, q_group_size=-1):
|
|
@@ -62,7 +75,7 @@ model_path = "facebook/opt-125m"
|
|
| 62 |
|
| 63 |
model_q_path = "facebook/opt-125m_3bit"
|
| 64 |
|
| 65 |
-
|
| 66 |
generator = pipeline('text-generation', model="facebook/opt-125m_3bit")
|
| 67 |
#generator_q = pipeline('text-generation', model="facebook/opt-125m-awq")
|
| 68 |
|
|
@@ -98,7 +111,8 @@ def generate_text_from_quantized(prompt):
|
|
| 98 |
return generated_text
|
| 99 |
'''
|
| 100 |
# Create a Gradio interface
|
| 101 |
-
|
|
|
|
| 102 |
|
| 103 |
#iface_2 = gr.Interface(fn=generate_text_pip_q, inputs="text", outputs="text")
|
| 104 |
|
|
|
|
| 6 |
from functools import partial
|
| 7 |
import gc
|
| 8 |
|
| 9 |
+
def get_model_size(model: nn.Module, data_width=16, group_size=-1):
|
| 10 |
|
| 11 |
+
if group_size != -1:
|
| 12 |
+
data_width += (16 + 4) / group_size
|
| 13 |
+
|
| 14 |
+
num_elements = 0
|
| 15 |
+
for param in model.parameters():
|
| 16 |
+
num_elements += param.numel()
|
| 17 |
+
return num_elements * data_width
|
| 18 |
+
|
| 19 |
+
Byte = 8
|
| 20 |
+
KiB = 1024 * Byte
|
| 21 |
+
MiB = 1024 * KiB
|
| 22 |
+
GiB = 1024 * MiB
|
| 23 |
|
| 24 |
# core quantization method (simulated quantization)
|
| 25 |
def pseudo_quantize_tensor(w, n_bit=4, q_group_size=-1):
|
|
|
|
| 75 |
|
| 76 |
model_q_path = "facebook/opt-125m_3bit"
|
| 77 |
|
| 78 |
+
model = AutoModelForCausalLM.from_pretrained(model_q_path, device_map="auto", offload_folder=offload_folder)
|
| 79 |
generator = pipeline('text-generation', model="facebook/opt-125m_3bit")
|
| 80 |
#generator_q = pipeline('text-generation', model="facebook/opt-125m-awq")
|
| 81 |
|
|
|
|
| 111 |
return generated_text
|
| 112 |
'''
|
| 113 |
# Create a Gradio interface
|
| 114 |
+
model_size = get_model_size(model, data_width=32, group_size=128)
|
| 115 |
+
iface = gr.Interface(fn=generate_text_pip, inputs="text", outputs="text", description=f"model size: {model_size/MiB:.2f} MiB")
|
| 116 |
|
| 117 |
#iface_2 = gr.Interface(fn=generate_text_pip_q, inputs="text", outputs="text")
|
| 118 |
|