Spaces:
Sleeping
Sleeping
Keep ZeroGPU demo on stable SFT base
Browse files
README.md
CHANGED
|
@@ -17,9 +17,10 @@ models:
|
|
| 17 |
|
| 18 |
# tinyLLM 0.51B Demo
|
| 19 |
|
| 20 |
-
This free ZeroGPU Space loads the public tinyLLM SFT
|
| 21 |
-
|
| 22 |
|
| 23 |
The first start is slower while the 0.51B checkpoint is downloaded. The full
|
| 24 |
multimodal demo remains available in the GitHub repository; this small hosted
|
| 25 |
-
Space focuses on text and
|
|
|
|
|
|
| 17 |
|
| 18 |
# tinyLLM 0.51B Demo
|
| 19 |
|
| 20 |
+
This free ZeroGPU Space loads the public tinyLLM 0.51B SFT checkpoint and offers
|
| 21 |
+
a small streaming chat demo.
|
| 22 |
|
| 23 |
The first start is slower while the 0.51B checkpoint is downloaded. The full
|
| 24 |
multimodal demo remains available in the GitHub repository; this small hosted
|
| 25 |
+
Space focuses on the stable text base. ARC GRPO and IFEval OPD adapters are
|
| 26 |
+
linked from the app and can be loaded locally with `load_lora_pretrained()`.
|
app.py
CHANGED
|
@@ -10,15 +10,9 @@ from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStream
|
|
| 10 |
|
| 11 |
|
| 12 |
BASE_REPO = "chris0809/tinyLLM-0.51B-SFT"
|
| 13 |
-
ADAPTERS = {
|
| 14 |
-
"SFT base": None,
|
| 15 |
-
"ARC-Easy GRPO": "chris0809/tinyLLM-0.51B-ARC-GRPO",
|
| 16 |
-
"IFEval OPD": "chris0809/tinyLLM-0.51B-IFEval-OPD",
|
| 17 |
-
}
|
| 18 |
|
| 19 |
_model = None
|
| 20 |
_tokenizer = None
|
| 21 |
-
_loaded_adapters: set[str] = set()
|
| 22 |
_lock = threading.RLock()
|
| 23 |
|
| 24 |
|
|
@@ -32,36 +26,16 @@ def load_runtime():
|
|
| 32 |
trust_remote_code=True,
|
| 33 |
dtype=torch.bfloat16,
|
| 34 |
).to("cuda").eval()
|
| 35 |
-
# Register both adapters before ZeroGPU packs the model tensors.
|
| 36 |
-
# Adding CUDA parameters later inside a request is less reliable.
|
| 37 |
-
for adapter_repo in (repo for repo in ADAPTERS.values() if repo):
|
| 38 |
-
_model.load_lora_pretrained(adapter_repo, activate=False)
|
| 39 |
-
_loaded_adapters.add(adapter_repo)
|
| 40 |
-
_model.activate_single_lora(None)
|
| 41 |
return _model, _tokenizer
|
| 42 |
|
| 43 |
|
| 44 |
-
def select_adapter(model, mode: str) -> None:
|
| 45 |
-
adapter_repo = ADAPTERS[mode]
|
| 46 |
-
if adapter_repo is None:
|
| 47 |
-
model.activate_single_lora(None)
|
| 48 |
-
return
|
| 49 |
-
if adapter_repo not in _loaded_adapters:
|
| 50 |
-
model.load_lora_pretrained(adapter_repo)
|
| 51 |
-
_loaded_adapters.add(adapter_repo)
|
| 52 |
-
else:
|
| 53 |
-
name = "arc" if mode == "ARC-Easy GRPO" else "opd_ifeval_rank64"
|
| 54 |
-
model.activate_single_lora(name)
|
| 55 |
-
|
| 56 |
-
|
| 57 |
@spaces.GPU(duration=120)
|
| 58 |
-
def respond(message: str, history: list[dict],
|
| 59 |
if not message.strip():
|
| 60 |
yield "请输入一个问题。"
|
| 61 |
return
|
| 62 |
with _lock:
|
| 63 |
model, tokenizer = load_runtime()
|
| 64 |
-
select_adapter(model, mode)
|
| 65 |
messages = [
|
| 66 |
{"role": row["role"], "content": row["content"]}
|
| 67 |
for row in history
|
|
@@ -108,19 +82,17 @@ load_runtime()
|
|
| 108 |
with gr.Blocks(title="tinyLLM 0.51B") as demo:
|
| 109 |
gr.Markdown(
|
| 110 |
"# tinyLLM 0.51B\n"
|
| 111 |
-
"从零训练的中英双语小模型。
|
| 112 |
)
|
| 113 |
-
|
| 114 |
-
mode = gr.Dropdown(list(ADAPTERS), value="SFT base", label="Model / LoRA")
|
| 115 |
-
max_tokens = gr.Slider(32, 512, value=160, step=32, label="Maximum new tokens")
|
| 116 |
gr.ChatInterface(
|
| 117 |
fn=respond,
|
| 118 |
-
additional_inputs=[
|
| 119 |
type="messages",
|
| 120 |
examples=[
|
| 121 |
-
["用两句话介绍一下你自己。",
|
| 122 |
-
["
|
| 123 |
-
["Write
|
| 124 |
],
|
| 125 |
cache_examples=False,
|
| 126 |
concurrency_limit=1,
|
|
@@ -128,7 +100,9 @@ with gr.Blocks(title="tinyLLM 0.51B") as demo:
|
|
| 128 |
gr.Markdown(
|
| 129 |
"多模态权重已发布在 [tinyLLM-0.51B-VLM]"
|
| 130 |
"(https://huggingface.co/chris0809/tinyLLM-0.51B-VLM)。"
|
| 131 |
-
"
|
|
|
|
|
|
|
| 132 |
)
|
| 133 |
|
| 134 |
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
BASE_REPO = "chris0809/tinyLLM-0.51B-SFT"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
_model = None
|
| 15 |
_tokenizer = None
|
|
|
|
| 16 |
_lock = threading.RLock()
|
| 17 |
|
| 18 |
|
|
|
|
| 26 |
trust_remote_code=True,
|
| 27 |
dtype=torch.bfloat16,
|
| 28 |
).to("cuda").eval()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
return _model, _tokenizer
|
| 30 |
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
@spaces.GPU(duration=120)
|
| 33 |
+
def respond(message: str, history: list[dict], max_new_tokens: int):
|
| 34 |
if not message.strip():
|
| 35 |
yield "请输入一个问题。"
|
| 36 |
return
|
| 37 |
with _lock:
|
| 38 |
model, tokenizer = load_runtime()
|
|
|
|
| 39 |
messages = [
|
| 40 |
{"role": row["role"], "content": row["content"]}
|
| 41 |
for row in history
|
|
|
|
| 82 |
with gr.Blocks(title="tinyLLM 0.51B") as demo:
|
| 83 |
gr.Markdown(
|
| 84 |
"# tinyLLM 0.51B\n"
|
| 85 |
+
"从零训练的中英双语小模型。这里在线运行公开的 0.51B SFT checkpoint。"
|
| 86 |
)
|
| 87 |
+
max_tokens = gr.Slider(32, 512, value=160, step=32, label="Maximum new tokens")
|
|
|
|
|
|
|
| 88 |
gr.ChatInterface(
|
| 89 |
fn=respond,
|
| 90 |
+
additional_inputs=[max_tokens],
|
| 91 |
type="messages",
|
| 92 |
examples=[
|
| 93 |
+
["用两句话介绍一下你自己。", 128],
|
| 94 |
+
["What is 12 minus 5? Give a short answer.", 96],
|
| 95 |
+
["Write three bullet points about small language models.", 160],
|
| 96 |
],
|
| 97 |
cache_examples=False,
|
| 98 |
concurrency_limit=1,
|
|
|
|
| 100 |
gr.Markdown(
|
| 101 |
"多模态权重已发布在 [tinyLLM-0.51B-VLM]"
|
| 102 |
"(https://huggingface.co/chris0809/tinyLLM-0.51B-VLM)。"
|
| 103 |
+
"[ARC GRPO](https://huggingface.co/chris0809/tinyLLM-0.51B-ARC-GRPO) 和 "
|
| 104 |
+
"[IFEval OPD](https://huggingface.co/chris0809/tinyLLM-0.51B-IFEval-OPD) LoRA 也可单独下载。"
|
| 105 |
+
"完整图片演示建议使用 GitHub 中的本地 Demo;这个免费 Space 主要用于快速验证文本基座。"
|
| 106 |
)
|
| 107 |
|
| 108 |
|