Run this model with HF Jobs

Run beileng/rewrite2-4b-bf16 on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs and TRL to fine-tune https://huggingface.co/beileng/rewrite2-4b-bf16. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/beileng/rewrite2-4b-bf16 on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

Evaluate on a benchmark

Use HF Jobs to evaluate https://huggingface.co/beileng/rewrite2-4b-bf16. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.

Quantize for lower memory use

Use HF Jobs to create a 4-bit version of https://huggingface.co/beileng/rewrite2-4b-bf16. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
File size: 6,228 Bytes
06506de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c5371bb
06506de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c5371bb
 
 
 
06506de
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
language:
- zh
license: apache-2.0
library_name: transformers
pipeline_tag: text-generation
tags:
- rewrite2
- novel-rewrite
- qwen3.5
- 4b
- bf16
---

# Rewrite2 4B · BF16

> 中文小说**改写专用** 4B 模型。Qwen3.5-4B + V12.5 rewrite-only LoRA 合并,只训练改写,没有扩写。
> 本仓库是未量化的 BF16 合并权重(2 个 safetensors 分片,约 9.1 GB / 8.45 GiB),作为 FP8 / NVFP4 / GGUF 的质量基准。

## 长度与切分

> **单段原文建议 500–1,200 汉字。** 1,200–1,500 汉字可用,但输出会更压缩、连续照抄和重复风险会上升;超过 1,500 汉字建议按场景/段落切成 500–700 字后再逐段输入。模型默认是**压缩式改写**,不是等长改写。
>
> 在 1,000–1,300 字的 heldout 小测里,改写率和 700–1,000 字基本一致;长输入的主要代价不是“改不动”,而是输出变短(约为原文的 0.6–0.9 倍)和连续照抄变多。

| 原文长度 | 建议 |
|---|---|
| ≤ 1,200 字 | 单段直接输入 |
| 1,200–1,500 字 | 可用;`max_tokens` 给到 1500–1600,抽查长度比和照抄 |
| > 1,500 字 | 按场景/段落切 500–700 字,逐段改写后拼接 |

## 必用提示词

这个模型是任务特化 SFT,不是通用润色助手。训练时只有一条 user 消息,没有 system prompt,也没有 thinking。请直接使用下面的固定提示词:

```text
你是一位小说编辑,正在帮作者改文。请把下面这段小说片段改写成自然、有作者个人风格的中文,保持情节走向、人物设定和主要事件不变。无论原文是否通顺、AI味是轻是重,都要重新组织语言,禁止连续照抄原文超过15字;原文越好,越要用同义改写而不是照搬。

原文:
```

拼接方式:`INSTRUCTION_rewrite.txt` 的内容 + 原文,直接作为一条 user 消息。仓库内附 `INSTRUCTION_rewrite.txt`。**不要**把 `enable_thinking` 当成开关:模板已经固定为空 `<think>\n\n</think>\n\n`,模型只输出正文。

## 推荐参数

| 项目 | 建议 |
|---|---|
| temperature | `0.7`;固定复现实验用 `0` |
| top_p | `0.9` |
| top_k | `50`(vLLM / llama.cpp 支持时) |
| max_tokens | 改写 1200;1,200–1,500 字输入用 1500–1600 |
| 重复惩罚 | `repetition_penalty=1.08` 起步;llama.cpp `--repeat-penalty 1.08` |
| 原文长度 | 单段 500–1,200 汉字;超过就切 |

看 `finish_reason`:`stop` 是自然收尾,`length` 是撞到上限,需要调大或切短。重复惩罚只能降低复读概率,不能完全消除。


## 快速开始(vLLM)

```bash
vllm serve /path/to/rewrite2-4B-bf16 \
  --served-model-name rewrite2-4b \
  --trust-remote-code \
  --max-model-len 4096 \
  --gpu-memory-utilization 0.50
```

