Skip to content

fix(cli): recognize pretrained model aliases in format_model_suffix#5719

Merged
njzjz merged 1 commit into
deepmodeling:masterfrom
wanghan-iapcm:fix-cli-pretrained-alias-suffix
Jul 3, 2026
Merged

fix(cli): recognize pretrained model aliases in format_model_suffix#5719
njzjz merged 1 commit into
deepmodeling:masterfrom
wanghan-iapcm:fix-cli-pretrained-alias-suffix

Conversation

@wanghan-iapcm

@wanghan-iapcm wanghan-iapcm commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Problem

Fixes #5673. CLI deep-eval commands (dp test, dp eval-desc, dp embed, dp model-devi) normalize their -m argument through format_model_suffix(), which decided whether a name is supported by comparing Path(filename).suffix against the registered backend suffixes. PretrainedBackend registers built-in model names as whole-name (lowercased) suffix aliases such as dpa-3.2-5m, but Path("DPA-3.2-5M").suffix is .2-5M (and DPA3-Omol-Large has an empty suffix), so the alias never matched. Because the CLI always passes a preferred_backend, the unmatched alias did not raise; it silently got the default backend suffix appended (DPA-3.2-5M becomes DPA-3.2-5M.pth) and the subsequent load failed.

Note this refines the issue's description: the observed failure is a silent suffix-mangle, not the ValueError("Unsupported model file format") the issue predicts — that raise branch is unreachable from these CLI commands because a preferred backend is always supplied. The Python API (DeepPot("DPA-3.2-5M")) already worked, because Backend.detect_backend_by_model matches with a case-insensitive endswith; the two matchers were simply inconsistent.

Fix

Align format_model_suffix with Backend.match_filename: match on a case-insensitive endswith over the suffix set. This recognizes both ordinary dotted suffixes (.pth, .pb, ...) and whole-name pretrained aliases (dpa-3.2-5m, dpa3-omol-large) and returns the recognized name unchanged, so PretrainedBackend can resolve it downstream.

Test

Adds tests to source/tests/common/test_pretrained_backend.py asserting that DPA-3.2-5M, DPA3-Omol-Large, and a lowercase alias pass through format_model_suffix unchanged, with controls that an ordinary model.pth is preserved and an unknown bare name still receives the preferred suffix. The alias case fails on master (mangled to DPA-3.2-5M.pth) and passes with the fix. This path had no prior coverage.

Summary by CodeRabbit

  • Bug Fixes

    • Improved model file suffix detection so supported formats are recognized more reliably, including case-insensitive matches and non-standard suffix aliases.
    • Preserved existing behavior for unknown model names, while ensuring the preferred backend suffix is still applied when needed.
  • Tests

    • Expanded coverage for model suffix handling to verify aliases, standard suffixes, and fallback behavior.

CLI deep-eval commands (dp test/eval-desc/embed/model-devi) normalize their -m
argument through format_model_suffix(), which decided support by testing
Path(filename).suffix against the registered backend suffixes. PretrainedBackend
registers built-in model names as whole-name (lowercased) suffix aliases such as
"dpa-3.2-5m", so Path("DPA-3.2-5M").suffix == ".2-5M" never matched and
DPA3-Omol-Large has an empty suffix. With a preferred_backend always supplied by
the CLI, the unmatched alias silently got the default backend suffix appended
(e.g. "DPA-3.2-5M" -> "DPA-3.2-5M.pth") and the subsequent load failed, even
though the pretrained backend advertises those names. The Python API
(DeepPot("DPA-3.2-5M")) worked because Backend.detect_backend_by_model matches
with a case-insensitive endswith, so the two matchers were inconsistent.

Align format_model_suffix with Backend.match_filename: match on a
case-insensitive endswith over the suffix set, which recognizes both ordinary
dotted suffixes and whole-name pretrained aliases and returns them unchanged.

Adds tests asserting aliases (DPA-3.2-5M, DPA3-Omol-Large, lowercase) pass
through unchanged, with controls that an ordinary ".pth" is preserved and an
unknown bare name still gets the preferred suffix appended. Before the fix the
alias case failed (mangled to "DPA-3.2-5M.pth").

