Skip to content

feat: add shared CPU ONNX execution infrastructure - #55538

Open
KurodaKayn wants to merge 4 commits into
milvus-io:masterfrom
KurodaKayn:feat/onnx-execution-infrastructure
Open

KurodaKayn wants to merge 4 commits into
milvus-io:masterfrom
KurodaKayn:feat/onnx-execution-infrastructure

Conversation

@KurodaKayn

Copy link
Copy Markdown
Contributor

issue: #53844
design doc: docs/design-docs/design_docs/20261114-onnx-execution-infrastructure.md

Problem

Embedding and reranking need shared CPU model session management. Loading a
model per request can waste native memory and runtime threads.

Changes

  • Add content-addressed model session caching.
  • Add lease ownership, idle release and manager shutdown.
  • Bound resident sessions, model size, native memory and inference concurrency.
  • Handle cancellation, load failures and model replacement during loading.
  • Validate input and output tensor signatures and payload sizes.
  • Add a runnable lifecycle example and focused tests.

Scope

This PR provides the shared execution contract and resource manager. It does
not add a new ONNX Runtime dependency, tokenizer, pooling, GPU execution,
model download or Function integration. Runtime integration uses the Backend
interface.

Add content-addressed model session caching with lease lifecycle, bounded resident sessions, native memory, inference concurrency and cancellation.

Validate tensor signatures and preserve typed runtime errors. Keep the ONNX Runtime adapter and Function integration behind the Backend interface.

issue: milvus-io#53844
Signed-off-by: Kuroda Kayn <kurodakayn@outlook.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T07:38:30.977168Z da0dd4a New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sre-ci-robot sre-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines. label Nov 14, 2026
@sre-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign xiaofan-luan after the PR has been reviewed.
You can assign the PR to them by writing /assign @xiaofan-luan in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mergify mergify Bot added dco-passed DCO check passed. kind/feature Issues related to feature request from users labels Nov 14, 2026
@sre-ci-robot

Copy link
Copy Markdown
Contributor

[ci-v2-notice]
Notice: New ci-v2 system is enabled for this PR.

To rerun ci-v2 checks, comment with:

  • /ci-rerun-code-check // for ci-v2/code-check
  • /ci-rerun-code-check-macos // for Code Checker MacOS (GitHub Actions)
  • /ci-rerun-build // for ci-v2/build
  • /ci-rerun-build-all // for ci-v2/build-all (multi-arch builds)
  • /ci-rerun-buildenv // for ci-v2/build-env (build milvus-env builder images; update .env after the new tag is ready)
  • /ci-rerun-ut-integration // for ci-v2/ut-integration, will rerun ci-v2/build
  • /ci-rerun-ut-go // for ci-v2/ut-go, will rerun ci-v2/build
  • /ci-rerun-ut-cpp // for ci-v2/ut-cpp
  • /ci-rerun-ut // for all ci-v2/ut-integration, ci-v2/ut-go, ci-v2/ut-cpp, will rerun ci-v2/build
  • /ci-rerun-e2e-default // for ci-v2/e2e-default
  • /ci-rerun-e2e-pulsar-wp // for ci-v2/e2e-pulsar-wp (GCP branch-equivalent Pulsar + Woodpecker Python E2E)
  • /ci-rerun-e2e-amd // for ci-v2/e2e-amd (e2e pool dispatcher)
  • /ci-rerun-e2e-dist-wp // for ci-v2/e2e-dist-wp (Tencent distributed woodpecker-service boundary)
  • /ci-rerun-build-ut-cov // for ci-v2/build-ut-cov (build + unit tests in one pipeline)
  • /ci-rerun-build-ut-cov-tcus // force TC-US build-ut-cov; respects Portal limit, never falls back to AWS
  • /ci-rerun-gosdk // for ci-v2/go-sdk (Go SDK E2E tests, ARM)
  • /ci-rerun-gosdk-std // for ci-v2/go-sdk-std (Go SDK E2E, standalone)
  • /ci-rerun-gosdk-dist-wp // for ci-v2/go-sdk-dist-wp (Go SDK E2E, distributed + Woodpecker service)

If you have any questions or requests, please contact @zhikunyao.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fbc6be75ff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/util/function/onnx/manager.go Resolved
Comment thread internal/util/function/onnx/manager.go Resolved
Comment thread internal/util/function/onnx/manager.go Resolved
Comment thread internal/util/function/onnx/runner.go Resolved
Comment thread internal/util/function/onnx/manager.go Resolved
Keep closing sessions charged until native teardown completes, reject unsupported external tensor data, and guard model and tensor validation edge cases.

issue: milvus-io#53844
Signed-off-by: Kuroda Kayn <kurodakayn@outlook.com>
@sre-ci-robot

