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

Model: wuyonghui0810/text-generation
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-09-29 16:19:14 +08:00
commit ae0db33715
15 changed files with 909819 additions and 0 deletions

47
.gitattributes vendored Normal file
View File

@@ -0,0 +1,47 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bin.* filter=lfs diff=lfs merge=lfs -text
*.bz2 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
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack 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
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
saved_model/**/* 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
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zstandard filter=lfs diff=lfs merge=lfs -text
*.tfevents* filter=lfs diff=lfs merge=lfs -text
*.db* filter=lfs diff=lfs merge=lfs -text
*.ark* filter=lfs diff=lfs merge=lfs -text
**/*ckpt*data* filter=lfs diff=lfs merge=lfs -text
**/*ckpt*.meta filter=lfs diff=lfs merge=lfs -text
**/*ckpt*.index filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.gguf* filter=lfs diff=lfs merge=lfs -text
*.ggml filter=lfs diff=lfs merge=lfs -text
*.llamafile* filter=lfs diff=lfs merge=lfs -text
*.pt2 filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
runs/
images/

217
README.md Normal file
View File

@@ -0,0 +1,217 @@
---
license: Apache License 2.0
language:
- zh
tasks:
- text-generation
frameworks: PyTorch
base_model:
- Qwen/Qwen2.5-0.5B-Instruct
base_model_relation: finetune
widgets:
- version: 1
task: text-generation
inputs:
- type: text
displayType: TextArea
validator:
max_words: 128
output:
displayType: Text
displayValueMapping: text
examples:
- name: 1
title: 示例1
inputs:
- name: text
data: 光的速度是多少?
datasets:
- wuyonghui0810/General-Knowledge
tags:
- 文本生成
- 科技探索
- ' 永辉'
---
# Qwen2.5-0.5B-Instruct 微调模型
## 模型概述
这是一个基于 Qwen2.5-0.5B-Instruct 模型的微调版本,使用 LoRA (低秩适应) 训练方法在特定领域数据上进行了定制化训练,涵盖数学、英语、科学、化学、物理等1000条自定义数据进行训练,以增强模型在特定任务上的性能。
## 模型详情
- **基础模型**: Qwen/Qwen2.5-0.5B-Instruct
- **模型类型**: qwen2_5
- **训练方法**: LoRA 微调
- **模板**: qwen2_5
- **模型大小**: 0.5B 参数
- **检查点**: checkpoint-186-merged
- **训练日期**: 2025-08-05
## 训练配置
- **最大序列长度**: 1024 个 token
- **学习率**: 1e-4
- **梯度累积步数**: 16
- **训练轮数**: 3
- **最终训练损失**: 0.0802
- **最终评估损失**: 0.00013508
## 调用方法
### 快速开始
这里提供了一个使用 wuyonghui0810/text-generation模型的代码片段,展示了如何加载分词器和模型以及如何生成内容。
```python
from modelscope import AutoModelForCausalLM, AutoTokenizer
model_name = "wuyonghui0810/text-generation"
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
prompt = "光的速度是多少?"
messages = [
{"role": "system", "content": "You are Vkey, created by yonghui, You are a helpful assistant."},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
**model_inputs,
max_new_tokens=512
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)
```
### 训练前
光的传播速度是多少:
- 在标准条件下,光的传播速度约为 299792458 米/秒。这个速度是恒定不变的,无论光源的位置、距离多远,都保持不变。这与物理定律和实验数据一致,证明了光速是宇宙中的基本物理常数。
### 训练后
- <<< 光的传播速度是多少
- <think>
- 用户问的是关于物理的问题:'光的传播速度是多少'。我需要根据物理学原理给出准确的答案。对于这个问题,正确的回答是:光在真空中的传播速度约为299,792,458米/秒。。
- </think>
- <answer>
- 光在真空中的传播速度约为299,792,458米/秒。
- </answer>
- <<< 光的速度
- <think>
- 用户问的是关于物理的问题:'光的速度'。我需要根据物理学原理给出准确的答案。对于这个问题,正确的回答是:光在真空中的速度约为299,792,458米/秒。。
- </think>
- <answer>
- 光在真空中的速度约为299,792,458米/秒。
- </answer>
## 微调方法
### 使用 Swift 进行训练认知微调
```bash
CUDA_VISIBLE_DEVICES=0 \
swift sft \
--torch_dtype 'float16' \
--model 'Qwen/Qwen2.5-0.5B-Instruct' \
--model_type 'qwen2_5' \
--template 'qwen2_5' \
--system 'You are Vkey, created by yonghui. You are a helpful assistant.' \
--dataset '/mnt/workspace/myipynb/transformers/datasets/training_data.jsonl' \
--max_length '1024' \
--init_weights 'True' \
--learning_rate '1e-4' \
--gradient_accumulation_steps '16' \
--eval_steps '500' \
--truncation_strategy 'delete' \
--report_to 'tensorboard' \
--add_version False \
--output_dir /mnt/workspace/myipynb/transformers/ms-swift/output/Qwen2.5-0.5B-Instruct/v0-20250805-170718 \
--logging_dir /mnt/workspace/myipynb/transformers/ms-swift/output/Qwen2.5-0.5B-Instruct/v0-20250805-170718/runs \
--ignore_args_error True \
--device_map 'cpu' \
> /mnt/workspace/myipynb/transformers/ms-swift/output/Qwen2.5-0.5B-Instruct/v0-20250805-170718/runs/run.log 2>&1 &
```
### 使用 swift 框架进行推理
```bash
CUDA_VISIBLE_DEVICES=0 \
swift infer \
--model /mnt/workspace/myipynb/transformers/ms-swift/output/Qwen2.5-0.5B-Instruct/v0-20250805-170718/checkpoint-186-merged \
--merge_lora true \
--infer_backend vllm \
--temperature 0 \
--max_new_tokens 2048
```
### 使用 swift 框架进行导出
--adapters 参数:用于导出适配器权重(如 LoRA),需要配合基础模型使用
--model 参数:用于导出完整模型,可以直接使用
由于 checkpoint-186-merged 是一个完整的合并模型(包含基础模型和适配器权重),所以应该使用 --model 参数。
方案一(使用的这个):
```bash
CUDA_VISIBLE_DEVICES=0 swift export \
--model /mnt/workspace/myipynb/transformers/ms-swift/output/Qwen2.5-0.5B-Instruct/v0-20250805-170718/checkpoint-186-merged \
--push_to_hub true \
--hub_model_id 'wuyonghui0810/text-generation' \
--hub_token 'ms-c9f5013e-8343-4d26-a53b-4d5a75f8a973' \
--use_hf false
```
方案二:
```bash
CUDA_VISIBLE_DEVICES=0 swift export \
--adapters /mnt/workspace/myipynb/transformers/ms-swift/output/Qwen2.5-0.5B-Instruct/v0-20250805-170718/checkpoint-186 \
--push_to_hub true \
--hub_model_id 'wuyonghui0810/text-generation' \
--hub_token 'ms-c9f5013e-8343-4d26-a53b-4d5a75f8a973' \
--use_hf false
```
### 关键推理参数
- `--model`: 用于导出完整模型,可以直接使用(或者--adapters:训练好的适配器/LoRA 权重路径)
- `--merge_lora true`: 将 LoRA 权重与基础模型合并
- `--infer_backend vllm`: 使用 vLLM 进行推理加速
- `--temperature 0`: 确定性输出(贪婪解码)
- `--max_new_tokens 2048`: 最大生成 token 数量
## 性能表现
- **评估样本每秒处理数**: 18.64
- **训练样本每秒处理数**: 5.045
- **内存使用**: 模型权重约 0.9276 GB
- **推理速度**: 使用 vLLM 和 CUDA 图形优化
## 系统要求
- **GPU**: 支持 CUDA 的 GPU(推荐)
- **显存**: 至少 4-8GB 以获得最佳性能
- **软件环境**:
- Python 3.11+
- Swift 框架
- vLLM 库
- CUDA 工具包
## 模型能力
此微调模型设计用于:
- 回答特定领域问题
- 准确遵循指令
- 提供一致且确定性的响应(temperature=0时)
- 处理长上下文输入(最多8192个token)
## 局限性
- 当 temperature=0 时响应是确定性的
- 性能取决于微调数据的质量
- 在训练领域外可能泛化能力有限
*如需技术支持或有关此模型的问题,请参考模型目录中包含的训练日志和配置文件。*

24
added_tokens.json Normal file
View File

@@ -0,0 +1,24 @@
{
"</tool_call>": 151658,
"<tool_call>": 151657,
"<|box_end|>": 151649,
"<|box_start|>": 151648,
"<|endoftext|>": 151643,
"<|file_sep|>": 151664,
"<|fim_middle|>": 151660,
"<|fim_pad|>": 151662,
"<|fim_prefix|>": 151659,
"<|fim_suffix|>": 151661,
"<|im_end|>": 151645,
"<|im_start|>": 151644,
"<|image_pad|>": 151655,
"<|object_ref_end|>": 151647,
"<|object_ref_start|>": 151646,
"<|quad_end|>": 151651,
"<|quad_start|>": 151650,
"<|repo_name|>": 151663,
"<|video_pad|>": 151656,
"<|vision_end|>": 151653,
"<|vision_pad|>": 151654,
"<|vision_start|>": 151652
}

331
args.json Normal file

File diff suppressed because one or more lines are too long

54
chat_template.jinja Normal file
View File

@@ -0,0 +1,54 @@
{%- if tools %}
{{- '<|im_start|>system\n' }}
{%- if messages[0]['role'] == 'system' %}
{{- messages[0]['content'] }}
{%- else %}
{{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
{%- endif %}
{{- "\n\n# 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' }}
{%- else %}
{{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
{%- endif %}
{%- endif %}
{%- for message in messages %}
{%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
{%- elif message.role == "assistant" %}
{{- '<|im_start|>' + message.role }}
{%- if message.content %}
{{- '\n' + message.content }}
{%- endif %}
{%- for tool_call in message.tool_calls %}
{%- if tool_call.function is defined %}
{%- set tool_call = tool_call.function %}
{%- endif %}
{{- '\n<tool_call>\n{"name": "' }}
{{- tool_call.name }}
{{- '", "arguments": ' }}
{{- tool_call.arguments | tojson }}
{{- '}\n</tool_call>' }}
{%- endfor %}
{{- '<|im_end|>\n' }}
{%- elif message.role == "tool" %}
{%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
{{- '<|im_start|>user' }}
{%- endif %}
{{- '\n<tool_response>\n' }}
{{- message.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' }}
{%- endif %}

55
config.json Normal file
View File

@@ -0,0 +1,55 @@
{
"architectures": [
"Qwen2ForCausalLM"
],
"attention_dropout": 0.0,
"bos_token_id": 151643,
"eos_token_id": 151645,
"hidden_act": "silu",
"hidden_size": 896,
"initializer_range": 0.02,
"intermediate_size": 4864,
"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"
],
"max_position_embeddings": 32768,
"max_window_layers": 21,
"model_type": "qwen2",
"num_attention_heads": 14,
"num_hidden_layers": 24,
"num_key_value_heads": 2,
"pad_token_id": 151643,
"rms_norm_eps": 1e-06,
"rope_scaling": null,
"rope_theta": 1000000.0,
"sliding_window": null,
"tie_word_embeddings": true,
"torch_dtype": "bfloat16",
"transformers_version": "4.53.1",
"use_cache": true,
"use_sliding_window": false,
"vocab_size": 151936
}

1
configuration.json Normal file
View File

@@ -0,0 +1 @@
{"framework": "pytorch", "task": "text-generation", "allow_remote": true}

14
generation_config.json Normal file
View File

@@ -0,0 +1,14 @@
{
"bos_token_id": 151643,
"do_sample": true,
"eos_token_id": [
151645,
151643
],
"pad_token_id": 151643,
"repetition_penalty": 1.1,
"temperature": 0.7,
"top_k": 20,
"top_p": 0.8,
"transformers_version": "4.53.1"
}

151388
merges.txt Normal file

File diff suppressed because it is too large Load Diff

3
model.safetensors Normal file
View File

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

31
special_tokens_map.json Normal file
View File

@@ -0,0 +1,31 @@
{
"additional_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|>"
],
"eos_token": {
"content": "<|im_end|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"pad_token": {
"content": "<|endoftext|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
}
}

757444
tokenizer.json Normal file

File diff suppressed because it is too large Load Diff

207
tokenizer_config.json Normal file
View File

@@ -0,0 +1,207 @@
{
"add_bos_token": false,
"add_prefix_space": false,
"added_tokens_decoder": {
"151643": {
"content": "<|endoftext|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151644": {
"content": "<|im_start|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151645": {
"content": "<|im_end|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151646": {
"content": "<|object_ref_start|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151647": {
"content": "<|object_ref_end|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151648": {
"content": "<|box_start|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151649": {
"content": "<|box_end|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151650": {
"content": "<|quad_start|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151651": {
"content": "<|quad_end|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151652": {
"content": "<|vision_start|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151653": {
"content": "<|vision_end|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151654": {
"content": "<|vision_pad|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151655": {
"content": "<|image_pad|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151656": {
"content": "<|video_pad|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151657": {
"content": "<tool_call>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151658": {
"content": "</tool_call>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151659": {
"content": "<|fim_prefix|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151660": {
"content": "<|fim_middle|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151661": {
"content": "<|fim_suffix|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151662": {
"content": "<|fim_pad|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151663": {
"content": "<|repo_name|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151664": {
"content": "<|file_sep|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
}
},
"additional_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|>"
],
"bos_token": null,
"clean_up_tokenization_spaces": false,
"eos_token": "<|im_end|>",
"errors": "replace",
"extra_special_tokens": {},
"model_max_length": 131072,
"pad_token": "<|endoftext|>",
"split_special_tokens": false,
"tokenizer_class": "Qwen2Tokenizer",
"unk_token": null
}

1
vocab.json Normal file

File diff suppressed because one or more lines are too long