Text Generation
Transformers
Safetensors
Chinese
qwen3
rewrite4
rewrite4-medium
novel-rewrite
chinese
web-novel
jev
mtp
dflash
speculative-decoding
draft-model
text-generation-inference
Run this model with HF Jobs
Run beileng/rewrite4-medium-dflash2 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/rewrite4-medium-dflash2. 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/rewrite4-medium-dflash2 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/rewrite4-medium-dflash2. 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/rewrite4-medium-dflash2. 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.
Instructions to use beileng/rewrite4-medium-dflash2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use beileng/rewrite4-medium-dflash2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="beileng/rewrite4-medium-dflash2")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("beileng/rewrite4-medium-dflash2") model = AutoModel.from_pretrained("beileng/rewrite4-medium-dflash2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use beileng/rewrite4-medium-dflash2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "beileng/rewrite4-medium-dflash2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "beileng/rewrite4-medium-dflash2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/beileng/rewrite4-medium-dflash2
- SGLang
How to use beileng/rewrite4-medium-dflash2 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 "beileng/rewrite4-medium-dflash2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "beileng/rewrite4-medium-dflash2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "beileng/rewrite4-medium-dflash2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "beileng/rewrite4-medium-dflash2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use beileng/rewrite4-medium-dflash2 with Docker Model Runner:
docker model run hf.co/beileng/rewrite4-medium-dflash2
docs: compact SVD tables and add post-train SVD analysis
Browse files142 unmodified lines1431441451461471481491501511521531541551561571461471481491501511521531541551561571581591607 unmodified lines168169170171172173174175176177178179180181182183184185186187188189190191192142 unmodified lines
后来 debug 的时候,我对第一次 R64 权重做了**奇异值分解(SVD)和能量谱分析**,发现了如下表的有趣迹象:
| 模块名 | 层数 | 实测有效秩 | R16 能量 | R32 能量 | R48 能量 | 二训拟设 Rank | 拟设档位保留能量 | 核对结论 ||---|---:|---:|---:|---:|---:|---:|---:|---|| `in_proj_z` | 48 | 4.3 | 94.7% | 97.7% | 99.2% | **16** | 94.7% | 完美(3.7× 有效秩,无过调) || `gate_proj` | 64 | 4.5 | 95.0% | 97.7% | 99.2% | **16** | 95.0% | 完美(3.6× 有效秩,无过调) || `q_proj` | 16 | 6.3 | 93.2% | 97.4% | 99.1% | **16** | 93.2% | 完美(2.5× 有效秩,无过调) || `in_proj_qkv` | 48 | 7.1 | 91.4% | 96.2% | 98.6% | **16** | 91.4% | 完美(2.3× 有效秩,无过调) || `up_proj` | 64 | 13.8 | 84.6% | 93.1% | 97.5% | **32** | 93.1% | 完美(2.3× 有效秩,无过调) || `v_proj` | 16 | 17.0 | 83.9% | 93.8% | 98.1% | **32** | 93.8% | 完美(1.9× 有效秩,无过调) || `k_proj` | 16 | 18.4 | 80.9% | 91.9% | 97.2% | **32** | 91.9% | 完美(1.7× 有效秩,无过调) || `down_proj` | 64 | 18.9 | 80.9% | 91.3% | 96.8% | **32** | 91.3% | 完美(1.7× 有效秩,无过调) || `o_proj` | 16 | 23.3 | 79.0% | 90.8% | 96.7% | **32** | 90.8% | 恰当(1.4× 有效秩,刚好给全局逻辑去尾噪) || `out_proj` | 48 | 32.0 | 68.8% | 85.1% | 94.4% | **48** | 94.4% | 完美(1.5× 有效秩,满血托住文笔张力) || 模块 | 层数 | R64 有效秩 | 二训 Rank | 对应档位保留能量 ||---|---:|---:|---:|---:|| `in_proj_z` | 48 | 4.3 | **16** | 94.7% || `gate_proj` | 64 | 4.5 | **16** | 95.0% || `q_proj` | 16 | 6.3 | **16** | 93.2% || `in_proj_qkv` | 48 | 7.1 | **16** | 91.4% || `up_proj` | 64 | 13.8 | **32** | 93.1% || `v_proj` | 16 | 17.0 | **32** | 93.8% || `k_proj` | 16 | 18.4 | **32** | 91.9% || `down_proj` | 64 | 18.9 | **32** | 91.3% || `o_proj` | 16 | 23.3 | **32** | 90.8% || `out_proj` | 48 | 32.0 | **48** | 94.4% |
可以看到:输入相关的门控等模块,有效 rank 很低,连十位数都没到;KV 相关的 proj 有效维度也就十几的水平;只有 `out_proj` 有效 rank 极高,到达了 32 的水平。也就是说第一次训练用的统一 R64,绝大部分 rank 到最后都仅仅是在引入高维噪声,巨大的噪声直接把模型的注意力和智力炼爆了。而 `o_proj` 和 `out_proj` 如此高,说明文风改写高度依赖输出层,训练信号在这里吸收得最多——这也印证了文学改写任务对模型的前级模块真的是个低秩任务,仅在部分输出模块高秩。
7 unmodified lines
经过这套配方训练的模型,不仅保持了极其优秀的文风水平,而且有效保护了原模型的注意力和智力。虽然它还是有概率出小问题,但我认为 `rewrite4-medium` 已经到达了速度-性能的最佳平衡点——为了一点随机性出的小毛病去引入更雷霆的思考,我觉得很不值当。后续的 `rewrite4-large` 有着更先进的基模、更大的参数量和更准确的直觉,应该会在“不犯错”上表现得更加出色。
### 二训最终版 SVD 复查与下一代配方展望
对本次发布的 `R16/32/48` 最终权重同样做了 SVD 复查(与前表同口径):
| 模块 | 二训 Rank | 实测有效秩 | Top-8 能量 | 95% 能量秩 | `\|\|ΔW\|\|_F` 变化 *(vs R64)* ||---|---:|---:|---:|---:|---:|| `in_proj_z` | 16 | **1.7** | 98.6% | 2.2 | `-39%` || `gate_proj` | 16 | **1.6** | 99.1% | 2.5 | `-33%` || `q_proj` | 16 | **2.0** | 98.7% | 3.0 | `-42%` || `in_proj_qkv` | 16 | **2.2** | 97.9% | 4.1 | `-42%` || `up_proj` | 32 | **4.2** | 93.2% | 10.5 | `-15%` || `v_proj` | 32 | **7.2** | 87.3% | 14.8 | `-34%` || `k_proj` | 32 | **9.7** | 83.0% | 18.7 | `-20%` || `down_proj` | 32 | **8.9** | 84.5% | 17.9 | `-22%` || `o_proj` | 32 | **9.5** | 84.1% | 18.2 | `-24%` || `out_proj` | 48 | **18.1** | 69.1% | 33.2 | **`-6%`** |
可以看到,前级 4 个输入/门控模块的有效秩已收敛到 `1.6~2.2`、扰动范数大幅下降 `33%~42%`,高维尾噪基本被剃净;而承载文风与张力的 `out_proj` 更新幅度几乎无损(仅 `-6%`)。基于这份复查数据,下一代 `rewrite4-large` 计划进一步尝试四档配方:**前级 4 模块下探至 `r=8`**(保留任务路由开关但进一步降噪)、**`up_proj` 降至 `r=16`**、**`v / k / down / o_proj` 保持 `r=32`**、**`out_proj` 继续给足 `r=48`**。
### MTP 蒸馏与量化配方
- **MTP 投机头蒸馏**:使用新骨干 FP8 自身在 `temp=1.0 / top_p=0.95` 下采样生成 `1,600 train + 128 val` 的 on-policy 数据,做纯 **Top-128 Forward-KL 蒸馏**(`ce_alpha=0`,`lr=3e-5`,1 epoch / 200 步)并重新注入 BF16 / FP8 / NVFP4 与全部 GGUF 权重。实测 FP8 + MTP `k=2`(`temp=1.0`):单路 `59.4 tok/s`(���均接受长度 `2.16`),8 并发总吞吐 `318.6 tok/s`(`k=2` 综合效率优于 `k=3`)。README.md+31-12