Skip to content

fix: download readme and respect subfolder - #392

Merged
stephantul merged 1 commit into
mainfrom
download-readme
Oct 8, 2026
Merged

stephantul merged 1 commit into
mainfrom
download-readme

Conversation

@stephantul

Copy link
Copy Markdown
Contributor

We didn't respect the subfolder argument any more and also didn't download the README, so the language field was not filled. Caught by integration tests.

@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
model2vec/persistence/persistence.py 98.82% <100.00%> (+0.08%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@greptile-apps

greptile-apps Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Model loading now downloads README and respects subfolders.

The PR appears safe to merge, with non-blocking gaps in cached README loading and test coverage.

Reviews (1) · Last reviewed commit: "download readme and respect subfolder" · Reviewed by Greptile

Comment on lines +147 to 148
if folder is not None and _has_valid_layout(folder / subfolder if subfolder else folder):
return folder

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Cached models still lose language

With force_download=False, a snapshot downloaded by the old code can contain all model files but no README.md. _has_valid_layout accepts it, so _resolve_folder returns before fetching the newly included README. model.language stays None even when the hub README declares a language.

Fetch missing README metadata without making a README mandatory for models that have none.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, and?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The actionable fix is to avoid returning a valid cached snapshot when its model directory lacks README.md; let it fall through to snapshot_download so the README can be fetched. Keep _has_valid_layout unchanged, so models that genuinely have no README remain valid.

Suggested change
if folder is not None and _has_valid_layout(folder / subfolder if subfolder else folder):
return folder
if folder is not None and _has_valid_layout(folder / subfolder if subfolder else folder):
model_folder = folder / subfolder if subfolder else folder
if (model_folder / "README.md").exists():
return folder

This preserves the cache fast path when the README is already present, while allowing older cached snapshots to acquire it. Repositories without a README may be rechecked on later loads unless the cache layer records that the README is absent.

Comment thread tests/test_persistence.py
with patch("model2vec.persistence.persistence.maybe_get_cached_model_path") as cache:
# Cached snapshot without the subfolder files
cache.return_value = tmp_path / "other"
model = StaticModel.from_pretrained("my_org/haha", subfolder="subfolder")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Test skips the cache fallback

test_hub_subfolder_loading patches an incomplete cache, but StaticModel.from_pretrained defaults to force_download=True. The cache patch is never used, so the test would pass even if the new cache-layout check were removed.

Pass force_download=False and assert that the cache was checked before the download.

@stephantul
stephantul merged commit f8523cd into main Oct 8, 2026
12 checks passed
@stephantul
stephantul deleted the download-readme branch October 8, 2026 12:56
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.

1 participant