From b46f22433c810a9ee79d37bd42c4d1b26641d494 Mon Sep 17 00:00:00 2001 From: Alpamys Date: Thu, 4 Jun 2026 19:53:33 +0500 Subject: [PATCH] ci: warm HF Hub cache before tests to fix tiny-model 429 flake MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test job loads sshleifer/tiny-gpt2 and hf-internal-testing/tiny-random-gpt2 from HF Hub. Under transient HF rate-limiting (429) a single matrix cell would fail the model download (test_v07111.py::TestMiniLLM::test_anchor_term_with_file) and drop coverage under the 77% gate — observed reding 3 commits today (~2/7 cells per run). Add a best-effort pre-test step that snapshot_downloads both tiny models with 6 retries + backoff so the tests read from the warmed cache (verified locally: the test passes with HF_HUB_OFFLINE=1 once the cache is warm). The step never fails the job — it emits a ::warning:: if warming can't complete. CI-only; no version bump. --- .github/workflows/ci.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9dbd498..88cb7d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,6 +56,30 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: pip install -e ".[dev]" + - name: Warm HF Hub cache (tiny test models) + # Pre-download the tiny models the unit tests load, with retries, so a + # transient HF Hub 429 (Too Many Requests) on a single matrix cell does + # not red the whole run. Observed: ~5/7 cells download fine and ~2/7 hit + # a 429 — a retry loop reliably populates the cache so the tests then + # read from disk (no network). Never fails the job: if warming can't + # complete it emits a ::warning:: and lets the test step run as before. + shell: python + run: | + import time + from huggingface_hub import snapshot_download + + models = ["sshleifer/tiny-gpt2", "hf-internal-testing/tiny-random-gpt2"] + for repo in models: + for attempt in range(1, 7): + try: + snapshot_download(repo) + print(f"warmed {repo}") + break + except Exception as exc: # noqa: BLE001 — best effort, never fail the job + print(f"attempt {attempt}/6 for {repo} failed: {type(exc).__name__}: {exc}") + time.sleep(min(5 * attempt, 30)) + else: + print(f"::warning title=HF cache::could not warm {repo} after 6 attempts") - name: Run unit tests with coverage run: pytest tests/ -v --tb=short --junitxml=report.xml --cov=soup_cli --cov-report=xml:coverage.xml --cov-report=term-missing:skip-covered - name: Upload coverage to Codecov