Skip to content

Fix CI read-only cache failures by patching cached_files in conftest#47043

Open
ydshieh wants to merge 2 commits into
mainfrom
workaround_read_only
Open

Fix CI read-only cache failures by patching cached_files in conftest#47043
ydshieh wants to merge 2 commits into
mainfrom
workaround_read_only

Conversation

@ydshieh

@ydshieh ydshieh commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

CI

Context

In CPU CI, the shared HF cache is read-only (pre-populated with most models). Tests that call from_pretrained with a model not yet in the cache — or one with updated files — hit OSError: [Errno 30] Read-only file system and fail with an opaque error.

This is a temporary workaround. We are in discussion with the infra team to evaluate whether a proper writable cache system is feasible. Until then, we want a lightweight fix that handles the common cases without over-engineering.

Why not #46768

#46768 addressed this with a per-test @use_temp_cache_if_readonly decorator. We moved away from that approach because it is opt-in and contributors adding a new test can forget it.

Why patch cached_files instead of from_pretrained

Patching from_pretrained directly would require importing several large classes (PreTrainedModel, PreTrainedTokenizerBase, PretrainedConfig, ImageProcessingMixin, etc.) into conftest.py, which we want to avoid. transformers.utils.hub.cached_files is the common code path that all from_pretrained implementations go through for hub downloads, so a single patch there covers everything with no class imports.

What this does

Wraps transformers.utils.hub.cached_files in conftest.py with a try/except that catches EROFS only. On failure, a session-scoped tmp dir is created (lazily, once) and the call is retried with HF_HUB_CACHE and HF_XET_CACHE patched to it. All other tests continue to read from the pre-populated read-only cache as before.

This covers the common cases well enough for a temporary fix. Edge cases that don't go through cached_files are out of scope for now.

@ydshieh ydshieh requested a review from tarekziade July 3, 2026 15:34
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 28669757926:1
Result: success | Jobs: 2 | Tests: 24 | Failures: 0 | Duration: 2m 18s

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