Skip to main content

ei-pipe-sdk

面向算法同学的极简模型接入 SDK。把你的模型写成一个 EiInfer 的两个方法,ei-pipeline 就能调度它推理:你不用关心数据怎么进来、结果怎么提交,也不用关心部署。

安装

pip install ei-pipe-sdk
# 或先在仓库 ei_pipe_sdk/ 下本地构建
uv build && pip install dist/ei_pipe_sdk-*.whl

三步接入

# my_model.py
from ei_infer import EiInfer, register


class MyModel(EiInfer):
    def init(self, model_cfg: dict | None = None) -> None:
        # 进程启动时调用一次:加载权重、tokenizer、选设备。失败会让 worker 启动即崩溃。
        self.model = load_weights(...)

    def inference(self, input_path: str, output_path: str, node_info: dict) -> dict:
        # input_path / output_path: worker 已恢复好的绝对路径
        #   = {EI_INFER_DATA_ROOT}/{time_bucket}/{pipeline_id}/<相对路径>
        # input_path 是输入(文件或目录);output_path 是允许写结果文件的目录(可能为空)。
        # 是否落盘由模型自己决定;返回的 dict 会被 worker 回传给 pipeline。
        return {"detections": self.model(open(input_path))}


register("my-model", MyModel())   # 注册名 = 管道节点 params.name 的值
pip install ei-pipe-sdk
# 在算法部署里跑(pod 内需挂载 PFS data_root 到 EI_INFER_DATA_ROOT,
# 并给出调度服务的 service_id:静态给定或经 scheduler_url 解析)
EI_INFER_DATA_ROOT=/lpai/pvc/ei-autolabel-bd-ga-infer \
EI_INFER_SCHEDULER_URL=http://ei-pipeline:8000 python -m ei_infer.worker

协议

调度端(ei-pipeline 的 ei_infer 节点)会按统一协议给你发任务:

字段 类型 说明
name str 模型注册名,由你 register("name", ...) 时命名
input_path str 输入路径(相对 pipe 共享目录,如 data/),worker 恢复为绝对路径
output_path str? 允许写结果文件的目录(相对 pipe 共享目录,可选)
version str? 版本提示,透传保留

worker 用 node_info.time_bucket + pipeline_id + EI_INFER_DATA_ROOT 把 input_path / output_path 恢复成绝对路径,调用 inference(input_path, output_path, node_info)。 是否把结果落盘由模型自己决定,worker 不替模型落盘,只把模型返回的 dict 原样回传。 整个链路里你的函数只看绝对路径 input_path / output_path 和 node_info,其余(数据就位、 并发、轮询)全部由 SDK 兜底。

配置(环境变量)

变量 默认 说明
EI_INFER_REDIS_URL 回退 EI_ARQ_REDIS_URL → EI_REDIS_URL → redis://localhost:6379/0 消费队列的 Redis
EI_INFER_SERVICE_ID 空 调度服务的 service_id(h8),静态给定时优先生效
EI_INFER_SCHEDULER_URL 空 未给 EI_INFER_SERVICE_ID 时,向该调度请求 GET /api/status/service-id 解析(不可达每分钟重试)。两者必须二选一
EI_INFER_MAX_JOBS 4 每 worker 并发任务数(arq max_jobs)
EI_INFER_MAX_THREADS max(4, max_jobs) 跑同步推理的线程池大小
EI_INFER_DATA_ROOT /lpai/pvc/ei-autolabel-bd-ga-infer PFS data_root 在 pod 内的挂载根

队列

每个注册模型一条队列,统一文法(详见 ei-pipeline docs/arq_queue_naming.md):

arq:ei:{service_id}:ei_infer:{model_name}

worker 进程为每个注册模型起一个 arq Worker 消费对应队列;service_id 与 调度侧表名/Redis 前缀同源,隔离共用一套 Redis 的多个调度服务。

多模型

多个模型可在同一个 worker 进程里 register 多个名字;进程会为每个模型各起 一个 arq Worker,各自消费自己的队列,互不抢任务。

失败模式

  • inference 返回非 dict → 任务失败(错误信息含模型名)。
  • name 未注册 → 任务失败,节点错误信息会指出未知模型名。
  • init 抛异常 → worker 启动即退出,方便在你自己的日志里早发现。

本地联调

# 起一个本地 redis 后(redis-server)
EI_INFER_SERVICE_ID=f7436895 python -m ei_infer.worker
# 每个注册模型一条队列:arq:ei:f7436895:ei_infer:{model_name}

然后在 ei-pipeline 用 ei_infer 节点提交一条任务即可走通。

Metadata

Release files for ei-pipe-sdk 0.2.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ei-pipe-sdk 0.2.7
File Size Uploaded Provenance Actions
ei_pipe_sdk-0.2.7.tar.gz 84.4 kB Without provenance Details for ei_pipe_sdk-0.2.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ei-pipe-sdk 0.2.7
File Interpreter ABI Platform Actions
ei_pipe_sdk-0.2.7-py3-none-any.whl Python 3 none any Details for ei_pipe_sdk-0.2.7-py3-none-any.whl

Total release size: 157.6 kB

Release files / ei_pipe_sdk-0.2.7.tar.gz

Download URL ei_pipe_sdk-0.2.7.tar.gz
Size 84.4 kB
Tags Source
SHA-256 checksum
How to use checksums
06f6729592b9f6e159063cfdec0796bad055c3ba9660e612b5b2f3da7e316cc2
BLAKE2b-256 checksum
How to use checksums
1fc2fffaa900e55961653bd7458e1b4aad2e9eec0fb22c3b0a3ebd9c269e980f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / ei_pipe_sdk-0.2.7-py3-none-any.whl

Download URL ei_pipe_sdk-0.2.7-py3-none-any.whl
Size 73.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
229c7542ed12e1b7718925038f0b9a855473c3545d0c87709baa77a1c50b88aa
BLAKE2b-256 checksum
How to use checksums
4ead93743b69f690029d5da24dec69a1486f4a2032d211b92c8b48a9983ab570
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for ei-pipe-sdk 0.2.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page