Skip to content

fix: fall back to HuggingFace for local encoder paths when sentence-transformers is absent#701

Open
sunnyguntuka wants to merge 1 commit into
yzhao062:developmentfrom
sunnyguntuka:fix/local-path-hf-fallback
Open

fix: fall back to HuggingFace for local encoder paths when sentence-transformers is absent#701
sunnyguntuka wants to merge 1 commit into
yzhao062:developmentfrom
sunnyguntuka:fix/local-path-hf-fallback

Conversation

@sunnyguntuka

Copy link
Copy Markdown

Follow-up to #696. Resolves the Codex review comment on release PR #700.

Problem

In resolve_encoder, the local-path branch forced the SentenceTransformer backend unconditionally. On a pyod[huggingface]-only install (no sentence-transformers), passing a local model path raised ImportError before the existing HuggingFace fallback could run - a regression for local-path usage in HF-only environments.

Fix

The local-path branch now tries the SentenceTransformer backend first and, on ImportError, falls back to the HuggingFace backend (mirroring the existing auto-resolve pattern below it). If neither backend is available it raises a clear ImportError with install hints. Both backends load from a local directory without any Hub/network call.

Tests

Adds TestLocalPathEncoderFallback (resolver fallback control flow with _create_encoder mocked) and TestSentenceTransformerEncoderLoading (encoder local-path / remote / pre-instantiated / bad-type loading branches via a fake SentenceTransformer). All new tests run without sentence-transformers or torch installed.

No breaking API changes.

All Submissions Basics:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you checked all Issues to tie the PR to a specific one?

All Submissions Cores:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?
  • Does your submission pass tests, including CircleCI, Travis CI, and AppVeyor?
  • Does your submission have appropriate code coverage? The cutoff threshold is 95% by Coversall.

@coveralls

coveralls commented Jun 17, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 27662659891

Warning

No base build found for commit 680acf3 on development.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 92.489%

Details

  • Patch coverage: 2 uncovered changes across 1 file (91 of 93 lines covered, 97.85%).

Uncovered Changes

File Changed Covered %
pyod/test/test_embedding.py 84 82 97.62%
Total (2 files) 93 91 97.85%

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 20358
Covered Lines: 18829
Line Coverage: 92.49%
Coverage Strength: 3.7 hits per line

💛 - Coveralls

@sunnyguntuka

Copy link
Copy Markdown
Author

Hi @yzhao062 - gentle ping on this one whenever you have a moment. It's a small follow-up to #696 that closes the Codex review comment from #700: on a pyod[huggingface]-only install, a local model path now falls back to the HuggingFace backend instead of raising ImportError, with tests that run without sentence-transformers or torch. CI is green and patch coverage is ~98%. Happy to rebase or adjust anything if it'd help before merge. Thanks for all the work on PyOD!

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