Spaces:
Paused
Paused
Upload folder using huggingface_hub
Browse files- README.md +7 -9
- app.py +38 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
| 1 |
---
|
| 2 |
-
title: Bench
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
python_version: '3.13'
|
| 9 |
app_file: app.py
|
| 10 |
-
|
| 11 |
---
|
| 12 |
-
|
| 13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Bench ZeroGPU
|
| 3 |
+
emoji: ⚡
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.50.0
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
+
short_description: bake-off model server on ZeroGPU
|
| 10 |
---
|
| 11 |
+
Model server for the base-model bake-off. API: `run(messages_json, tools_json, max_new_tokens, temperature)`.
|
|
|
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
+
import torch, json
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 5 |
+
|
| 6 |
+
MODEL_ID = "Qwen/Qwen3-0.6B"
|
| 7 |
+
tok = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto").to("cuda")
|
| 9 |
+
|
| 10 |
+
@spaces.GPU(duration=60)
|
| 11 |
+
def run(messages_json, tools_json="", max_new_tokens=512, temperature=0.7):
|
| 12 |
+
messages = json.loads(messages_json)
|
| 13 |
+
tools = json.loads(tools_json) if (tools_json and tools_json.strip()) else None
|
| 14 |
+
ids = tok.apply_chat_template(
|
| 15 |
+
messages, tools=tools, add_generation_prompt=True,
|
| 16 |
+
return_tensors="pt", tokenize=True, enable_thinking=False,
|
| 17 |
+
).to(model.device)
|
| 18 |
+
with torch.no_grad():
|
| 19 |
+
out = model.generate(
|
| 20 |
+
ids, max_new_tokens=int(max_new_tokens),
|
| 21 |
+
do_sample=(float(temperature) > 0),
|
| 22 |
+
temperature=max(float(temperature), 0.01),
|
| 23 |
+
pad_token_id=tok.eos_token_id,
|
| 24 |
+
)
|
| 25 |
+
return tok.decode(out[0][ids.shape[1]:], skip_special_tokens=False)
|
| 26 |
+
|
| 27 |
+
demo = gr.Interface(
|
| 28 |
+
fn=run,
|
| 29 |
+
inputs=[
|
| 30 |
+
gr.Textbox(label="messages_json", value='[{"role":"user","content":"Say hi in 3 words"}]'),
|
| 31 |
+
gr.Textbox(label="tools_json", value=""),
|
| 32 |
+
gr.Number(label="max_new_tokens", value=512),
|
| 33 |
+
gr.Number(label="temperature", value=0.7),
|
| 34 |
+
],
|
| 35 |
+
outputs=gr.Textbox(label="output"),
|
| 36 |
+
api_name="run",
|
| 37 |
+
)
|
| 38 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers>=4.51.0
|
| 2 |
+
accelerate
|