Document fp32/fp16/int8 variants and measured agreement
Browse files
README.md
CHANGED
|
@@ -17,10 +17,10 @@ tags:
|
|
| 17 |
|
| 18 |
在一条「带脚手架的长回复」里找出**正文区间**。输入整条回复(可能包含 `<dream_plot>` 之类的设定块、`<Status_block>` 之类的状态块、结尾选项块等),输出正文那一段连续的字符区间 `[start, end)`。不是逐 token 分类,也不改写文本:`text[start:end]` 就是正文原文。
|
| 19 |
|
| 20 |
-
- 基座:`alphaedge-ai/mmBERT-small-zho-32768`(ModernBERT,hidden 384 / 22 层 / vocab 32768
|
| 21 |
-
-
|
|
|
|
| 22 |
- 清洗后子集上重训的版本见 [GoForceX/body-locator-small-v1-curated](https://huggingface.co/GoForceX/body-locator-small-v1-curated)。
|
| 23 |
-
- 模型参数量 57,529,988,单文件 660 MB(fp32)。
|
| 24 |
|
| 25 |
## 输入 / 输出
|
| 26 |
|
|
@@ -36,10 +36,15 @@ tags:
|
|
| 36 |
## 快速开始
|
| 37 |
|
| 38 |
```bash
|
| 39 |
-
# 1) 取回仓库(约
|
| 40 |
hf download GoForceX/body-locator-small-v1 --local-dir body-locator-small-v1
|
| 41 |
cd body-locator-small-v1
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
# 2) 装依赖(Python >= 3.10;有 GPU 会自动用 CUDA,否则 CPU 也能跑)
|
| 44 |
python -m pip install -r requirements.txt
|
| 45 |
|
|
@@ -50,6 +55,24 @@ python predict.py --checkpoint best.pt --input examples/example_input.txt --outp
|
|
| 50 |
|
| 51 |
`infer.py` 是同一套逻辑的另一种入口,不落盘、直接回显结果:
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
```bash
|
| 54 |
python infer.py --checkpoint best.pt --input examples/example_input.txt
|
| 55 |
# => {"span": [151, 448], "char_count": 718, "token_count": 522, "chunk_count": 1, "time_ms": 319}
|
|
@@ -133,6 +156,18 @@ DEV(329 篇中 328 篇可评估,1 篇超过 8,192 token 预算):
|
|
| 133 |
|
| 134 |
同口径 V5 基线为 295/324 Exact、误删 5,432 字、误留 6,790 字。选模型时先看 Exact,同分比字符 F1;上线更应关注误删。
|
| 135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
## 已知限制
|
| 137 |
|
| 138 |
- **中文 RP / 长回复场景**训练出来的模型,其他文体(邮件头、论坛签名等)可以跑通但精度不保证。
|
|
|
|
| 17 |
|
| 18 |
在一条「带脚手架的长回复」里找出**正文区间**。输入整条回复(可能包含 `<dream_plot>` 之类的设定块、`<Status_block>` 之类的状态块、结尾选项块等),输出正文那一段连续的字符区间 `[start, end)`。不是逐 token 分类,也不改写文本:`text[start:end]` 就是正文原文。
|
| 19 |
|
| 20 |
+
- 基座:`alphaedge-ai/mmBERT-small-zho-32768`(ModernBERT,54.8 M 参数 / hidden 384 / 22 层 / vocab 32768)。本模型 57.5 M 参数(多了全局块、字符嵌入和起止头)。
|
| 21 |
+
- 同一份权重三种精度:`best.pt`(fp32,230 MB)、`best_fp16.pt`(115 MB)、`best_int8.pt`(97 MB),外加分词器和推理代码。
|
| 22 |
+
- **只传了最好的那一轮**:不含 `last.pt`、优化器状态、训练日志和历史预测。原始训练产物 660 MB,其中约 430 MB 是 AdamW 的一、二阶矩,推理用不到,已剥离。
|
| 23 |
- 清洗后子集上重训的版本见 [GoForceX/body-locator-small-v1-curated](https://huggingface.co/GoForceX/body-locator-small-v1-curated)。
|
|
|
|
| 24 |
|
| 25 |
## 输入 / 输出
|
| 26 |
|
|
|
|
| 36 |
## 快速开始
|
| 37 |
|
| 38 |
```bash
|
| 39 |
+
# 1) 取回仓库(三种精度全拿约 440 MB;只要 fp16 可加 --include "best_fp16.pt" 等)
|
| 40 |
hf download GoForceX/body-locator-small-v1 --local-dir body-locator-small-v1
|
| 41 |
cd body-locator-small-v1
|
| 42 |
|
| 43 |
+
# 只要小体积权重时:
|
| 44 |
+
# hf download GoForceX/body-locator-small-v1 --local-dir body-locator-small-v1 \
|
| 45 |
+
# --include "best_fp16.pt" "infer.py" "checkpoint.py" "model.py" "encode.py" \
|
| 46 |
+
# "structure.py" "transition.py" "span.py" "data.py" "tokenizer/*"
|
| 47 |
+
|
| 48 |
# 2) 装依赖(Python >= 3.10;有 GPU 会自动用 CUDA,否则 CPU 也能跑)
|
| 49 |
python -m pip install -r requirements.txt
|
| 50 |
|
|
|
|
| 55 |
|
| 56 |
`infer.py` 是同一套逻辑的另一种入口,不落盘、直接回显结果:
|
| 57 |
|
| 58 |
+
```bash
|
| 59 |
+
python infer.py --checkpoint best_fp16.pt --input examples/example_input.txt # 换权重即可
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
### 权重怎么选
|
| 63 |
+
|
| 64 |
+
| 文件 | 存储精度 | 体积 | 推理 | 说明 |
|
| 65 |
+
| --- | --- | ---: | --- | --- |
|
| 66 |
+
| `best.pt` | fp32 | 230 MB | CPU/GPU | 参考权重,DEV Exact 307/328 |
|
| 67 |
+
| `best_fp16.pt` | fp16 | 115 MB | CPU/GPU | 权重减半;载入后默认按 fp32 计算,DEV 全部预测与 `best.pt` 逐条一致 |
|
| 68 |
+
| `best_int8.pt` | int8(Linear 动态量化) | 97 MB | 仅 CPU | 更快更小,但边界分数有量化漂移,Exact 会掉(见下方「精度与体积」) |
|
| 69 |
+
|
| 70 |
+
三个文件共用同一套代码,`--checkpoint` 换文件名即可。fp16 想真正以半精度跑(省显存、GPU 更快):
|
| 71 |
+
|
| 72 |
+
```python
|
| 73 |
+
locator = BodyLocator("best_fp16.pt", device="cuda", dtype="float16") # CPU 上会拒绝 half
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
```bash
|
| 77 |
python infer.py --checkpoint best.pt --input examples/example_input.txt
|
| 78 |
# => {"span": [151, 448], "char_count": 718, "token_count": 522, "chunk_count": 1, "time_ms": 319}
|
|
|
|
| 156 |
|
| 157 |
同口径 V5 基线为 295/324 Exact、误删 5,432 字、误留 6,790 字。选模型时先看 Exact,同分比字符 F1;上线更应关注误删。
|
| 158 |
|
| 159 |
+
## 精度与体积:fp16 / int8
|
| 160 |
+
|
| 161 |
+
三个权重是同一份参数的三种存储精度,解码逻辑完全相同。本机(CPU,无 GPU)实测前 40 篇 DEV:
|
| 162 |
+
|
| 163 |
+
| 文件 | 精度 | 体积 | 与 fp32 预测一致 | 说明 |
|
| 164 |
+
| --- | --- | ---: | ---: | --- |
|
| 165 |
+
| `best.pt` | fp32 | 230 MB | — | 参考权重,前 40 篇命中 39/40(唯一漏的 `real-dev-000008` 预测 `[25, 2408)`,gold `[9, 2408)`) |
|
| 166 |
+
| `best_fp16.pt` | fp16 存储 | 115 MB | **40/40** | 载入后仍按 fp32 计算,边界决策与 fp32 逐条相同;只省体积 |
|
| 167 |
+
| `best_int8.pt` | int8(Linear 动态量化) | 97 MB | **36/40(90%)** | 4 篇偏差:3 篇起止差 6–26 字,1 篇起点被拉到 0(把整段脚手架当正文) |
|
| 168 |
+
|
| 169 |
+
结论:**要稳定边界就用 `best.pt` 或 `best_fp16.pt`**;`best_int8.pt` 适合"体积/CPU 速度优先、能接受偶发边界漂移"的场合。int8 量化只改 encoder 里的 `nn.Linear`,不改 8,192 token 上限,也不能在 CUDA 上跑(量化算子是 CPU 实现)。
|
| 170 |
+
|
| 171 |
## 已知限制
|
| 172 |
|
| 173 |
- **中文 RP / 长回复场景**训练出来的模型,其他文体(邮件头、论坛签名等)可以跑通但精度不保证。
|