Skip to content

fix(dpmodel): move econf embeddings to active backend#5840

Open
njzjz-bot wants to merge 1 commit into
deepmodeling:masterfrom
njzjz-bot:fix/dpmodel-econf-type-embed-backend-5641
Open

fix(dpmodel): move econf embeddings to active backend#5840
njzjz-bot wants to merge 1 commit into
deepmodeling:masterfrom
njzjz-bot:fix/dpmodel-econf-type-embed-backend-5641

Conversation

@njzjz-bot

@njzjz-bot njzjz-bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #5641

Summary

  • keep electronic-configuration tables as portable NumPy state for serialization
  • materialize the table at call time in the namespace, dtype, and device of the first embedding weight
  • prevent NativeLayer from selecting NumPy and coercing Torch/JAX/array-API weights back to CPU
  • cover tables regenerated by change_type_map() through the same call-time boundary

Why existing tests missed this

The cross-backend consistency tests already include electronic-configuration embeddings, but their JAX, array-api-strict, TF2, and exportable-PyTorch wrappers eagerly convert NumPy attributes when constructing the backend object. That converts both the weights and econf_tebd, so the generic dpmodel mixed-state boundary is never exercised.

The direct dpmodel path uses NumPy parameters and a NumPy electronic-configuration table, where NativeLayer selecting its namespace from the input is correct. Existing tests therefore compared homogeneous NumPy state or homogeneous wrapper-converted state, but never backend-native weights alongside the intentionally portable NumPy constant. CPU-only numerical comparisons also did not assert the returned array backend, dtype, or device.

Validation

  • source/tests/consistent/test_type_embedding.py: 64 passed, 49 backend-dependent skips
  • focused regression converts only dpmodel layer weights to Torch and verifies Torch output, dtype, device, and NumPy numerical parity
  • the same regression repeats after change_type_map() regenerates the NumPy electronic-configuration table
  • ruff format .
  • ruff check .

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

Summary by CodeRabbit

  • Bug Fixes

    • Electronic-configuration type embeddings now consistently use the active computational backend, data type, and device.
    • Improved compatibility when combining portable model data with PyTorch-based weights.
    • Type-map updates continue to produce consistent results across supported backends.
  • Tests

    • Added coverage validating numerical consistency and device/dtype handling for electronic-configuration embeddings.

Materialize portable NumPy electronic-configuration tables in the namespace, dtype, and device of the type-embedding weights before evaluation. This prevents NativeLayer from selecting NumPy and coercing backend-native parameters back to CPU.

Add a direct mixed-state regression covering Torch output identity, numerical parity, and change_type_map regeneration without relying on eager-converting backend wrappers.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.4
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
@dosubot dosubot Bot added the bug label Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 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

Run ID: 3bda8f96-138f-4873-9f37-e94fcc3ea20d

📥 Commits

Reviewing files that changed from the base of the PR and between 6c3b985 and a095055.

📒 Files selected for processing (2)
  • deepmd/dpmodel/utils/type_embed.py
  • source/tests/consistent/test_type_embedding.py

📝 Walkthrough

Walkthrough

TypeEmbedNet.call() now converts electronic-configuration embeddings to the active backend, dtype, and device. A PyTorch-only consistency test validates mixed NumPy constants, PyTorch parameters, and type-map remapping.

Changes

Electronic-configuration backend alignment

Layer / File(s) Summary
Call-time backend conversion and validation
deepmd/dpmodel/utils/type_embed.py, source/tests/consistent/test_type_embedding.py
TypeEmbedNet.call() materializes electronic-configuration embeddings with the active weight’s dtype and device. The PyTorch test verifies output type, device, numerical equivalence, and remapping behavior.

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

Suggested reviewers: njzjz

🚥 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 matches the main change: moving electronic-configuration embeddings to the active backend.
Linked Issues check ✅ Passed The changes implement the requested backend conversion and add regression coverage for backend-native econf embeddings.
Out of Scope Changes check ✅ Passed The diff stays focused on econf backend materialization and its consistency test, with no obvious unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.86%. Comparing base (6c3b985) to head (a095055).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5840      +/-   ##
==========================================
- Coverage   78.58%   77.86%   -0.72%     
==========================================
  Files        1050     1050              
  Lines      120637   120639       +2     
  Branches     4356     4354       -2     
==========================================
- Hits        94801    93936     -865     
- Misses      24278    25144     +866     
- Partials     1558     1559       +1     

☔ 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.

@njzjz

njzjz commented Jul 18, 2026

Copy link
Copy Markdown
Member

Possible reviewers based on changed lines, exact file history, and exact-file review history:

  • @OutisLi — 14 reviews on exact changed files (deepmd/dpmodel/utils/type_embed.py).
  • @iProzd — 6 commits on changed files (deepmd/dpmodel/utils/type_embed.py, source/tests/consistent/test_type_embedding.py).

No review request was made automatically.

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

@njzjz
njzjz requested review from OutisLi and iProzd July 18, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code scan] Move electronic-configuration type embeddings onto the active backend

2 participants