Skip to content

Conversation

arvinder004
Copy link

What does this PR do?

The offline test was skipped and brittle due to reliance on TRANSFORMERS_OFFLINE and pre-warmed caches. Standardize on HF_HUB_OFFLINE and make the test self-contained and deterministic.

Fixes #41311

Changes:

  • Unskip test_offline_mode.
  • Implement two-step subprocess approach:
    • Step 1: Warm cache online by loading config, model, tokenizer, and a small pipeline.
    • Step 2: Run offline with HF_HUB_OFFLINE=1 and a socket.socket monkey-patch to fail on any network access; load everything from local cache.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?
    • Updated tests/utils/test_offline.py::OfflineTests::test_offline_mode to be hermetic (two-step subprocess: cache warmup online, then offline with HF_HUB_OFFLINE=1 and socket mock).

How to validate

Run: pytest -q tests/utils/test_offline.py::OfflineTests::test_offline_mode

@Cyrilvallez
@Rocketknight1
@ydshieh

Copy link
Contributor

github-actions bot commented Oct 3, 2025

[For maintainers] Suggested jobs to run (before merge)

run-slow: gpt2

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.

Unskip and fix test_offline_mode by using HF_HUB_OFFLINE and hermetic cache warmup
1 participant