初始化项目,由ModelHub XC社区提供模型

Model: zzoceanpie/Qwen3-1.7B-Yukari-DPO
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-06-16 06:22:16 +08:00
commit 8d763f2df2
9 changed files with 333 additions and 0 deletions

37
.gitattributes vendored Normal file
View File

@@ -0,0 +1,37 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text
Qwen3-1.7B-Yukari-DPO-f16.gguf filter=lfs diff=lfs merge=lfs -text
tokenizer.json filter=lfs diff=lfs merge=lfs -text

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:fe2dc9c4cc221ec413c79976d737ae6f430d7e8bb525ec2f2cf0032d76106df8
size 3447348928

93
README.md Normal file
View File

@@ -0,0 +1,93 @@
---
base_model: Qwen/Qwen3-1.7B
library_name: transformers
tags:
- qlora
- roleplay
- qwen
- dpo
- sft
- touhou
- character-roleplay
- synthetic-data
- generated_from_trainer
language:
- zh
license: apache-2.0
---
# Qwen3-1.7B-Yukari-DPO
八云紫 (Yukari Yakumo) 角色扮演模型 — DPO 偏好对齐版。
在 SFT-v2 基础上用 DPO (Direct Preference Optimization) 做偏好对齐,消除攻击性输出、减少冗长偏好、降低公式化生成。
## 模型信息
| 项目 | 值 |
|------|-----|
| 基座 | [Qwen/Qwen3-1.7B](https://huggingface.co/Qwen/Qwen3-1.7B) |
| 起点 | [Qwen3-1.7B-Yukari-SFT-v2](https://hf.co/zzoceanpie/Qwen3-1.7B-Yukari-SFT-v2) (r=32, a=64) |
| 方法 | QLoRA 4-bit NF4 + DPO (sigmoid loss) |
| LoRA | **r=32, alpha=64**, target: q/k/v/o/gate/up/down proj |
| 训练 | 3 epochs, beta=0.1, lr=1e-6, seed=42 |
| DPO Loss | 0.693 to 0.658 |
| DPO Margin | +0.072 |
| DPO Acc | 87.5% |
| 格式 | Merged bf16 safetensors + GGUF F16 |
## 系列模型
| 模型 | LoRA | 方法 | 版本 |
|------|------|------|------|
| [Qwen3-1.7B-Yukari-SFT](https://hf.co/zzoceanpie/Qwen3-1.7B-Yukari-SFT) | r=8, a=8 | SFT | v1 |
| [Qwen3-1.7B-Yukari-SFT-v2](https://hf.co/zzoceanpie/Qwen3-1.7B-Yukari-SFT-v2) | r=32, a=64 | SFT | v2 |
| **Qwen3-1.7B-Yukari-DPO** (本模型) | r=32, a=64 | SFT+DPO | v2+DPO |
## 用法
模型输入格式为 `[情绪标签]\n用户输入`标签控制八云紫的回复语气。8 维 Plutchik 情绪向量离散化:喜悦/愤怒/悲伤/恐惧/厌恶/惊讶/信任/期待,每维取「无」「极轻微」「轻微」「中轻度」「中度」「较强烈」「强烈」「极强烈」。
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained(
"zzoceanpie/Qwen3-1.7B-Yukari-DPO",
torch_dtype="auto", device_map="auto", trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained("zzoceanpie/Qwen3-1.7B-Yukari-DPO")
tags = "[<|中度喜悦|><|轻微愤怒|><|轻微悲伤|><|无恐惧|><|无厌恶|><|无惊讶|><|轻微信任|><|中度期待|>]"
prompt = f"{tags}\n你觉得人类最有趣的地方是什么?"
messages = [{"role": "user", "content": prompt}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=128, temperature=0.8)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```
### GGUF
```python
from llama_cpp import Llama
model = Llama(model_path="Qwen3-1.7B-Yukari-SFT-f16.gguf", n_ctx=2048, n_gpu_layers=-1)
response = model.create_chat_completion(
messages=[{"role": "user", "content": prompt}],
max_tokens=200, temperature=0.8
)
print(response["choices"][0]["message"]["content"])
```
## 许可 / License
- 模型权重: Apache 2.0
- 角色「八云紫」版权: (C) 上海爱丽丝幻乐团 (Team Shanghai Alice) / ZUN
- 本模型是东方Project的二次创作/粉丝作品。遵循 [东方Project二次创作指南](https://touhou-project.news/guidelines_en/)。
- 训练数据: [yukari-synthetic](https://hf.co/datasets/zzoceanpie/yukari-synthetic) (Apache 2.0)
- *This is a fan-made derivative work based on Touhou Project. Touhou Project is (C) Team Shanghai Alice / ZUN.*
> This model is a fan-made derivative work based on Touhou Project.
> Touhou Project is (C) Team Shanghai Alice / ZUN.
> Please refer to the [official guidelines](https://touhou-project.news/guidelines_en/) for Touhou fan content.

89
chat_template.jinja Normal file
View File

@@ -0,0 +1,89 @@
{%- if tools %}
{{- '<|im_start|>system\n' }}
{%- if messages[0].role == 'system' %}
{{- messages[0].content + '\n\n' }}
{%- endif %}
{{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
{%- for tool in tools %}
{{- "\n" }}
{{- tool | tojson }}
{%- endfor %}
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
{%- else %}
{%- if messages[0].role == 'system' %}
{{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
{%- endif %}
{%- endif %}
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
{%- for message in messages[::-1] %}
{%- set index = (messages|length - 1) - loop.index0 %}
{%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
{%- set ns.multi_step_tool = false %}
{%- set ns.last_query_index = index %}
{%- endif %}
{%- endfor %}
{%- for message in messages %}
{%- if message.content is string %}
{%- set content = message.content %}
{%- else %}
{%- set content = '' %}
{%- endif %}
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
{%- elif message.role == "assistant" %}
{%- set reasoning_content = '' %}
{%- if message.reasoning_content is string %}
{%- set reasoning_content = message.reasoning_content %}
{%- else %}
{%- if '</think>' in content %}
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
{%- endif %}
{%- endif %}
{%- if loop.index0 > ns.last_query_index %}
{%- if loop.last or (not loop.last and reasoning_content) %}
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
{%- else %}
{{- '<|im_start|>' + message.role + '\n' + content }}
{%- endif %}
{%- else %}
{{- '<|im_start|>' + message.role + '\n' + content }}
{%- endif %}
{%- if message.tool_calls %}
{%- for tool_call in message.tool_calls %}
{%- if (loop.first and content) or (not loop.first) %}
{{- '\n' }}
{%- endif %}
{%- if tool_call.function %}
{%- set tool_call = tool_call.function %}
{%- endif %}
{{- '<tool_call>\n{"name": "' }}
{{- tool_call.name }}
{{- '", "arguments": ' }}
{%- if tool_call.arguments is string %}
{{- tool_call.arguments }}
{%- else %}
{{- tool_call.arguments | tojson }}
{%- endif %}
{{- '}\n</tool_call>' }}
{%- endfor %}
{%- endif %}
{{- '<|im_end|>\n' }}
{%- elif message.role == "tool" %}
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
{{- '<|im_start|>user' }}
{%- endif %}
{{- '\n<tool_response>\n' }}
{{- content }}
{{- '\n</tool_response>' }}
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
{{- '<|im_end|>\n' }}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
{{- '<|im_start|>assistant\n' }}
{%- if enable_thinking is defined and enable_thinking is false %}
{{- '<think>\n\n</think>\n\n' }}
{%- endif %}
{%- endif %}

63
config.json Normal file
View File

@@ -0,0 +1,63 @@
{
"architectures": [
"Qwen3ForCausalLM"
],
"attention_bias": false,
"attention_dropout": 0.0,
"bos_token_id": 151643,
"dtype": "bfloat16",
"eos_token_id": 151645,
"head_dim": 128,
"hidden_act": "silu",
"hidden_size": 2048,
"initializer_range": 0.02,
"intermediate_size": 6144,
"layer_types": [
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention"
],
"max_position_embeddings": 40960,
"max_window_layers": 28,
"model_type": "qwen3",
"num_attention_heads": 16,
"num_hidden_layers": 28,
"num_key_value_heads": 8,
"pad_token_id": null,
"rms_norm_eps": 1e-06,
"rope_parameters": {
"rope_theta": 1000000,
"rope_type": "default"
},
"sliding_window": null,
"tie_word_embeddings": true,
"transformers_version": "5.5.1",
"use_cache": true,
"use_sliding_window": false,
"vocab_size": 151936
}

13
generation_config.json Normal file
View File

@@ -0,0 +1,13 @@
{
"bos_token_id": 151643,
"do_sample": true,
"eos_token_id": [
151645,
151643
],
"pad_token_id": 151643,
"temperature": 0.6,
"top_k": 20,
"top_p": 0.95,
"transformers_version": "5.5.1"
}

3
model.safetensors Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e5b97935de59be98a9a1de98dc4088f0f3f1a01790e9108aeedf4ddddf83f2bc
size 3441185608

3
tokenizer.json Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:be75606093db2094d7cd20f3c2f385c212750648bd6ea4fb2bf507a6a4c55506
size 11422650

29
tokenizer_config.json Normal file
View File

@@ -0,0 +1,29 @@
{
"add_prefix_space": false,
"backend": "tokenizers",
"bos_token": null,
"clean_up_tokenization_spaces": false,
"eos_token": "<|im_end|>",
"errors": "replace",
"extra_special_tokens": [
"<|im_start|>",
"<|im_end|>",
"<|object_ref_start|>",
"<|object_ref_end|>",
"<|box_start|>",
"<|box_end|>",
"<|quad_start|>",
"<|quad_end|>",
"<|vision_start|>",
"<|vision_end|>",
"<|vision_pad|>",
"<|image_pad|>",
"<|video_pad|>"
],
"is_local": false,
"model_max_length": 131072,
"pad_token": "<|endoftext|>",
"split_special_tokens": false,
"tokenizer_class": "Qwen2Tokenizer",
"unk_token": null
}