Instructions to use aikexue170/rewrite2-4b-fp8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use aikexue170/rewrite2-4b-fp8 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="aikexue170/rewrite2-4b-fp8") 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("aikexue170/rewrite2-4b-fp8") model = AutoModelForMultimodalLM.from_pretrained("aikexue170/rewrite2-4b-fp8", 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 aikexue170/rewrite2-4b-fp8 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "aikexue170/rewrite2-4b-fp8" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "aikexue170/rewrite2-4b-fp8", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/aikexue170/rewrite2-4b-fp8
- SGLang
How to use aikexue170/rewrite2-4b-fp8 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 "aikexue170/rewrite2-4b-fp8" \ --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": "aikexue170/rewrite2-4b-fp8", "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 "aikexue170/rewrite2-4b-fp8" \ --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": "aikexue170/rewrite2-4b-fp8", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use aikexue170/rewrite2-4b-fp8 with Docker Model Runner:
docker model run hf.co/aikexue170/rewrite2-4b-fp8
Rewrite2 4B · FP8 W8A8
中文小说改写专用 4B 模型。Qwen3.5-4B + V12.5 rewrite-only LoRA 合并后量化;只训练改写,没有扩写。 本仓库是 FP8 W8A8,约 5.5 GB(5.15 GiB)。ModelOpt 0.47.0 FP8 W8A8(e4m3),校准 128 条 V12.5 原文;排除 vision、MTP、linear_attn 的 conv1d / in_proj_a / in_proj_b 和 lm_head/embed_tokens。
长度与切分
单段原文建议 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。请直接使用下面的固定提示词:
你是一位小说编辑,正在帮作者改文。请把下面这段小说片段改写成自然、有作者个人风格的中文,保持情节走向、人物设定和主要事件不变。无论原文是否通顺、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)
vllm serve /path/to/rewrite2-4B-fp8 \
--served-model-name rewrite2-4b-fp8 \
--trust-remote-code \
--max-model-len 4096 \
--gpu-memory-utilization 0.40
vLLM 会自动识别 ModelOpt 的 FP8 W8A8 配置;如果提示未知量化,请加 --quantization modelopt_fp8。
格式与显存
| 项 | 本仓库 |
|---|---|
| 版本 | FP8 W8A8 |
| 权重 | 约 5.5 GB(5.15 GiB) |
| 推理权重显存 | 约 5.35 GiB 权重 |
| 建议 | 16GB 级显卡;NVFP4 在 Blackwell 上收益最大 |
| 推理栈 | vLLM(ModelOpt 量化格式) |
model.safetensors、config.json、hf_quant_config.json、generation_config.jsontokenizer.json、tokenizer_config.json、chat_template.jinjapreprocessor_config.json、video_preprocessor_config.json、processor_config.jsonINSTRUCTION_rewrite.txt、README.md、SHA256SUMS
验证
同一条 646 字 heldout 输入(temperature 0.7、seed 42、max_tokens 800、repetition_penalty 1.08):
- FP8 W8A8:输出 903 字,改写率 42.3%,
dup80,自然收尾 - 两条都正常加载并生成;量化后的差异主要是输出长度和照抄率,不是格式错误
训练概况
- 基座:
Qwen/Qwen3.5-4B,revision851bf6e806efd8d0a36b00ddf55e13ccb7b8cd0a - 数据:V12.5 clean,25,647 条纯 rewrite;LoRA rank 32、1 epoch、2,934 steps
- 量化:ModelOpt 0.47.0,校准 128 条 V12.5 原文;没有 KV cache 量化
全部版本(4B 系列)
| 格式 | 体积 | Hugging Face | ModelScope |
|---|---|---|---|
| BF16 合并 | 8.47 GiB | rewrite2-4b-bf16 | rewrite2-4b-bf16 |
| FP8 W8A8 | 5.15 GiB | rewrite2-4b-fp8 | rewrite2-4b-fp8 |
| NVFP4 W4A4 | 3.70 GiB | rewrite2-4b-nvfp4 | rewrite2-4b-nvfp4 |
| GGUF Q8_0 / Q4_K_M | 4.48 GB / 2.71 GB | rewrite2-4b-gguf | rewrite2-4b-gguf |
4B 是独立实验线,和 27B Rewrite2 权重不通用;27B 见 rewrite2-27b-bf16。
已知限制
- 4B 的容量有限,不要按 27B 的质量预期使用;复杂长段、多人物场景仍建议人工校对。
- 默认压缩改写:800–950 字输入的训练目标中位输出约 540 字(约 0.63 倍);需要全文覆盖时请切段,并在提示词后明确要求覆盖全文。
- 有概率复读或死循环。部署时启用重复惩罚(建议 1.08 起步),同时设置硬性
max_tokens和超时。 - 本版只训练了改写,没有扩写能力;不要使用扩写提示词。
- 视觉塔保留在权重里,但没有做图像训练;本仓库只保证文本改写。
- 低比特量化会放大压缩和复读倾向;Q4_K_M 比 Q8_0 更明显,正式使用前请按自己的文本验收。
- 不保证通用聊天、代码、数学、翻译或跨章节长篇一致性。
- Downloads last month
- -