echogo_4b
弈秋 EchoGo 的中文围棋讲解模型。输入为落子前棋盘、KataGo 分析提取的结构化事实及可用上下文,输出为带事实引用的中文讲解。仓库提供 BF16 Safetensors 权重与 tokenizer,可通过 Transformers 直接加载。
在 Apple M4 上运行本地版
本地版使用 echogo_4b-Q5_K_M.gguf(2.89 GB)。这个文件包含模型权重、分词器和对话模板。下面用 llama.cpp 的 Metal 后端运行,下载一次后即可离线生成讲解。应用需要把棋盘和 KataGo 事实一起传给模型,example_messages.json 提供了一条完整的输入示例。
在已安装 Homebrew 的 Mac 上打开终端,下载 GGUF 和示例棋局,然后启动本地服务。curl -C - 支持断点续传。
brew install llama.cpp jq
mkdir -p ~/echogo && cd ~/echogo
curl -fL --retry 3 -C - -o echogo_4b-Q5_K_M.gguf \
https://huggingface.co/Scarick2003buffalo/echogo_4b/resolve/main/echogo_4b-Q5_K_M.gguf
curl -fL -o example_messages.json \
https://huggingface.co/Scarick2003buffalo/echogo_4b/resolve/main/example_messages.json
llama-server -m echogo_4b-Q5_K_M.gguf --alias echogo_4b \
--host 127.0.0.1 --port 18084 -ngl 99 -c 4096 -np 1 \
--jinja --chat-template-kwargs '{"enable_thinking":false}'
保持服务运行,在第二个终端执行下面的命令,即可看到这一步棋的中文讲解。按 Ctrl+C 可在第一个终端停止服务。
cd ~/echogo
jq '{model:"echogo_4b", messages:., temperature:0, max_tokens:400}' example_messages.json |
curl -fsS http://127.0.0.1:18084/v1/chat/completions \
-H 'Content-Type: application/json' --data-binary @- |
jq -r '.choices[0].message.content'
M4 实测。 Apple M4、16 GiB 统一内存、llama.cpp b7370,逐个请求 12 盘棋的 12 个局面。输入中位数约 1,003 tokens,模型加载后首段文字中位等待 9.6 秒,整篇讲解 18.5 秒,解码 6.7 tokens/s。进程峰值常驻内存(RSS)4.33 GiB。测试时机器有后台传输和内存交换,实际速度随负载和输入长度变化。
输入与推理
example_messages.json 是为演示接口而构造的局面与数值。接到 APP 时,用实际棋盘与分析结果替换它。盘面用 X/O 表示黑白,@ 标注实战落点,A、B 标注参考点。事实可以包含目差、推荐变化、对方应对、棋块和区域得失。参考变化仅供解说,实战下一手在实时输入中隐藏。推理时关闭 thinking,使用 greedy 解码。
import json
import os
import torch
from huggingface_hub import hf_hub_download
from transformers import AutoModelForCausalLM, AutoTokenizer
# 将 MODEL_ID 设为这个仓库的完整 Hugging Face ID
repo = os.environ["MODEL_ID"]
tokenizer = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(repo, torch_dtype=torch.bfloat16, device_map="auto").eval()
with open(hf_hub_download(repo, "example_messages.json"), encoding="utf-8") as f:
messages = json.load(f)
inputs = tokenizer.apply_chat_template(
messages, tokenize=True, return_dict=True, return_tensors="pt",
add_generation_prompt=True, enable_thinking=False,
).to(model.device)
with torch.inference_mode():
ids = model.generate(**inputs, do_sample=False, max_new_tokens=400, pad_token_id=tokenizer.eos_token_id)
print(tokenizer.decode(ids[0, inputs.input_ids.shape[1]:], skip_special_tokens=True))
局限
引用标记用于对照输入。模型有时会弄错棋色、落子次序、手法或区域得失。部署应为模型提供可信的棋局分析。
软件
弈秋 EchoGo 用这个模型在本机讲解棋局:https://yiqiu-go.github.io(源码 https://github.com/yiqiu-go/yiqiu-go.github.io)。
许可证
本发布修改了 Qwen3-4B 的权重。上游模型采用 Apache License 2.0。详见仓库的 LICENSE 与上游模型。