```python
from pathlib import Path
from openai import OpenAI

client = OpenAI(base_url="http://127.0.0.1:8000/v1", api_key="EMPTY")
instruction = Path("INSTRUCTION_rewrite.txt").read_text(encoding="utf-8")
text = """把这里换成需要改写的小说原文。"""
response = client.chat.completions.create(
    model="rewrite2-4b",
    messages=[{"role": "user", "content": instruction + text}],
    temperature=0.7,
    top_p=0.9,
    max_tokens=1200,
    extra_body={"repetition_penalty": 1.08, "top_k": 50},
)
print(response.choices[0].message.content)
```

## 格式与显存

| 项 | 本仓库 |
|---|---|
| 版本 | BF16 合并权重 |
| 权重 | 约 9.1 GB(8.45 GiB),2 个分片 |
| 推理权重显存 | 约 8.5 GiB |
| 建议 | 16GB 级显卡可跑;24GB 更宽裕 |
| 推理栈 | vLLM / Transformers(Qwen3.5 架构) |

- `model-00001-of-00002.safetensors`、`model-00002-of-00002.safetensors`
- `model.safetensors.index.json`、`config.json`、`generation_config.json`
- `tokenizer.json`、`tokenizer_config.json`、`chat_template.jinja`
- `preprocessor_config.json`、`video_preprocessor_config.json`、`processor_config.json`
- `INSTRUCTION_rewrite.txt`、`README.md`、`SHA256SUMS`

## 训练概况

- 基座:`Qwen/Qwen3.5-4B`,revision `851bf6e806efd8d0a36b00ddf55e13ccb7b8cd0a`
- 数据:V12.5 clean,25,647 条纯 rewrite;2048 长度下可用 23,470 条
- 方法:LoRA rank 32、alpha 64、1 epoch、`max_length=2048`、completion-only loss
- 训练:2,934 steps,final train_loss 1.214,mean token accuracy 0.718
- 合并:`merge_and_unload()` 后导出 BF16;模板固定无思考

## 全部版本(4B 系列)

| 格式 | 体积 | Hugging Face | ModelScope |
|---|---:|---|---|
| BF16 合并 | 8.47 GiB | [rewrite2-4b-bf16](https://huggingface.co/aikexue170/rewrite2-4b-bf16) | [rewrite2-4b-bf16](https://modelscope.cn/models/alkaid55555/rewrite2-4b-bf16) |
| FP8 W8A8 | 5.15 GiB | [rewrite2-4b-fp8](https://huggingface.co/aikexue170/rewrite2-4b-fp8) | [rewrite2-4b-fp8](https://modelscope.cn/models/alkaid55555/rewrite2-4b-fp8) |
| NVFP4 W4A4 | 3.70 GiB | [rewrite2-4b-nvfp4](https://huggingface.co/aikexue170/rewrite2-4b-nvfp4) | [rewrite2-4b-nvfp4](https://modelscope.cn/models/alkaid55555/rewrite2-4b-nvfp4) |
| GGUF Q8_0 / Q4_K_M | 4.48 GB / 2.71 GB | [rewrite2-4b-gguf](https://huggingface.co/aikexue170/rewrite2-4b-gguf) | [rewrite2-4b-gguf](https://modelscope.cn/models/alkaid55555/rewrite2-4b-gguf) |

4B 是独立实验线,和 27B Rewrite2 权重不通用;27B 见 [rewrite2-27b-bf16](https://huggingface.co/aikexue170/rewrite2-27b-bf16)。

## 已知限制

- 4B 的容量有限,不要按 27B 的质量预期使用;复杂长段、多人物场景仍建议人工校对。
- 默认压缩改写:800–950 字输入的训练目标中位输出约 540 字(约 0.63 倍);需要全文覆盖时请切段,并在提示词后明确要求覆盖全文。
- 有概率复读或死循环。部署时启用重复惩罚(建议 1.08 起步),同时设置硬性 `max_tokens` 和超时。
- 本版只训练了改写,**没有扩写能力**;不要使用扩写提示词。
- 视觉塔保留在权重里,但没有做图像训练;本仓库只保证文本改写。
- 低比特量化会放大压缩和复读倾向;Q4_K_M 比 Q8_0 更明显,正式使用前请按自己的文本验收。
- 不保证通用聊天、代码、数学、翻译或跨章节长篇一致性。