Full sync: LemonDecider 4B preview (2026-12-05 new_hf_model)
Browse filesFiles changed (9)
- DEPLOYMENT.mdAdded+159
- QUICKSTART.md+5-1
- README.md+19-11
- SHA256SUMS+8-6
- config.json+1-1
- configuration_lemondecider.py+1-1
- decision_config.json+1-1
- requirements.txt+3-1
- serve.pyAdded+100
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159# LemonJev 4B Decision 本地 GPU 部署指引
**Model ID:** `lemonjev-4b-decision-20261202-v1` **包内版本:** `v1.1-256k` **接口:** `GET /health`、`GET /v1/models`、`POST /v1/systemone`
本目录包含 BF16 权重、tokenizer、推理代码、HTTP 服务和校验清单。复制整个目录即可使用,不需要额外下载基座或 adapter。模型只接受文本或结构化 JSON,输出 `choice`、`noul`、`score` 三类决策概率,不做自由文本生成,也不支持图片或视频。
## 1. 环境与容量
- 推荐 Python 3.12、PyTorch 2.10+、Transformers 5.8+;已在 PPU-ZW810E(单卡 96 GiB) 和系统 Python / vendor PyTorch 环境实测。- **PPU 环境务必保留厂商 PyTorch,不要用通用 CUDA wheel 覆盖。**- 常规输入建议至少 16 GiB 显存;接近 256K 的单问题前向建议 96 GiB,并关闭同卡其他任务。- 每个 question 独立渲染和前向;上限 **262,144 tokens(含模板)**,一次最多 256 个问题。 `usage.input_tokens` 是本次请求各问题独立输入之和。- 输入从不静默截断;超过 262,144 tokens 时,HTTP 返回 400。- 最终 SFT 只使用不超过 8,192 tokens 的输入。256K 是已进行真实前向验证的输入容量, **不代表长上下文准确率或概率校准已经系统验证**。
安装依赖并验证包完整性:
```bashcd /path/to/lemonjev-4b-decision-20261202-v1python3 -m pip install -r requirements.txtpython3 verify.py```
当前发布包应输出:`OK: 23 release files verified`。
## 2. 不走 HTTP 的本地冒烟
```bashpython3 model.py --device cuda:0 --input example.json```
`--device auto` 自动选择首个可用 GPU,没有 GPU 时回退到 CPU。CPU 可用于检查代码,但长输入会很慢。静默加载 NAS 权重需要数十秒到数分钟属于正常现象。
## 3. 启动本地 HTTP 服务
前台启动(日志直接可见):
```bashcd /path/to/lemonjev-4b-decision-20261202-v1PYTHONDONTWRITEBYTECODE=1 CUDA_VISIBLE_DEVICES=0 \ python3 serve.py --host 0.0.0.0 --port 8100 --device cuda:0```
权重加载完成后,另一个终端检查:
```bashcurl -s http://127.0.0.1:8100/health | python3 -m json.tool```
应包含:`status=ready`、`device=cuda:0`、`max_input_length=262144`、`modalities=["text"]`。默认 **无鉴权**,请仅在可信内网或受控网络中绑定 `0.0.0.0`;只需要本机访问时可使用 `--host 127.0.0.1`。
后台测试启动方式(`nohup` 不保证保活):
```bashcd /path/to/lemonjev-4b-decision-20261202-v1nohup env PYTHONDONTWRITEBYTECODE=1 CUDA_VISIBLE_DEVICES=0 \ python3 serve.py --host 0.0.0.0 --port 8100 --device cuda:0 \ > /tmp/lemonjev-4b-serve.log 2>&1 &echo $! > /tmp/lemonjev-4b-serve.pid```
停止时只结束自己登记的进程:
```bashkill "$(cat /tmp/lemonjev-4b-serve.pid)"```
容器互访可使用 `http://<POD_IP>:8100`,无需经过外部网关。若要给公网用户提供服务,应在前面增加鉴权、请求体大小限制、超时和生产级保活,不要直接暴露本测试服务。
## 4. 一次请求覆盖三种题型
```bashcurl -s http://127.0.0.1:8100/v1/systemone \ -H 'Content-Type: application/json' \ -d '{ "model": "lemonjev-4b-decision-20261202-v1", "state": "商品已经收到,但屏幕损坏。客户要求退货退款,并希望今天处理。", "questions": { "intent": { "type": "choice", "instructions": "客户的主要诉求是什么?", "criteria": {"refund": "退货退款", "delivery": "查询物流", "account": "账户问题"} }, "damaged": {"type": "noul", "instructions": "客户是否表示商品损坏?"}, "urgency": {"type": "score", "instructions": "评估处理紧急程度。", "criteria": ["低", "中", "高"]} } }' | python3 -m json.tool```
预期输出语义:`intent.choice="refund"`;`damaged.noul` 接近 1;`urgency` 的高等级概率较高。返回结构为 `answers.<问题名>`:
- `choice`:`probabilities`、`choice`、`confidence`;选择概率最大的选项。- `noul`:`noul`,即肯定答案概率,常用 0.5 作为二值判读阈值。- `score`:有序等级概率、`score`(从 0 开始的期望值)和 `confidence`。等级分类评测时取 概率最大的等级;期望值不要求恰好为整数。
## 5. 本机实测结果(2026-12-04)
### 带标准答案的功能题
判读规则预先固定为 choice=argmax、noul 阈值 0.5、score=等级 argmax。共 8 道:**8/8 正确**(choice 3/3、noul 2/2、score 3/3)。
| 用例 | 期望 | 预测 ||---|---|---|| 退货退款诉求 | refund | refund || 查询物流诉求 | delivery | delivery || 无法登录账户 | account | account || 明确表示碎屏 | true | true || 明确表示商品完好 | false | false || 系统中断、立即处理 | 高(2) | 高(2) || 希望今天跟进 | 中(1) | 中(1) || 不着急、有空回复 | 低(0) | 低(0) |
这些只是部署功能冒烟,样本少且题意明确,不能替代正式能力评测。
### 长上下文容量与资源
环境:单张 PPU-ZW810E 98,304 MiB,单问题、重复合成文本;延迟含 HTTP 与推理,不含首次模型加载。显存为监测到的整卡峰值,包含服务常驻与工作区。
| 输入 tokens | 结果 | 延迟 | 整卡峰值 ||---:|---|---:|---:|| 10,085 | 通过,返回有限归一化概率 | 1.733s | 12,550 MiB || 60,085 | 通过,返回有限归一化概率 | 15.626s | 33,351 MiB || **262,100** | **通过,返回有限归一化概率** | **156.300s** | **95,795 MiB** |
近 256K 请求非常接近单卡上限,长输入时请使用**单卡、单问题、无同卡其他任务**;不要把多个近 256K 问题放在同一请求中。长测后 caching allocator 可能保留大量显存;需要立即释放时,停止并重新启动本服务。
原始 Decision Index 0.3 public index 74.20 来自既有权重评测,**不是 256K 上下文成绩**。上述长文本用例仅证明前向容量和正常返回,不说明长上下文语义正确率。
## 6. 常见问题
| 现象 | 处理 ||---|---|| 启动阶段连接被拒绝 | 权重和 remote code 尚未加载完,观察日志并继续等待;大型模型从 NAS 冷加载可能需要数分钟 || 首个请求慢或内核初始化 | 再做一次短请求;预热后仍异常才检查 torch / PPU 后端 || HTTP 400 `Question exceeds the context limit` | 缩短 state、问题或选项;服务不会截断输入 || HTTP 400 图片相关提示 | 此发布包只支持文本/JSON,移除 images/videos || 长输入 OOM | 改为单问题、缩短输入、清理同卡其他任务;近 256K 需 96 GiB 级显存 || 长测后显存未下降 | 重启服务释放 CUDA caching allocator || 校验失败 | 不要手动修改权重或 JSON;重新复制完整目录后运行 `python3 verify.py` |
更多 Python API 和请求字段说明见 `README.md`、`QUICKSTART.md` 与 `example.json`。52 unmodified lines5354555657585952 unmodified lines不保证为整数。温度和输入渲染由运行配置自动应用,**不要再次除以温度或自行套聊天模板**。输入上限 8192 tokens(包含模板);超限会明确报错,不会静默截断。## 3. Python52 unmodified lines535455565758596061626352 unmodified lines不保证为整数。温度和输入渲染由运行配置自动应用,**不要再次除以温度或自行套聊天模板**。输入上限 262144 tokens(包含模板);超限会明确报错,不会静默截断。本次仅将运行时门禁放开到底层已有的 256K 位置容量,权重未改;最终 SFT 只见过不超过8192 tokens 的输入,超过 8K 的效果尚未验证。接近 256K 的前向需要显著更多显存和计算,建议从单个 question 开始,并根据硬件能力控制输入长度。HTTP 服务启动方式、8 道带答案功能题以及 10K / 60K / 262,100-token 实测资源数据见 `DEPLOYMENT.md`。## 3. Python
18 unmodified lines1920212223242565 unmodified lines9192939495968 unmodified lines10510610710810911011111211311411511611711811912012112212312412512612714 unmodified lines14214314414514614714818 unmodified lines| Attention | Non-causal full attention on full-attention layers, SDPA || Readout position | Final non-padding token || Precision | BF16 weights; FP32 probability post-processing || Capacity | 8,192 tokens per question (template included); 1–255 options || Modalities | Text and structured JSON only; no images or video || Loader | `modeling_lemondecider.LemonDeciderForDecisionClassification`, `trust_remote_code=True` |65 unmodified lines| `modeling_lemondecider.py` | Inference architecture || `decision_runtime.py` | Protocol rendering and probability post-processing || `model.py` | Python API and CLI || `tokenizer.json`, `tokenizer_config.json`, `chat_template.jinja`, `processor_config.json` | Tokenizer and processor || `decision_config.json` | Protocol summary || `example.json` | Runnable three-type example |8 unmodified lines| Headline | Score ||---|---:|| Decision Index (public) | **74.20** || Raw index | 80.10 || Breadth skill | 74.06 || Area (weight) | Skill | Raw ||---|---:|---:|| Knowledge & Reasoning (25.8%) | 77.87 | 81.86 || Language Understanding (25.8%) | 68.71 | 76.91 || Retrieval & Classification (20.0%) | 72.41 | 78.35 || Tools & Automation (18.3%) | 81.54 | 83.68 || Arts & Human Taste (10.0%) | 69.04 | 80.74 |### Comparison| Model (Decision Index 0.3, full public suite) | Index | Raw | Knowledge | Language | Retrieval | Tools | Arts ||---|---:|---:|---:|---:|---:|---:|---:|| **This model** | **74.20** | **80.10** | **77.87** | 68.71 | 72.41 | **81.54** | **69.04** || LemonDecider 4B v3.1 | 63.78 | 72.09 | 46.39 | **70.04** | **73.14** | 72.99 | 57.01 || LemonDecider 4B v3 | 60.07 | 69.37 | 40.61 | 68.00 | 68.24 | 74.38 | 47.41 |14 unmodified lines- Text-only release; image and video inputs are rejected.- One readout per question; questions are answered independently rather thanjointly.- 8,192-token hard limit per question; longer requests fail explicitly.- Quality depends on the wording of `instructions` and option descriptions.## License and attribution18 unmodified lines1920212223242565 unmodified lines91929394959697988 unmodified lines10710810911011111211311411511611711811912012112212312412512612712812914 unmodified lines14414514614714814915015115215315415515618 unmodified lines| Attention | Non-causal full attention on full-attention layers, SDPA || Readout position | Final non-padding token || Precision | BF16 weights; FP32 probability post-processing || Capacity | 262,144 tokens per question (template included); 1–255 options || Modalities | Text and structured JSON only; no images or video || Loader | `modeling_lemondecider.LemonDeciderForDecisionClassification`, `trust_remote_code=True` |65 unmodified lines| `modeling_lemondecider.py` | Inference architecture || `decision_runtime.py` | Protocol rendering and probability post-processing || `model.py` | Python API and CLI || `serve.py` | Local GPU HTTP service (`/health`, `/v1/systemone`) || `DEPLOYMENT.md` | Local GPU deployment guide, correctness smoke tests and 256K resource measurements || `tokenizer.json`, `tokenizer_config.json`, `chat_template.jinja`, `processor_config.json` | Tokenizer and processor || `decision_config.json` | Protocol summary || `example.json` | Runnable three-type example |8 unmodified lines| Headline | Score ||---|---:|| Decision Index (public) | **74.16** || Raw index | 80.07 || Breadth skill | 74.02 || Area (weight) | Skill | Raw ||---|---:|---:|| Knowledge & Reasoning (25.8%) | 77.65 | 81.69 || Language Understanding (25.8%) | 68.77 | 76.94 || Retrieval & Classification (20.0%) | 72.33 | 78.28 || Tools & Automation (18.3%) | 81.61 | 83.72 || Arts & Human Taste (10.0%) | 69.09 | 80.83 |### Comparison| Model (Decision Index 0.3, full public suite) | Index | Raw | Knowledge | Language | Retrieval | Tools | Arts ||---|---:|---:|---:|---:|---:|---:|---:|| **This model** | **74.16** | **80.07** | **77.65** | 68.77 | 72.33 | **81.61** | **69.09** || LemonDecider 4B v3.1 | 63.78 | 72.09 | 46.39 | **70.04** | **73.14** | 72.99 | 57.01 || LemonDecider 4B v3 | 60.07 | 69.37 | 40.61 | 68.00 | 68.24 | 74.38 | 47.41 |14 unmodified lines- Text-only release; image and video inputs are rejected.- One readout per question; questions are answered independently rather thanjointly.- 262,144-token hard input limit per question; longer requests fail explicitly.- The input gate is opened to the backbone's 256K position capacity without changingweights. Final SFT used inputs no longer than 8,192 tokens. A synthetic 262,100-tokensingle-question forward passed on a 96 GiB PPU (156.3s; 95,795 MiB whole-GPU peak),but quality and calibrated behavior beyond 8K remain unvalidated. Long requests requiresubstantial accelerator memory and compute; the reported evaluation scores are not256K claims. See `DEPLOYMENT.md` for measured resource usage and deployment checks.- Quality depends on the wording of `instructions` and option descriptions.## License and attribution
1234567891011122 unmodified lines1516171819202150cbab8a892c5f2993b8c7351a99182507472def3b1374558308605d99b86b32 LICENSEbdb5d45a5736702104f43f47f0d7dd2fbdd52295e81d20951131b06a319c693b LICENSE.code312bb5c656b18057372cffb7f2a699d9e3133577596c18a3c9c5c10e3db1bd9f NOTICE6b2da3cde3b536831ab44b1255a35026d58ba33319d998259f1802f4f18b8025 QUICKSTART.mdaea8da8bacbe342f64893dd33d8810f14dac402771816e9cffede68b3feead70 README.mda4aee8afcf2e0711942cf848899be66016f8d14a889ff9ede07bca099c28f715 chat_template.jinjae576baabefb3c1def8fa755ae60ca0eb993472d09d20f798e69b120e461be63e config.jsona60949fab359c5585f04fefff1a18500c604a8545426b22d43a483800348eace configuration_lemondecider.pydc279963121402d01c48ff8be230dc673deef683e7e603f81bd758641bad332c decision_config.jsona762f22d571a8a584116e06d9cb4236da4d13d142498e6c5d5591d8dc37fd6e0 decision_runtime.pye51ac8eb518f75ad85cb9c2fd52b86dc109b8f8bc0af43df8cc6e65492c89866 example.json34b26bfcaff8b70daac03a4fc607c8bc0ae0c831ec6012d68c6cf547c0d76c2a model-00001-of-00002.safetensors2 unmodified lines36d3602491b49476adb37e188abe44d6ba161dc03970023683cfb4d9ff4d3dde model.safetensors.index.jsonaab77a819b29a5e91284001749596be6a18c440a20f0221bbac83cf66dbc1873 modeling_lemondecider.py990d8466b2d193797665e4d84d30b8c25cba64a30a0c37b91e60f1b620db422e processor_config.json814dfd792760b479cf0f2c576b0414da1de18a725603d4b93fe78f2e26f60e4e requirements.txt6f32ce20dc35f57a7f9ad1eac03525bd7d30f9df8cea6507e958279cc3657706 tokenizer.json7488550a894dcf741616126e322ea31d66cf9457b59ec5825f4c7efdced421f8 tokenizer_config.jsonbcce5185620c3c2ed9d1953e8966d93e8be07d2e2135b03e769287e16d749f6a verify.py123456789101112132 unmodified lines161718192021222350cbab8a892c5f2993b8c7351a99182507472def3b1374558308605d99b86b32 LICENSEbdb5d45a5736702104f43f47f0d7dd2fbdd52295e81d20951131b06a319c693b LICENSE.code25bbb89ca7a35c68f5df1bf81000aa5e50f76d689558c9f60a15b68400669b02 DEPLOYMENT.md312bb5c656b18057372cffb7f2a699d9e3133577596c18a3c9c5c10e3db1bd9f NOTICE9b269e3453e58b904e447575d2cd524016368e0054d2e2dd045d4e420ea914a3 QUICKSTART.md807ecb2219b3128401ebdc446e07aff93eaee02d7445899cf47b6eea07780267 README.mda4aee8afcf2e0711942cf848899be66016f8d14a889ff9ede07bca099c28f715 chat_template.jinja6e5b5669cdaeeb3b5022b896c202aa39ff03905ebda875c2394b0b58e8a1b37f config.jsond0771e12dd61e9a1b6281fd540b77b500a2ee4ea667edeaed85633973243924d configuration_lemondecider.pyb4a3216a93fb0fab30fe7c6af6dd58cb7aced35219f88556d77df29066c0a723 decision_config.jsona762f22d571a8a584116e06d9cb4236da4d13d142498e6c5d5591d8dc37fd6e0 decision_runtime.pye51ac8eb518f75ad85cb9c2fd52b86dc109b8f8bc0af43df8cc6e65492c89866 example.json34b26bfcaff8b70daac03a4fc607c8bc0ae0c831ec6012d68c6cf547c0d76c2a model-00001-of-00002.safetensors2 unmodified lines36d3602491b49476adb37e188abe44d6ba161dc03970023683cfb4d9ff4d3dde model.safetensors.index.jsonaab77a819b29a5e91284001749596be6a18c440a20f0221bbac83cf66dbc1873 modeling_lemondecider.py990d8466b2d193797665e4d84d30b8c25cba64a30a0c37b91e60f1b620db422e processor_config.jsond4f38387f6f86fa2f61257f64a000836b81522a7a6a435139515a8a8d4a62475 requirements.txt22df2734fea20817e54fca5468e11d4f19aa09e474aaf6a238a26fa26f251fd2 serve.py6f32ce20dc35f57a7f9ad1eac03525bd7d30f9df8cea6507e958279cc3657706 tokenizer.json7488550a894dcf741616126e322ea31d66cf9457b59ec5825f4c7efdced421f8 tokenizer_config.jsonbcce5185620c3c2ed9d1953e8966d93e8be07d2e2135b03e769287e16d749f6a verify.py
270 unmodified lines271272273274275276277270 unmodified lines"decision_protocol": "autojev-v1","dtype": "bfloat16","image_token_id": 248056,"max_input_length": 8192,"max_options": 255,"model_type": "lemondecider_decision","pooling": "last",270 unmodified lines271272273274275276277270 unmodified lines"decision_protocol": "autojev-v1","dtype": "bfloat16","image_token_id": 248056,"max_input_length": 262144,"max_options": 255,"model_type": "lemondecider_decision","pooling": "last",
15 unmodified lines1617181920212215 unmodified linestoken_ids=None,max_options=255,temperature=1.0,max_input_length=8192,attention_mode="noncausal_full_attention",pooling="last",code_scheme="letters-v1",15 unmodified lines1617181920212215 unmodified linestoken_ids=None,max_options=255,temperature=1.0,max_input_length=262144,attention_mode="noncausal_full_attention",pooling="last",code_scheme="letters-v1",
11 unmodified lines12131415161711 unmodified lines"decision_protocol": "autojev-v1","readout": "last_token","temperature": 1.0,"max_input_length": 8192,"max_options": 255}11 unmodified lines12131415161711 unmodified lines"decision_protocol": "autojev-v1","readout": "last_token","temperature": 1.0,"max_input_length": 262144,"max_options": 255}
2 unmodified lines34562 unmodified linestokenizers>=0.23safetensors>=0.8numpy>=1.26pillow>=102 unmodified lines3456782 unmodified linestokenizers>=0.23safetensors>=0.8numpy>=1.26pillow>=10fastapi>=0.115uvicorn>=0.30
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100#!/usr/bin/env python3"""Serve this self-contained LemonDecider package over the typed-decision HTTP API.
Endpoints: GET /health, GET /v1/models, POST /v1/systemone.The service is text-only, unauthenticated, and serializes requests on one GPU."""from __future__ import annotations
import argparseimport sysimport threadingimport timefrom pathlib import Path
import uvicornfrom fastapi import FastAPI, HTTPExceptionfrom pydantic import BaseModel, ConfigDict, Field
SERVICE = {"model": None, "lock": threading.Lock(), "checkpoint": "", "started_at": time.time()}
class Question(BaseModel): model_config = ConfigDict(extra="forbid") type: str instructions: str | dict | list | None = None criteria: dict | list | None = None
class DecisionRequest(BaseModel): model_config = ConfigDict(extra="forbid") model: str = Field(min_length=1) state: str | dict | list questions: dict[str, Question] = Field(min_length=1) images: list[str] = Field(default_factory=list, max_length=4)
app = FastAPI(title="LemonDecider HTTP service", version="1.0.0")
@app.get("/health")def health(): model = SERVICE["model"] if model is None: return {"status": "loading", "checkpoint": SERVICE["checkpoint"], "authentication": False} return { "status": "ready", "model": model.config.model_id, "checkpoint": SERVICE["checkpoint"], "device": model.device, "max_input_length": model.config.max_input_length, "max_position_embeddings": model.config.text_config.max_position_embeddings, "modalities": ["text"], "authentication": False, "uptime_seconds": round(time.time() - SERVICE["started_at"], 1), }
@app.get("/v1/models")def models(): model = SERVICE["model"] return {"data": [{"id": model.config.model_id if model is not None else "loading"}]}
@app.post("/v1/systemone")def systemone(req: DecisionRequest): model = SERVICE["model"] if model is None: raise HTTPException(503, "model still loading") if req.images: raise HTTPException(400, "This release supports text and structured JSON only") request = { "state": req.state, "questions": {name: q.model_dump(exclude_none=True) for name, q in req.questions.items()}, } with SERVICE["lock"]: try: return model.predict(request) except ValueError as exc: raise HTTPException(400, str(exc)) from exc
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--checkpoint", default=str(Path(__file__).resolve().parent)) parser.add_argument("--host", default="0.0.0.0") parser.add_argument("--port", type=int, default=8100) parser.add_argument("--device", default="cuda:0") args = parser.parse_args()
checkpoint = Path(args.checkpoint).resolve() sys.path.insert(0, str(checkpoint)) from model import DecisionModel
SERVICE["checkpoint"] = str(checkpoint) SERVICE["model"] = DecisionModel(checkpoint, device=args.device) uvicorn.run(app, host=args.host, port=args.port, log_level="info")
if __name__ == "__main__": main()DEPLOYMENT.mdAdded+159
QUICKSTART.md+5-1
README.md+19-11
SHA256SUMS+8-6
config.json+1-1
configuration_lemondecider.py+1-1
decision_config.json+1-1
requirements.txt+3-1
serve.pyAdded+100