用同一输入比较不同分词配置。
cnmodel-fit 将分词数与登记的上下文限制、费率假设结合,输出表格或 JSON 报告。
分词数因 tokenizer 而异,可用成本估计还需要明确费率与输出假设。应把这些输入展示出来,而不是把价格表当成实测账单。
- 同一输入多个配置 — 报告对登记 tokenizer 使用同一文本。
- 区分费用情景 — 输入、缓存输入与输出估计分别展示。
- 可见登记假设 — 模型限制与带日期费率保存在 YAML。
InputReader 读取文本;TokenizerRegistry 按需加载登记的 tokenizer,返回数量或逐模型错误。PricingRegistry 读取带日期 YAML 费率;ReportBuilder 计算上下文占用和输入、缓存输入、预估输出费用。
| 组件 | 职责 |
|---|---|
Input text |
input_reader.py |
Tokenizer registry |
tokenizer_registry.py |
Pricing registry |
pricing_registry.py |
Fit report |
report.py; formatter.py |
使用仓库清单指定的运行时版本构建,并在仓库根目录运行示例。
git clone https://github.com/SuperMarioYL/cnmodel-fit.git
cd cnmodel-fit
uv venv .venv
uv pip install --python .venv/bin/python -e .
source .venv/bin/activate用真实本地 WordLevel tokenizer 处理 hello world hello,再按明确的合成费率与 100-token 上下文计算生产报告。
.venv/bin/python examples/presentation-demo.pyThe local tokenizer yields three tokens and the report calculates 3% context occupancy for the demo profile.
{
"model_id": "demo-local",
"token_count": 3,
"context_fit_pct": 3.0,
"cost_input_usd": 3e-06,
"cost_cache_usd": 6.000000000000001e-07,
"cost_output_usd": 6e-06,
"error": null
}
完整命令与输出保存在 docs/demo-results.json. 输入和复现代码均随仓提供。
保留已有录制供参考;上方文字示例给出当前可复现的操作。
CLI 提供以下操作。示例之外的命令需要替换成你的文件路径或标识。
cnmodel-fit examples/fibonacci.py --tokens
cnmodel-fit examples/fibonacci.py --json
cnmodel-fit examples/fibonacci.py --output-ratio 0.5
cnmodel-fit examples/fibonacci.py --model deepseek-v4,qwen3.8-max
cat prompt.txt | cnmodel-fit--output-ratio FLOAT(默认 1.0,需 >= 0)设定输出 token 投影比例:默认按输入等量投影 $Output,传 0.5 即按输入的一半估算输出成本。输入侧成本不受该比例影响。
--model ID[,ID...] 只对比列出的注册模型(ID 见 data/models.yaml,如 deepseek-v4,qwen3.8-max);未注册的 ID 会打印有效 ID 列表并以退出码 2 结束,且在任何 tokenizer 下载之前完成校验。默认输出全部四个模型。
data/models.yaml 将 ID 映射到 tokenizer 仓库;data/pricing.yaml 定义 context_window、input_price、cache_price、output_price 与 as_of。离线示例使用明确临时登记表和本地 WordLevel tokenizer,不下载仓库。
以下路径已有源码实现。按任务选择输入,并把生成的结果与项目一起保存。
| 路径 | 已实现职责 |
|---|---|
| File / stdin | Input text |
| HF tokenizers | Configured tokenizer repositories |
| YAML registries | Model limits and dated rates |
| JSON / table | Counts, estimates and errors |
- 模型名称、tokenizer 映射与价格属于登记数据,不证明厂商当前产品状态;使用前应核实对应模型。
- 默认加载器启用 trust_remote_code=True;加载未缓存 tokenizer 可能下载并执行仓库代码。
- 缓存输入费用是情景估计,不是预期折扣。默认输出 token 数等于输入数,除非通过
--output-ratio指定其他比例。
模型映射和费率快照需要持续维护;真实负载估算还需要实测输出长度与缓存命中假设。
许可见 LICENSE. 反馈问题时请提供最小输入、执行命令和实际输出。
