【免费下载链接】timberOllama for classical ML models. AOT compiler that turns XGBoost, LightGBM, scikit-learn, CatBoost ONNX models into native C99 inference code. One command to load, one command to serve. 336x faster than Python inference.项目地址https://gitcode.com/gh_mirrors/timber2/timber点击查看免费下载Timber是一款把 XGBoost、LightGBM、scikit-learn、CatBoost 等经典机器学习模型编译为原生 C99 推理代码的 AOT 编译器并提供一套Ollama 兼容的 REST 推理 API。只需两条命令你的模型就能通过http://localhost:11434/api/predict这样的标准 HTTP 接口对外提供微秒级推理服务。本文将带你快速上手Timber 推理 API逐个讲解/api/predict、/api/models、/api/health等接口的请求格式、返回字段与常见错误。为什么用 Ollama 兼容接口端口一致默认监听11434端口与 Ollama 完全相同客户端代码几乎可以无缝替换别名兼容/api/generate是/api/predict的别名专门兼容 Ollama 客户端库⚡微秒级延迟Python 只负责 HTTP 与 JSON 处理真正的推理由编译后的 C 代码完成单次推理约 2 µs整条 HTTP 链路约 91 µs开箱即用服务器自带 CORS 头Access-Control-Allow-Origin: *浏览器端可直接调用。服务端实现位于 timber/serve.py完整的接口文档见 website/docs/api-reference/http-api.md。快速上手三步开启 Timber 推理服务前置条件Python 3.10、一台装有gcc/clang的机器以及一个训练好的树模型文件。第一步安装 Timberpip install timber-compiler第二步加载并编译模型timber load model.json --name my-modelTimber 会自动识别框架XGBoost / LightGBM 等经过 6 个优化 pass 后生成 C99 代码并编译成原生动态库缓存在本地模型仓库中。第三步启动服务并验证timber serve my-model # 默认监听 0.0.0.0:11434 curl http://localhost:11434/api/health # {status: ok, version: 0.1.0}启动后终端会打印出所有可用端点清单并附带一条 curl 示例。服务支持--host与--port参数自定义绑定地址例如timber serve my-model --port 8080。Timber 推理 API 端点总览方法端点作用POST/api/predict执行推理核心接口POST/api/generate/api/predict的 Ollama 兼容别名GET/api/models列出所有已加载模型/api/tags为别名GET/api/model/:name查询指定模型的元数据GET/api/health健康检查核心接口POST /api/predict 详解请求格式字段类型必填说明modelstring是已加载模型的名称inputsfloat[][]是二维数组形状为[n_samples, n_features]curl http://localhost:11434/api/predict \ -H Content-Type: application/json \ -d {model: my-model, inputs: [[1.0, 2.0, 3.0, 4.0, 5.0]]} 小提示inputs传入一维数组单个样本也会被自动处理成[1, n_features]形状。返回字段{ model: my-model, outputs: [0.87], n_samples: 1, latency_us: 91.0, done: true }字段说明outputs预测结果长度 n_samples × n_outputsn_samples本次处理的样本数latency_us纯 C 调用的推理耗时微秒done非流式响应恒为true批量推理一次请求可携带多个样本显著降低网络往返开销curl http://localhost:11434/api/predict \ -d { model: my-model, inputs: [ [1.0, 2.0, 3.0, 4.0, 5.0], [5.0, 4.0, 3.0, 2.0, 1.0], [2.5, 3.5, 1.5, 4.5, 0.5] ] }Python 客户端调用示例完整可运行版见 examples/quickstart_client.pyimport requests resp requests.post(http://localhost:11434/api/predict, json{ model: my-model, inputs: [[1.0, 2.0, 3.0, 4.0, 5.0]], }) print(resp.json()[outputs])JavaScript、Go、Rust 等多语言调用示例可以参考 website/docs/examples/http-client.md。GET /api/models查看已加载模型curl http://localhost:11434/api/models{ models: [ { name: fraud-detector, n_features: 30, n_outputs: 1, n_trees: 50, objective: binary:logistic, framework: xgboost, version: 0.1.0 } ] }拿到n_features后你就能立刻知道/api/predict的inputs每行需要多少个特征值。/api/tags是它的别名GET /api/model/:name则返回单个模型的上述元数据模型不存在时返回 404。常见错误码速查HTTP 状态示例返回原因与排查400{error: missing inputs field}请求体缺少inputs字段注意字段名拼写400{error: invalid JSON body}JSON 格式不合法404{error: unknown endpoint: /api/foo}请求了不存在的端点413{error: request body too large (max 64 MB)}请求体超过 64 MB 硬上限500{error: ...}推理阶段内部错误信息中会给出具体原因Ollama 兼容性与架构内幕/api/generate别名、11434默认端口、done: true字段都是为了让现有 Ollama 客户端代码改几个字就能指向 Timber 服务。架构上服务做了清晰分工Python 处理 HTTP 解析、JSON 序列化与 CORS编译后的 C 代码负责全部推理计算通过ctypes调用.so动态库。Python 从不进入推理热路径这正是 Timber 能比 Python 原生推理快 336 倍的关键。生产环境部署建议内置服务器基于 Python 标准库实现适合开发与中小流量场景。大规模生产环境建议加一层 Nginx 反向代理配置示例见 website/docs/guides/serving-models.mdlocation /api/ { proxy_pass http://127.0.0.1:11434; }另外两点实用建议用GET /api/health做负载均衡器探活响应{status: ok}即服务健康批量推理时把多个样本合并到一次请求比逐条调用更快。总结要点说明核心推理接口POST /api/predict请求体为{model, inputs}模型管理GET /api/models、GET /api/model/:name健康检查GET /api/health默认地址http://localhost:11434兼容策略与 Ollama 同端口、/api/generate别名现在你可以照着 website/docs/getting-started.md 走一遍完整流程timber load加载模型 →timber serve启动服务 →curl /api/predict拿到预测结果全程不到一分钟。更多接口细节可查阅 website/docs/api-reference/http-api.md 与 docs/api-reference.md模型管理与 CLI 参考见 docs/api-reference.md 中的 CLI 部分。赞分享【免费下载链接】timberOllama for classical ML models. AOT compiler that turns XGBoost, LightGBM, scikit-learn, CatBoost ONNX models into native C99 inference code. One command to load, one command to serve. 336x faster than Python inference.项目地址https://gitcode.com/gh_mirrors/timber2/timber点击查看免费下载相关推荐LightRAG API服务器Web UI与Ollama兼容接口完整指南LightRAG API服务器Web UI与Ollama兼容接口完整指南 ? 概述 LightRAG API服务器是一个功能强大的检索增强生成Retriev人工智能RAG大模型知识图谱本地部署终极Ant Media Server API指南REST接口详解与实战应用终极Ant Media Server API指南REST接口详解与实战应用 Ant Media Server是一款超低延迟流媒体引擎支持WebRTC约0.音视频直播后端Druid API参考REST接口完整指南Druid API参考REST接口完整指南 Apache Druid作为高性能的时序数据处理系统提供了丰富的REST API接口用于数据查询、摄入管理和集群数据库OLAP大数据实时分析后端上一篇Ant Design Blazor 统计数值组件单位显示Prefix 与 Suffix 前缀/后缀用法全解析下一篇10分钟上手 Tinyflow为 Web 应用添加 AI 工作流设计画布的完整教程创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考