Spaces:
Paused
Paused
gse brain engine: MiMo-V2.6 4-bit on ZeroGPU (free tier)
Browse files
app.py
CHANGED
|
@@ -11,7 +11,7 @@ import torch
|
|
| 11 |
import gradio as gr
|
| 12 |
from transformers import (
|
| 13 |
AutoModelForImageTextToText,
|
| 14 |
-
|
| 15 |
BitsAndBytesConfig,
|
| 16 |
)
|
| 17 |
|
|
@@ -25,8 +25,8 @@ SYSTEM_PROMPT = (
|
|
| 25 |
"(3) Output ONLY valid JSON when a JSON schema is requested."
|
| 26 |
)
|
| 27 |
|
| 28 |
-
print("Loading
|
| 29 |
-
|
| 30 |
|
| 31 |
print("Loading model in 4-bit...", flush=True)
|
| 32 |
bnb = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.float16)
|
|
@@ -51,9 +51,9 @@ def chat(message: str, history: list):
|
|
| 51 |
messages.append({"role": "assistant", "content": h_asst})
|
| 52 |
messages.append({"role": "user", "content": message})
|
| 53 |
|
| 54 |
-
text =
|
| 55 |
messages, add_generation_prompt=True, tokenize=False)
|
| 56 |
-
inputs =
|
| 57 |
input_len = inputs["input_ids"].shape[1]
|
| 58 |
|
| 59 |
with torch.inference_mode():
|
|
@@ -62,9 +62,9 @@ def chat(message: str, history: list):
|
|
| 62 |
max_new_tokens=1024,
|
| 63 |
temperature=0.2,
|
| 64 |
do_sample=True,
|
| 65 |
-
pad_token_id=
|
| 66 |
)
|
| 67 |
-
response =
|
| 68 |
out[:, input_len:], skip_special_tokens=True)[0]
|
| 69 |
return response.strip()
|
| 70 |
except Exception as exc: # never crash the Space; return the error loudly
|
|
|
|
| 11 |
import gradio as gr
|
| 12 |
from transformers import (
|
| 13 |
AutoModelForImageTextToText,
|
| 14 |
+
AutoTokenizer,
|
| 15 |
BitsAndBytesConfig,
|
| 16 |
)
|
| 17 |
|
|
|
|
| 25 |
"(3) Output ONLY valid JSON when a JSON schema is requested."
|
| 26 |
)
|
| 27 |
|
| 28 |
+
print("Loading tokenizer...", flush=True)
|
| 29 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
|
| 30 |
|
| 31 |
print("Loading model in 4-bit...", flush=True)
|
| 32 |
bnb = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.float16)
|
|
|
|
| 51 |
messages.append({"role": "assistant", "content": h_asst})
|
| 52 |
messages.append({"role": "user", "content": message})
|
| 53 |
|
| 54 |
+
text = tokenizer.apply_chat_template(
|
| 55 |
messages, add_generation_prompt=True, tokenize=False)
|
| 56 |
+
inputs = tokenizer(text, return_tensors="pt").to("cuda")
|
| 57 |
input_len = inputs["input_ids"].shape[1]
|
| 58 |
|
| 59 |
with torch.inference_mode():
|
|
|
|
| 62 |
max_new_tokens=1024,
|
| 63 |
temperature=0.2,
|
| 64 |
do_sample=True,
|
| 65 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 66 |
)
|
| 67 |
+
response = tokenizer.batch_decode(
|
| 68 |
out[:, input_len:], skip_special_tokens=True)[0]
|
| 69 |
return response.strip()
|
| 70 |
except Exception as exc: # never crash the Space; return the error loudly
|