Skip to content

fix(inspect): distinguish local-path-not-found from network errors#679

Merged
DingmaomaoBJTU merged 4 commits into
mainfrom
qiowu/fix_input_output_issue
May 20, 2026
Merged

fix(inspect): distinguish local-path-not-found from network errors#679
DingmaomaoBJTU merged 4 commits into
mainfrom
qiowu/fix_input_output_issue

Conversation

@DingmaomaoBJTU
Copy link
Copy Markdown
Collaborator

Summary

Fixes #542. Two distinct failure modes were both surfacing as "Network error":

  • A bogus HF ID (totally-bogus/does-not-exist) → RepositoryNotFoundError is an OSError subclass, so the broad except OSError → NetworkError handler caught it
  • A missing local file (.\does-not-exist.onnx) → AutoConfig.from_pretrained raised a plain OSError with a confusing HF Hub message including "Network error"

Fix 1 — local path pre-check in inspect() (inspect.py)

Before touching HF Hub, classify the input. If it looks like a local path (absolute, backslash, dot-prefix, or has a file extension — none of which appear in normal org/model HF IDs) and does not exist, fail early with:

Error: Local path '.\does-not-exist.onnx' does not exist.

Fix 2 — explicit RepositoryNotFoundError catch in _inspect_model_v2() (inspect.py)

Catch RepositoryNotFoundError before the broad OSError handler so HF 404s map to ModelNotFoundError and surface as:

Error: Model not found: Model 'totally-bogus/does-not-exist' not found on Hugging Face Hub.

Tests (test_inspect_cli.py)

  • test_missing_local_file_shows_path_error — absolute tmp path without .onnx
  • test_missing_local_relative_path_shows_path_error./does-not-exist.onnx
  • test_bogus_hf_id_shows_model_not_found — patches AutoConfig.from_pretrained to raise RepositoryNotFoundError

Bogus HF IDs and missing local files were both reported as "Network error"
because AutoConfig.from_pretrained raises OSError in both cases, and the
handler blindly mapped all OSError to NetworkError.

Two targeted fixes:
- Add a local-path pre-check in inspect() that detects inputs looking like
  file paths (absolute, backslash, dot-prefix, or file extension) and fails
  early with "Local path '...' does not exist." before touching HF Hub.
- Catch RepositoryNotFoundError explicitly (before the broad OSError handler)
  in _inspect_model_v2() and re-raise as ModelNotFoundError so HF 404s
  show "Model not found: ..." instead of "Network error: ...".

Closes #542
@DingmaomaoBJTU DingmaomaoBJTU requested a review from a team as a code owner May 20, 2026 03:40
Comment thread src/winml/modelkit/commands/inspect.py Outdated
Copy link
Copy Markdown
Collaborator

@timenick timenick left a comment

Choose a reason for hiding this comment

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

Found a blocking regression in the local-path heuristic — bool(_p.suffix) will misclassify popular HF model IDs with dotted version numbers (Phi-3.5, Qwen2.5, Llama-3.1, …) as local paths and fail before any Hub lookup. See inline. Three smaller nits also flagged.

Comment thread src/winml/modelkit/commands/inspect.py Outdated
Comment thread tests/unit/commands/test_inspect_cli.py Outdated
Comment thread tests/unit/commands/test_inspect_cli.py
Comment thread tests/unit/commands/test_inspect_cli.py
Copy link
Copy Markdown

Copilot AI commented May 20, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • releases.astral.sh
    • Triggering command: /home/REDACTED/.local/bin/uv /home/REDACTED/.local/bin/uv run ruff check --fix (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from xieofxie May 20, 2026 03:53
Address PR #679 review comments:

- Replace bool(_p.suffix) with a allowlisted _LOCAL_FILE_EXTS set to avoid
  misclassifying dotted HF IDs (Phi-3.5, Qwen2.5, Llama-3.1, …) as local
  paths. Move the constant to module level.
- Tighten dot-prefix check to startswith(("./", "../")) so bare model names
  starting with a dot are not over-eagerly matched.
- Fix tmp_path type annotation: pytest.TempPathFactory → Path.
- Add test_dotted_hf_id_reaches_hub_path to pin the contract that HF IDs
  with version dots flow to the Hub branch and are never shown "does not exist".
Root cause: transformers catches RepositoryNotFoundError internally and
re-raises it as a plain OSError, so `except RepositoryNotFoundError` never
fires in practice. The error was still landing in `except OSError` and being
re-raised as NetworkError.

Fix: in the OSError handler, detect the recognisable HF Hub "not a valid
model identifier / not a local folder" message pattern and raise
ModelNotFoundError instead of NetworkError. The full original message is
preserved so the private-repository hint is visible in the error output.

Also update the test to mock the actual OSError that transformers raises
(not RepositoryNotFoundError directly) and assert the private-repo hint
is present in the output. Retain a separate test for the direct
RepositoryNotFoundError path as a defence-in-depth check.
Copy link
Copy Markdown
Collaborator

@timenick timenick left a comment

Choose a reason for hiding this comment

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

LGTM. All four prior review comments cleanly addressed:

  • bool(_p.suffix) regression → replaced with _LOCAL_FILE_EXTS allowlist via the new _looks_like_local_path() helper (now correctly handles Phi-3.5 / Qwen2.5 / Llama-3.1 / flan-t5-v1.1)
  • Test type annotation fixed via TYPE_CHECKING import of Path
  • Test docstring now matches the actual missing.onnx test code
  • test_dotted_hf_id_reaches_hub_path added as the suggested regression-pin

Bonus fix in e0f4941: caught that transformers.AutoConfig.from_pretrained re-wraps RepositoryNotFoundError as plain OSError, so the original except RepositoryNotFoundError handler would never have fired on the common path. The added message-pattern match plus test_bogus_hf_id_shows_model_not_found (which uses the real transformers error text and preserves the private-repo hint) closes this gap properly.

🤖 Generated with GitHub Copilot CLI

@DingmaomaoBJTU DingmaomaoBJTU merged commit c7d5586 into main May 20, 2026
9 checks passed
@DingmaomaoBJTU DingmaomaoBJTU deleted the qiowu/fix_input_output_issue branch May 20, 2026 06:54
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.

[winml inspect] [P0] Bogus HF id and missing local file both reported as "Network error"

4 participants