Instructions to use shiqianyan/TangYuGe-gemma-4-12b-it-qat with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use shiqianyan/TangYuGe-gemma-4-12b-it-qat with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="shiqianyan/TangYuGe-gemma-4-12b-it-qat") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("shiqianyan/TangYuGe-gemma-4-12b-it-qat") model = AutoModelForMultimodalLM.from_pretrained("shiqianyan/TangYuGe-gemma-4-12b-it-qat", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use shiqianyan/TangYuGe-gemma-4-12b-it-qat with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "shiqianyan/TangYuGe-gemma-4-12b-it-qat" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shiqianyan/TangYuGe-gemma-4-12b-it-qat", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/shiqianyan/TangYuGe-gemma-4-12b-it-qat
- SGLang
How to use shiqianyan/TangYuGe-gemma-4-12b-it-qat with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "shiqianyan/TangYuGe-gemma-4-12b-it-qat" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shiqianyan/TangYuGe-gemma-4-12b-it-qat", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "shiqianyan/TangYuGe-gemma-4-12b-it-qat" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shiqianyan/TangYuGe-gemma-4-12b-it-qat", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use shiqianyan/TangYuGe-gemma-4-12b-it-qat with Docker Model Runner:
docker model run hf.co/shiqianyan/TangYuGe-gemma-4-12b-it-qat
# pip install -U transformers accelerate
# Load model directly
from transformers import AutoProcessor, AutoModelForMultimodalLM
processor = AutoProcessor.from_pretrained("shiqianyan/TangYuGe-gemma-4-12b-it-qat")
model = AutoModelForMultimodalLM.from_pretrained("shiqianyan/TangYuGe-gemma-4-12b-it-qat", device_map="auto")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
{"type": "text", "text": "What animal is on the candy?"}
]
},
]
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=256)
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))TangYuGe · 唐语歌
TangYuGe 是基于 Gemma 4 12B 的中文角色对话模型,围绕唐语歌角色开展后训练,重点改善自然表达、多轮衔接、上下文纠错和角色卡使用。
本仓库提供合并后的完整 BF16 权重、角色卡、文字推理入口,以及配套的 MTP assistant。推理默认开启 thinking,角色设定可通过 role-card.json 调整。
模型信息
| 项目 | 内容 |
|---|---|
| 开发者 | shiqianyan |
| 基础模型 | google/gemma-4-12B-it-qat-q4_0-unquantized |
| 参数规模 | 12B |
| 架构 | Gemma4UnifiedForConditionalGeneration |
| 主要语言 | 中文 |
| 用途 | 角色对话、角色卡条件生成、对话后训练研究 |
| 训练方法 | LoRA、教师反馈 SFT、DPO |
| 权重格式 | BF16 · safetensors · 约 23.92 GB |
| 许可证 | Apache-2.0 |
仓库名称中的 qat 来自基础模型版本。本次发布将语言侧 LoRA 合并到原始 BF16 权重,保留了基础架构;当前训练和评测聚焦文字对话。
快速开始
已验证环境使用 PyTorch 2.9.1、Transformers 5.19.0、Accelerate 1.15.0。请按设备安装对应的 PyTorch;项目验证使用单张 48GB GPU,运行时还需为激活与 KV cache 预留显存。
hf download shiqianyan/TangYuGe-gemma-4-12b-it-qat --local-dir TangYuGe-model
python -m pip install -r TangYuGe-model/requirements.txt
python TangYuGe-model/inference.py --message "语歌,今天想和你聊一会儿。"
入口自动加载仓库角色卡,默认开启 thinking、采用 greedy 解码,并显示最终回答。
| 选项 | 说明 |
|---|---|
--message |
用户输入 |
--max-new-tokens |
生成预算,默认 2048,包含思考部分 |
--disable-thinking |
显式关闭 thinking |
--model |
本地模型目录,默认脚本所在目录 |
示例入口的提示与生成总预算为 4096 token。多轮应用可使用同一 tokenizer 的聊天模板传入历史消息。角色卡使用 {{user}} 占位,不预设任何昵称;入口默认替换为中性的“用户”,可用 --user-name 指定自己的称呼。
MTP 加速
仓库 mtp/ 提供与本版主模型绑定的独立 assistant,使用显式入口启用:
python TangYuGe-model/mtp/inference.py --message "语歌,今天想和你聊一会儿。"
该入口默认开启 thinking,采用 512 token 思考额度和 3 token 草稿长度。二十题在线对照中,本版 MTP 头 30.52 token/s、原头 28.94 token/s、关闭 MTP 14.24 token/s(答案段接受率 0.442,未达 60% 正式门槛,详见 mtp/README.md)。适配方法、分段接受率及运行条件见 MTP 模型说明。根目录文字入口默认使用主模型单独生成。
训练
训练使用正式角色卡、新场景示例及学生实际生成的多轮轨迹。教师 deepseek-flash 提供回复示例、错误反馈与偏好比较,经过筛选后用于 SFT 和 DPO;同卡改写、角色属性变化和纠错场景用于加强角色卡条件学习。
| 阶段 | 数据 | 优化步数 |
|---|---|---|
| 场景 SFT | 24 条审核示例 | 16 |
| 教师反馈 SFT | 64 条学生轨迹反馈+24 条回放 | 48 |
| DPO | 18 对教师偏好 | 8 |
| 表达与边界续训 | 136 条审核数据 | 256 |
最后阶段采用 LoRA rank 16、alpha 32、学习率 5e-5、梯度累积 4、序列长度 1024,在单张 4090 48GB 上以 NF4 加载训练。发布权重由最后阶段选定的适配器合并得到。教师参与方式为文本反馈与偏好优化。
评测
在独立的 16 组两轮场景中,对三个候选使用相同角色卡和生成设置,共产生 96 条回复。以下为教师匿名评审的第一或并列第一组数:
| 模型 | 第一或并列第一 / 16 |
|---|---|
| 基础模型+角色卡 | 6 |
| 反馈 SFT+DPO | 5 |
| 最终续训版本 | 12 |
评审允许并列。测试观察到角色属性切换、部分上下文边界处理和表达方面的改善;这组小规模场景主要用于项目内部版本比较。完整合并模型经过独立重载,678 个运行态张量指纹一致,8 条生成均正常结束。
当前局限
本版仍存在无工具支持的行动承诺、偶发外语混入及角色一致性波动,项目对话质量验收尚未通过。历史文字评测采用 thinking 关闭设置;默认开启后的表现,以及通用能力和长上下文表现,仍需进一步评测。MTP 的八题结果属于有限诊断,其总体和答案段接受率低于项目目标,完整 32 题评测待补充。
文件与复现
| 文件 | 内容 |
|---|---|
model.safetensors |
完整合并主模型 |
config.json、tokenizer 与处理器文件 |
模型结构、分词和聊天模板 |
role-card.json |
唐语歌角色卡 |
inference.py、gemma_output.py |
文字推理与回答解析 |
mtp/ |
配套 assistant、绑定信息和加载入口 |
provenance.json、evaluation.json |
模型来源与文字评测摘要 |
SHA256SUMS |
发布文件校验值 |
基础模型固定 revision 为 b6ed86275a6a5735884e208bfed95b445a684ca2,完整训练谱系和权重指纹见 provenance.json。继续训练时,可将仓库中的完整模型作为新的起点。
许可与致谢
本模型采用 Apache-2.0 许可证。感谢 Google DeepMind 提供 Gemma 基础模型与 assistant。来源归属与本次修改说明见 NOTICE。
- Downloads last month
- 1,050
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="shiqianyan/TangYuGe-gemma-4-12b-it-qat") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)