Fix deepmodeling#5673
@dosubot dosubot Bot added the bug label Jul 3, 2026
@github-actions github-actions Bot added the Python label Jul 3, 2026
@wanghan-iapcm wanghan-iapcm requested a review from njzjz July 3, 2026 06:38
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The format_model_suffix function in deepmd/backend/suffix.py was updated to use a case-insensitive endswith check against all registered backend suffixes instead of comparing Path(filename).suffix exactly, enabling recognition of whole-name pretrained aliases. Tests were added to validate this behavior.

Changes

Suffix Matching Fix

Layer / File(s) Summary
Case-insensitive suffix matching
deepmd/backend/suffix.py
format_model_suffix now checks filenames against all registered suffixes using a case-insensitive endswith match instead of exact Path().suffix comparison, supporting whole-name aliases.
Alias and suffix formatting tests
source/tests/common/test_pretrained_backend.py
Adds tests confirming pretrained aliases and known backend suffixes pass through unchanged, and unknown names get the preferred suffix appended.

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

Related issues: #5673 — Fixes CLI model suffix formatting to accept documented pretrained aliases (e.g., "DPA-3.2-5M") instead of rejecting them with "Unsupported model file format".

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

🚥 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 describes the main change: accepting pretrained model aliases in format_model_suffix.
Linked Issues check ✅ Passed The implementation matches issue #5673 by letting CLI suffix formatting accept pretrained aliases and keeps normal suffix handling intact.
Out of Scope Changes check ✅ Passed The changes stay focused on suffix matching and tests for pretrained aliases, with no obvious unrelated additions.
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.

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
deepmd/backend/suffix.py (1)

65-76: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Require exact match for bare aliases

Backend.match_filename and this helper both use endswith, so filenames like mydpa-3.2-5m are accepted as the pretrained alias dpa-3.2-5m. Keep endswith for dotted extensions, but use case-insensitive equality for bare aliases so unintended names don’t get dispatched as valid models.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@deepmd/backend/suffix.py` around lines 65 - 76, The filename matching in the
suffix helper is too permissive for bare aliases because the current endswith
check allows names like mydpa-3.2-5m to match a registered alias. Update the
logic in the Path/filename normalization path so dotted extensions still use
case-insensitive endswith, but bare alias entries are matched with
case-insensitive exact equality only. Keep the behavior aligned with
Backend.match_filename and detect_backend_by_model while tightening the alias
handling in the helper that returns the normalized filename or appends
preferred_backend.suffixes[0].
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@deepmd/backend/suffix.py`:
- Around line 65-76: The filename matching in the suffix helper is too
permissive for bare aliases because the current endswith check allows names like
mydpa-3.2-5m to match a registered alias. Update the logic in the Path/filename
normalization path so dotted extensions still use case-insensitive endswith, but
bare alias entries are matched with case-insensitive exact equality only. Keep
the behavior aligned with Backend.match_filename and detect_backend_by_model
while tightening the alias handling in the helper that returns the normalized
filename or appends preferred_backend.suffixes[0].

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ae6d291f-d52a-40ac-aa6f-8d23652e603e

📥 Commits

Reviewing files that changed from the base of the PR and between dd38b35 and 8a40a79.

📒 Files selected for processing (2)
  • deepmd/backend/suffix.py
  • source/tests/common/test_pretrained_backend.py

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.13%. Comparing base (dd38b35) to head (8a40a79).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5719      +/-   ##
==========================================
- Coverage   81.26%   81.13%   -0.13%     
==========================================
  Files         988      988              
  Lines      110877   110877              
  Branches     4234     4237       +3     
==========================================
- Hits        90103    89964     -139     
- Misses      19249    19386     +137     
- Partials     1525     1527       +2     

☔ 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 added this pull request to the merge queue Jul 3, 2026
Merged via the queue into deepmodeling:master with commit d279173 Jul 3, 2026
60 checks passed
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] Let CLI model suffix formatting accept pretrained aliases

2 participants