Skip to content

extract scheduler from encode server and DP runtime from HTTP server - #6

Merged
liusy58 merged 1 commit into
new_epdfrom
cya/new_epd
Jul 24, 2026
Merged

liusy58 merged 1 commit into
new_epdfrom
cya/new_epd

Conversation

@cccccya

@cccccya cccccya commented Jul 24, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

当前 Encoder Server 的调度与启动逻辑分散在多个模块中:

  • EncoderScheduler 位于 encode_server.py
  • DPDispatcher、DP Worker 和 DP 启动逻辑位于 encode_http_server.py
  • non-DP 的 ZMQ、TP follower、rank-0 MMEncoder 和 Scheduler 初始化也位于 encode_http_server.py

为了后续统一 HTTP/gRPC 后端启动方式、支持 DP+TP 拓扑,并进一步扩展 Scheduler 职责,本 PR 新增协议无关的 encoder_runtime.py,集中管理 Encoder 的调度、DP dispatch 和后端 Runtime 初始化。

本 PR 只调整代码位置和职责边界,不改变现有请求路径和运行拓扑。

本 PR 暂时不包含

  • 不改变 Scheduler batching 策略
  • 不改变请求队列和响应语义
  • 不支持 DP+TP 组合
  • 不让 gRPC 接入 EncoderRuntime 或 DPDispatcher
  • 不拆分 Scheduler 和 Encoder Worker 进程
  • 不迁移 preprocess 或 global cache matching
  • 不修改 HTTP、gRPC 或 protobuf 协议

当前 DP Runtime 仍要求:

dp_size > 1
tp_size == 1

Modifications

1. 新增 encoder_runtime.py

从 encode_server.py 移入:

  • PendingRequest
  • _BATCHABLE_MODALITIES
  • EncoderScheduler

从 encode_http_server.py 移入:

  • DPDispatcher
  • DP Worker 请求处理逻辑
  • DP Worker 健康检查与 embedding 发送逻辑
  • run_dp_worker() 和 launch_dp_worker()
  • DP Worker 进程、IPC socket 和 Dispatcher 初始化逻辑

同时新增:

  • EncoderRuntime
  • launch_local_runtime()
  • launch_dp_runtime()

2. 集中 non-DP Runtime 初始化

launch_local_runtime() 负责创建并持有:

  • ZMQ context 和 TP schedule sockets
  • TP follower processes
  • rank-0 MMEncoder
  • EncoderScheduler
  • non-DP metrics collector

当前仍保持:

HTTP -> EncoderScheduler -> 直接调用 rank-0 MMEncoder
                              -> 现有 TP followers

Scheduler 与 rank-0 MMEncoder 仍在同一进程中,不引入新的 Scheduler/Worker IPC。

3. 抽离 DP Runtime 启动逻辑

原 HTTP Server 中的 DP 启动逻辑拆分到 launch_dp_runtime(),负责:

  • 创建 DP dispatch/result ZMQ sockets
  • 启动 DP Worker processes
  • 初始化 DP metrics
  • 创建并返回 DPDispatcher
  • 注册 DP Worker 清理逻辑

HTTP Server 只保留 DPDispatcher 引用,用于现有路由处理。

4. 简化 HTTP Server 职责

encode_http_server.py 现在主要负责:

  • FastAPI 路由
  • HTTP 请求和响应转换
  • HTTP lifespan
  • Prometheus middleware
  • Encoder URL 注册与注销
  • Uvicorn 启动

启动时根据 dp_size 选择 Runtime:

dp_size == 1:
HTTP -> launch_local_runtime()

dp_size > 1:
HTTP -> launch_dp_runtime() -> DPDispatcher

non-DP 路径暂时保留 encoder、encoder_scheduler 和 send_sockets 模块级兼容引用,避免修改现有 HTTP handler。对象本身统一由 EncoderRuntime 创建和管理。

5. 调整 encode_server.py 的职责

  • 将 EncoderScheduler 及相关数据结构移至 encoder_runtime.py
  • 保留 MMEncoder 和 TP follower 的实际计算逻辑
  • Metrics collector 仍保留在 encode_server.py,因为 MMEncoder 内部直接引用,但其初始化转移到 Runtime

Accuracy Tests

Speed Tests and Profiling

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ❌ Run #30082920372
Latest PR Test (Extra): ❌ Run #30082920095

@cccccya
cccccya requested review from ZhengWG and liusy58 as code owners July 24, 2026 09:31
@liusy58
liusy58 merged this pull request into new_epd Jul 24, 2026
70 of 79 checks passed
cccccya pushed a commit that referenced this pull request Jul 27, 2026
extract scheduler from encode server and DP runtime from HTTP server
cccccya pushed a commit that referenced this pull request Jul 28, 2026
extract scheduler from encode server and DP runtime from HTTP server
cccccya pushed a commit that referenced this pull request Jul 29, 2026
extract scheduler from encode server and DP runtime from HTTP server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants