Skip to content

fix(tf): find external protobuf for TensorFlow 2.21 - #5986

Open
njzjz-bot wants to merge 3 commits into
deepmodeling:masterfrom
njzjz-bot:fix/tf21-external-protobuf
Open

fix(tf): find external protobuf for TensorFlow 2.21#5986
njzjz-bot wants to merge 3 commits into
deepmodeling:masterfrom
njzjz-bot:fix/tf21-external-protobuf

Conversation

@njzjz-bot

@njzjz-bot njzjz-bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Adapt the conda-forge TensorFlow 2.21 external-Protobuf fix for upstream use.

  • Find the external Protobuf package when TensorFlow does not expose protobuf as a direct runtime dependency.
  • Preserve an exact protobuf library discovered from the TensorFlow runtime dependencies.
  • Guide the header lookup only with a validated flat or multiarch installation prefix, then restore any caller-provided Protobuf root.

Validation

  • Focused CMake configure: preserved a versioned runtime-discovered protobuf library in a flat <prefix>/lib layout even when a different protobuf prefix was globally searchable.
  • Focused CMake configure: mapped a runtime-discovered library in <prefix>/lib/<triplet> to headers in <prefix>/include and restored the caller's Protobuf_ROOT.
  • Focused CMake configure: found protobuf normally when the TensorFlow runtime dependency scan produced no protobuf library.
  • cmake-format check passed for source/cmake/Findtensorflow.cmake.
  • ruff check . passed.
  • ruff format . left 1913 files unchanged.

Repository CI does not exercise the external-header branch because its pip TensorFlow packages bundle google/protobuf/type.pb.h. The focused CMake configurations above validate the changed lookup behavior directly.

Coding agent: Codex
Codex version: codex-cli 0.151.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

Summary by CodeRabbit

  • Bug Fixes
    • Improved TensorFlow and Protobuf library discovery across standard and multiarch installation layouts.
    • Preserved existing Protobuf configuration after dependency detection.
    • Enhanced validation of Protobuf headers and libraries to reduce configuration failures.

Backport conda-forge/deepmd-kit-feedstock patch 0001 at d02138263b0b30629fe28c68c8bcecc2b8644513.

Agent: ChatGPT
Model: GPT-5.6 Sol
@njzjz
njzjz requested a review from wanghan-iapcm August 22, 2026 19:19
@njzjz
njzjz marked this pull request as ready for review August 22, 2026 19:19
Copilot AI lite review requested due to automatic review settings August 22, 2026 19:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@dosubot dosubot Bot added the bug label Aug 22, 2026
@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c21c504b-058c-40d5-b094-6ce96a3eaf16

📥 Commits

Reviewing files that changed from the base of the PR and between 72f40f4 and 3499e8a.

📒 Files selected for processing (1)
  • source/cmake/Findtensorflow.cmake

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The TensorFlow CMake module now derives and validates a Protobuf prefix from the runtime library, supports flat and multiarch layouts, restores the original Protobuf_ROOT, and assigns the discovered Protobuf variables.

Changes

TensorFlow discovery

Layer / File(s) Summary
Require Protobuf package resolution
source/cmake/Findtensorflow.cmake
When TensorFlow provides a runtime Protobuf library, the module derives its installation prefix and validates the Protobuf header in flat or multiarch layouts. It temporarily sets Protobuf_ROOT, restores the previous value, requires Protobuf discovery, and assigns TensorFlow’s Protobuf variables.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 3499e

The PR improves external Protobuf discovery while preserving the TensorFlow runtime library and caller settings; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing external Protobuf discovery for TensorFlow 2.21.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.44%. Comparing base (8cfd46e) to head (3499e8a).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5986      +/-   ##
==========================================
- Coverage   79.10%   77.44%   -1.66%     
==========================================
  Files        1105     1105              
  Lines      130981   130975       -6     
  Branches     4771     4765       -6     
==========================================
- Hits       103609   101435    -2174     
- Misses      25686    27893    +2207     
+ Partials     1686     1647      -39     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wanghan-iapcm wanghan-iapcm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Non-blocking. The fix is sound for the environment it came from, and I confirmed the backport is byte-identical to the feedstock patch. Two notes and one fact about coverage.

Worth stating plainly: no CI job executes these lines. The branch is only entered when google/protobuf/type.pb.h is absent from the TensorFlow tree, and CI installs TensorFlow from pip wheels, which bundle that header (checked on a local pip TensorFlow: .../tensorflow/include/google/protobuf/type.pb.h is present, and it is exactly the sentinel find_path looks for at line 224). So the green checks on this PR say nothing about the change, and "Full build is left to upstream CI" does not hold for this path, because this repository's CI does not cover it. That is not a reason to block -- there is no reasonable unit test for a find-module branch like this, and adding a conda-forge-TensorFlow build job is far more than this PR should carry -- but it is worth being explicit that the change ships unexercised.

Comment thread source/cmake/Findtensorflow.cmake Outdated
Comment thread source/cmake/Findtensorflow.cmake Outdated
Keep an ldd-discovered protobuf library pinned while using its installation prefix to guide FindProtobuf. Fall back to the normal external package search when TensorFlow exposes no protobuf runtime dependency.

Coding-Agent: Codex
Codex-Version: codex-cli 0.149.0
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
@njzjz
njzjz requested review from wanghan-iapcm and a lite review from Copilot August 23, 2026 16:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@njzjz

njzjz commented Aug 23, 2026

Copy link
Copy Markdown
Member

The review summary coverage note is addressed as well: the PR description now explicitly states that repository CI does not execute the external-header branch and removes the previous claim that a full build was left to upstream CI. It documents the focused CMake configurations used to validate both the pinned runtime-library path and the TensorFlow 2.21 fallback path.

The inline threads have been addressed and resolved, and reviews have been re-requested.

Coding agent: Codex
Codex version: codex-cli 0.149.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

@wanghan-iapcm wanghan-iapcm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Both earlier points are addressed, verified against the code rather than the replies.

The pin survives: Protobuf_LIBRARY is no longer unset, and _protobuf_find_libraries in CMake's FindProtobuf (lines 511-517) takes the elseif(${name}_LIBRARY) branch and skips find_library, so the exact runtime-linked library is kept. Because Protobuf_INCLUDE_DIR is no longer pre-set, find_path now genuinely runs and Protobuf_ROOT can steer it, and the plain fallback happens only when the scan came up empty -- the TensorFlow 2.21 case. The protobuf-lite sentence is gone and the comment now describes only what is demonstrated. That is the shape I was asking for.

One gap in it, inline -- and it is a gap in what I suggested, not something you introduced on your own.

Two things worth flagging for your judgement rather than as defects:

The first revision was byte-identical to the feedstock patch, which meant it was already running in conda-forge's production builds. This revision is new code that has not run anywhere, and CI still does not execute it: the branch is entered only when google/protobuf/type.pb.h is missing from the TensorFlow tree, while CI installs TensorFlow from pip wheels, which ship that header (checked on a local pip TensorFlow -- and it is exactly the sentinel find_path looks for at line 224). So the validation basis is weaker than it was for the first revision, not stronger. That is an argument for keeping the new logic as small and as obviously-correct as possible.

Second, now that this diverges from 0001-find-external-protobuf-for-tensorflow-2.21.patch, the feedstock patch will need refreshing once this lands, or it will conflict.

Separately, I looked at whether the fallback should avoid linking a system protobuf at all when the scan finds nothing, and concluded it should not: deepmd calls protobuf runtime symbols directly (ParseFromString at source/api_cc/src/DeepPotTF.cc:439, TextFormat::Parse at source/api_cc/src/common.cc:1274-1277), so something has to be linked. Recording that here so it does not get raised again.

Comment thread source/cmake/Findtensorflow.cmake Outdated
Verify the inferred protobuf prefix contains the headers before using it, and handle multiarch library directories by checking one additional parent. Leave FindProtobuf on its normal search path when neither layout matches.

Coding-Agent: Codex
Codex-Version: codex-cli 0.151.0
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
@njzjz
njzjz requested a review from wanghan-iapcm August 29, 2026 17:11
@njzjz-bot

Copy link
Copy Markdown
Contributor Author

The latest review comment is addressed in 3499e8a.

The inferred Protobuf prefix is now accepted only when it contains include/google/protobuf/service.h. Both flat <prefix>/lib and multiarch <prefix>/lib/<triplet> layouts are checked. If neither inferred prefix contains the headers, Protobuf_ROOT is left unchanged and FindProtobuf performs its normal search.

I validated the flat runtime-linked layout, the multiarch runtime-linked layout, and the TensorFlow 2.21 fallback with no recorded Protobuf runtime dependency. The expected library and headers were selected in all three configurations, and caller-provided Protobuf_ROOT values were restored.

The inline response is here: #5986 (comment). Review has been re-requested from @wanghan-iapcm.

Coding agent: Codex
Codex version: codex-cli 0.151.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants