Spaces:
Runtime error
Runtime error
Commit
Β·
f9e7dbf
1
Parent(s):
ca7802a
init app
Browse files- README.md +7 -7
- app.py +76 -28
- requirements.txt +2 -1
README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
| 1 |
---
|
| 2 |
-
title: VPTQ
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 4.36.1
|
| 8 |
app_file: app.py
|
| 9 |
-
pinned:
|
| 10 |
license: mit
|
| 11 |
-
short_description: VPTQ
|
| 12 |
---
|
| 13 |
|
| 14 |
-
An example chatbot using [
|
|
|
|
| 1 |
---
|
| 2 |
+
title: VPTQ demo
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 4.36.1
|
| 8 |
app_file: app.py
|
| 9 |
+
pinned: true
|
| 10 |
license: mit
|
| 11 |
+
short_description: Vector Post-Training Quantization (VPTQ) Demo
|
| 12 |
---
|
| 13 |
|
| 14 |
+
An example chatbot using [VPTQ](https://github.com/microsoft/VPTQ), [huggingface community](https://huggingface.co/spaces/VPTQ-community/).
|
app.py
CHANGED
|
@@ -1,12 +1,41 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def respond(
|
| 11 |
message,
|
| 12 |
history: list[tuple[str, str]],
|
|
@@ -27,37 +56,56 @@ def respond(
|
|
| 27 |
|
| 28 |
response = ""
|
| 29 |
|
| 30 |
-
for message in
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
):
|
| 37 |
-
token = message
|
| 38 |
|
| 39 |
response += token
|
| 40 |
yield response
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
"""
|
| 43 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 44 |
-
"""
|
| 45 |
-
demo = gr.ChatInterface(
|
| 46 |
-
respond,
|
| 47 |
-
additional_inputs=[
|
| 48 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 49 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 50 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 51 |
-
gr.Slider(
|
| 52 |
-
minimum=0.1,
|
| 53 |
-
maximum=1.0,
|
| 54 |
-
value=0.95,
|
| 55 |
-
step=0.05,
|
| 56 |
-
label="Top-p (nucleus sampling)",
|
| 57 |
-
),
|
| 58 |
-
],
|
| 59 |
-
)
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
if __name__ == "__main__":
|
| 63 |
demo.launch()
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
+
from vptq.app_utils import get_chat_loop_generator
|
| 6 |
+
|
| 7 |
+
# Update model list with annotations
|
| 8 |
+
model_list_with_annotations = {
|
| 9 |
+
# "VPTQ-community/Meta-Llama-3.1-70B-Instruct-v8-k65536-65536-woft": "Llama 3.1 70B @ 4bit",
|
| 10 |
+
# "VPTQ-community/Meta-Llama-3.1-70B-Instruct-v8-k65536-256-woft": "Llama 3.1 70B @ 3bit",
|
| 11 |
+
# "VPTQ-community/Meta-Llama-3.1-70B-Instruct-v16-k65536-65536-woft": "Llama 3.1 70B @ 2bit",
|
| 12 |
+
# "VPTQ-community/Qwen2.5-72B-Instruct-v8-k65536-65536-woft": "Qwen2.5 72B @ 4 bits",
|
| 13 |
+
# "VPTQ-community/Qwen2.5-72B-Instruct-v8-k65536-256-woft": "Qwen2.5 72B @ 3 bits",
|
| 14 |
+
# "VPTQ-community/Qwen2.5-72B-Instruct-v16-k65536-65536-woft": "Qwen2.5 72B @ 3 bits",
|
| 15 |
+
# "VPTQ-community/Qwen2.5-32B-Instruct-v8-k65536-65536-woft": "Qwen2.5 32B @ 4 bits",
|
| 16 |
+
"VPTQ-community/Qwen2.5-32B-Instruct-v8-k65536-256-woft": "Qwen2.5 32B @ 3 bits",
|
| 17 |
+
"VPTQ-community/Qwen2.5-32B-Instruct-v16-k65536-0-woft": "Qwen2.5 32B @ 2 bits"
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
# Create a list of choices with annotations for the dropdown
|
| 21 |
+
model_list_with_annotations_display = [f"{key} ({value})" for key, value in model_list_with_annotations.items()]
|
| 22 |
|
| 23 |
+
model_keys = list(model_list_with_annotations.keys())
|
| 24 |
+
current_model_g = model_keys[0]
|
| 25 |
+
chat_completion = get_chat_loop_generator(current_model_g)
|
| 26 |
|
| 27 |
+
@spaces.GPU
|
| 28 |
+
def update_title_and_chatmodel(model):
|
| 29 |
+
model = str(model)
|
| 30 |
+
global chat_completion
|
| 31 |
+
global current_model_g
|
| 32 |
+
if model != current_model_g:
|
| 33 |
+
current_model_g = model
|
| 34 |
+
chat_completion = get_chat_loop_generator(current_model_g)
|
| 35 |
+
return model
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
@spaces.GPU
|
| 39 |
def respond(
|
| 40 |
message,
|
| 41 |
history: list[tuple[str, str]],
|
|
|
|
| 56 |
|
| 57 |
response = ""
|
| 58 |
|
| 59 |
+
for message in chat_completion(
|
| 60 |
+
messages,
|
| 61 |
+
max_tokens=max_tokens,
|
| 62 |
+
stream=True,
|
| 63 |
+
temperature=temperature,
|
| 64 |
+
top_p=top_p,
|
| 65 |
):
|
| 66 |
+
token = message
|
| 67 |
|
| 68 |
response += token
|
| 69 |
yield response
|
| 70 |
|
| 71 |
+
|
| 72 |
+
css = """
|
| 73 |
+
h1 {
|
| 74 |
+
text-align: center;
|
| 75 |
+
display: block;
|
| 76 |
+
}
|
| 77 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
+
chatbot = gr.Chatbot(label="Gradio ChatInterface")
|
| 80 |
+
with gr.Blocks() as demo:
|
| 81 |
+
with gr.Column(scale=1):
|
| 82 |
+
title_output = gr.Markdown("Please select a model to run")
|
| 83 |
+
chat_demo = gr.ChatInterface(
|
| 84 |
+
respond,
|
| 85 |
+
additional_inputs_accordion=gr.Accordion(
|
| 86 |
+
label="βοΈ Parameters", open=False, render=False
|
| 87 |
+
),
|
| 88 |
+
fill_height=False,
|
| 89 |
+
additional_inputs=[
|
| 90 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 91 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 92 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 93 |
+
gr.Slider(
|
| 94 |
+
minimum=0.1,
|
| 95 |
+
maximum=1.0,
|
| 96 |
+
value=0.95,
|
| 97 |
+
step=0.05,
|
| 98 |
+
label="Top-p (nucleus sampling)"
|
| 99 |
+
),
|
| 100 |
+
],
|
| 101 |
+
)
|
| 102 |
+
model_select = gr.Dropdown(
|
| 103 |
+
choices=model_list_with_annotations_display,
|
| 104 |
+
label="Models",
|
| 105 |
+
value=model_list_with_annotations_display[0],
|
| 106 |
+
info="Model & Estimated Quantized Bitwidth"
|
| 107 |
+
)
|
| 108 |
+
model_select.change(update_title_and_chatmodel, inputs=[model_select], outputs=title_output)
|
| 109 |
|
| 110 |
if __name__ == "__main__":
|
| 111 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
huggingface_hub
|
|
|
|
|
|
| 1 |
+
huggingface_hub>=0.22.2
|
| 2 |
+
https://github.com/microsoft/VPTQ/releases/download/v0.0.1/vptq-0.0.1-cp310-cp310-manylinux1_x86_64.whl
|