Copy link
Copy Markdown
Contributor

❌ CI Loop Results fbc6be7

Stage Result Duration Tests
✅ Build SUCCESS 10.6min -
❌ Code-Check FAILURE 5.1min -
✅ UT-Integration SUCCESS 22.8min -
❌ UT-GO FAILURE 26.7min -
✅ UT-CPP-Cov SUCCESS 28.2min 23159 total, 23159 passed, 0 failed

Total: 50min | Pipeline | Artifacts
C++ coverage phases: Compile 4.9min · UT 19.3min · LCOV 3.8min

Overall Coverage: 79.0%
Diff Coverage: Go 64.5% (373 hit, 205 miss, 578 measurable lines, 300 unmeasured)
Diff Coverage HTML: view changed lines
Total Patch Coverage: 64.5% (373/578 measurable lines, 300 unmeasured)

Failed Test Logs:

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aa64897f18

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/util/function/onnx/manager.go Resolved
Comment thread internal/util/function/onnx/manager.go Resolved
Comment thread internal/util/function/onnx/manager.go Resolved
Use the repository error package and apply gofumpt and gci formatting.

issue: milvus-io#53844
Signed-off-by: Kuroda Kayn <kurodakayn@outlook.com>
Preserve system and cancellation error classes across model reload races and fence stale idle timer callbacks.

issue: milvus-io#53844
Signed-off-by: Kuroda Kayn <kurodakayn@outlook.com>
@sre-ci-robot

Copy link
Copy Markdown
Contributor

❌ CI Loop Results 8b4ba3b

Stage Result Duration Tests
❌ Build UNKNOWN - -
❌ Code-Check SKIPPED - -
❌ UT-Integration SKIPPED - -
❌ UT-GO SKIPPED - -
❌ UT-CPP-Cov SKIPPED - -

Total: 6min | Pipeline | Artifacts

@sre-ci-robot

Copy link
Copy Markdown
Contributor

❌ CI Loop Results aa64897

Stage Result Duration Tests
✅ Build SUCCESS 3.4min -
❌ Code-Check FAILURE 3.6min -
❌ UT-Integration FAILURE 6.4min -
❌ UT-GO FAILURE 6.1min -
❌ UT-CPP-Cov FAILURE 6.0min -

Total: 21min | Pipeline | Artifacts
C++ coverage phases: Compile 5.6min · UT 0.0min · LCOV 0.0min

Failed Test Logs:

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: da0dd4ad77

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +471 to +472
case 8:
return modelProtoFunction, true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Traverse the correct ONNX local-function fields

For models containing external tensors inside local functions, the newly added scanner reports no external data because these protobuf field numbers are incorrect: ModelProto.functions is field 25, while field 8 is opset_import; FunctionProto.node and attribute_proto are fields 7 and 11, not 4 and 7. Consequently, these models bypass external-data rejection and can still reuse a cached session when their external weights differ or change. Correct both levels of the function traversal and cover function-contained tensors in the rejection tests.

Useful? React with 👍 / 👎.

if !ok {
continue
}
found, err := scanModelProto(ctx, file, childStart, int64(length), childKind)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Limit nesting depth in the model protobuf scan

For a malformed model with sufficiently deeply nested graph-valued attributes, this call recurses through GraphProto → NodeProto → AttributeProto.g without any depth limit. Scanning happens before Backend.Load, so an invalid model can exhaust the goroutine stack and terminate the process instead of returning a load error; context checks do not prevent this when callers use context.Background(). Bound the nesting depth and reject excessive nesting before making the recursive call.

Useful? React with 👍 / 👎.

@sre-ci-robot

Copy link
Copy Markdown
Contributor

❌ CI Loop Results da0dd4a

Stage Result Duration Tests
✅ Build SUCCESS 9.6min -
✅ Code-Check SUCCESS 6.2min -
✅ UT-Integration SUCCESS 26.8min -
❌ UT-GO FAILURE 27.2min -
✅ UT-CPP-Cov SUCCESS 41.3min 23159 total, 23159 passed, 0 failed

Total: 61min | Pipeline | Artifacts
C++ coverage phases: Compile 16.4min · UT 21.1min · LCOV 3.7min

Overall Coverage: 79.0%
Diff Coverage: Go 66.0% (495 hit, 255 miss, 750 measurable lines, 345 unmeasured)
Diff Coverage HTML: view changed lines
Total Patch Coverage: 66.0% (495/750 measurable lines, 345 unmeasured)

Failed Test Logs:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-passed DCO check passed. kind/feature Issues related to feature request from users size/XXL Denotes a PR that changes 1000+ lines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants