Skip to content

ci(notebooks): give Notebook Validation its own HuggingFace model cache - #840

Merged
vishal-bala merged 12 commits into
mainfrom
fix/notebook-hf-model-cache
Nov 25, 2026
Merged

vishal-bala merged 12 commits into
mainfrom
fix/notebook-hf-model-cache

Conversation

@vishal-bala

@vishal-bala vishal-bala commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Notebook Validation intermittently fails with nbval's 60-second cell timeout on cells that construct HFTextVectorizer(model="redis/langcache-embed-v2"). The job restored the HuggingFace cache that the test jobs share, and that cache holds only the models the tests load. Two models are loaded only by the user-guide notebooks, redis/langcache-embed-v2 and BAAI/bge-reranker-base, so they were never in it, and actions/cache does not save again after an exact key hit, so nothing ever added them. Both models were therefore downloaded inside nbval cells on every run. On run 41813891110 the notebook job restored the shared cache with an exact hit, and then both cells that load langcache-embed-v2 timed out inside huggingface_hub's xet_get, part-way through the weight download.

Changes

A model cache owned by the notebook job

The notebook job restores its own cache, <os>-hf-notebooks-<hash>, keyed on the hash of .github/scripts/prefetch_notebook_models.py. A new step runs that script before nbval. It loads each listed model through HFTextVectorizer or HFCrossEncoderReranker, the classes the notebooks use, so the cache holds exactly the files they read. The cache is saved straight after that step, not in a post-job step, so a failing notebook cannot stop the save. The notebook job is the only job that saves this key. It runs only for same-repository, non-Dependabot events, and the fork-PR workflow does not run notebooks, so no untrusted code reaches the save.

nbval then runs with HF_HUB_OFFLINE=1. A notebook that loads a model missing from the script fails at once with an OSError naming offline mode, instead of downloading against the cell timeout. Adding a model to the notebooks therefore means adding it to the script, and the comment beside HF_HUB_OFFLINE says so. The restore has no restore-keys fallback, because an older entry would still hold models since removed from the list and nbval would pass offline on them. A change to the list therefore starts from an empty cache and downloads the listed models once, in the prefetch step.

One langcache model in the user guide

03_llmcache.ipynb used langcache-embed-v2 for its first cache, but its private and multi-field caches passed no vectorizer and so loaded the SemanticCache default, langcache-embed-v1. 10_embeddings_cache.ipynb named v1 explicitly. Both now use v2: 03_llmcache builds one vectorizer and passes it to all three caches, which also stops the guide loading the model three times. The prefetch list therefore holds three models: langcache-embed-v2, sentence-transformers/all-mpnet-base-v2 (the HFTextVectorizer default) and BAAI/bge-reranker-base. The saved outputs that depend on the model were refreshed by re-running those cells. The filtered check() results in 03_llmcache are the same under v2, and the stored key hash and printed model name in 10_embeddings_cache changed. The library default is unchanged.

  • HF_TOKEN moves from the nbval step, where offline mode makes it unused, to the download step.
  • The service-tests comment now says the notebook job restores that job's uv cache but keeps its own model cache.

Notes

The prefetch step runs on every run, including an exact cache hit. On a warm cache it only checks each file against the hub, and it is what fills in any file a newer sentence-transformers or transformers release needs from a model the cached snapshot lacks; skipping it on a hit would leave nbval to fail offline after such a dependency bump until the model list next changed.

The notebook job keeps needs: service-tests with the !cancelled() guard. It no longer reads the shared HuggingFace cache, but it still restores the PYTHON_VERSION uv cache that service-tests saves, and the ordering is what lets it.

AI Assistance

  • No AI assistance was used for this PR.
  • This PR is AI-assisted. I have reviewed and understood everything in it, and I take responsibility for it.

Claude Code (claude-opus-5-5): diagnosis from the CI logs, the workflow and script changes, the notebook edits, this description and the pre-PR review.

Reviewer Brief

Start here: .github/workflows/test.yml:477-522, the notebook job's restore, prefetch and save steps. They decide what is in the cache that nbval then reads offline.

Where it could fail

  • .github/workflows/test.yml:574: with HF_HUB_OFFLINE=1, any notebook that loads a model not listed in .github/scripts/prefetch_notebook_models.py:15-22, including through a class default such as SemanticCache() or HFTextVectorizer(), now fails rather than downloading; check that the list covers every model a non-NBVAL_SKIP cell loads.
  • docs/user_guide/03_llmcache.ipynb and 10_embeddings_cache.ipynb: nbval runs with --nbval-lax, so CI never compares the refreshed stored outputs with what the cells print.

Not verified: the cold-cache path, which this PR's first CI run will exercise, and the fail-fast OSError from an unlisted model inside nbval in CI.

Beyond CI: the listed models load offline from a local cache in 0.5 to 5 s each, and an unlisted model fails at once with an OSError; 06_rerankers.ipynb passes under nbval offline apart from its Cohere and VoyageAI cells, run without keys; the changed cells of 03_llmcache and 10_embeddings_cache ran without errors against Redis 8.4 with HF_HUB_OFFLINE=1.

Since the last brief:

Reviewed 38de9eb8, fixes in 9439e87a · Claude Code (claude-opus-5-5) · lenses: correctness, security, design, tests, docs


Note

Medium Risk
CI behavior changes materially: offline nbval will fail if any notebook loads a model not listed in the prefetch script, including implicit defaults.

Overview
Notebook Validation no longer relies on the shared service-test HuggingFace cache. It uses a dedicated cache keyed on .github/scripts/prefetch_notebook_models.py, runs that script to download notebook models before nbval, saves the cache even when notebooks fail, and runs nbval with HF_HUB_OFFLINE=1 so missing models fail immediately instead of hitting the per-cell download timeout.

The new prefetch script loads redis/langcache-embed-v2, sentence-transformers/all-mpnet-base-v2, and BAAI/bge-reranker-base through the same HFTextVectorizer / HFCrossEncoderReranker classes the guides use.

User-guide updates align models with that list: 03_llmcache.ipynb builds one shared v2 vectorizer for all SemanticCache examples (fewer loads, cleaner outputs), and 10_embeddings_cache.ipynb switches from langcache-embed-v1 to v2 with refreshed stored outputs.

Reviewed by Cursor Bugbot for commit 8b952bb. Bugbot is set up for automated code reviews on this repo. Configure here.

The notebook job shared the fixed `Linux-hf-cache` key with the test jobs.
Whichever test job misses first saves that entry, so it holds only the
models the tests load, and actions/cache never re-saves after an exact
hit. redis/langcache-embed-v2 and BAAI/bge-reranker-base are loaded only
by notebooks, so they were downloaded inside nbval cells on every run;
PR run 41813891110 timed out at 60s in huggingface_hub's xet_get right
after an exact cache hit.

The notebook job now restores a cache keyed on the hash of
.github/scripts/prefetch_notebook_models.py, downloads the listed models
before nbval, and saves straight after that step, so a failing notebook
cannot stop the save. nbval runs with HF_HUB_OFFLINE=1, so a notebook
that loads an unlisted model fails at once instead of downloading
against the cell timeout. The `needs: service-tests` ordering existed
only to wait for the shared cache, so it is dropped.
03_llmcache loaded v2 for its first cache but fell back to the
SemanticCache default, v1, for the private and multi-field caches, and
10_embeddings_cache named v1 explicitly. The notebook job therefore
downloaded and cached two 572 MB models where one does.

03 now builds one v2 vectorizer and passes it to all three caches, and
10 uses v2. The prefetch list drops v1. Outputs that depend on the
model were refreshed by re-running those cells; the filtered check()
results in 03 are unchanged under v2. The library default stays v1.
… runs (FDE-205)

- Replace setup-uv's built-in cache (no restore-keys) with
  actions/cache/restore + save, pruned with `uv cache prune --ci` and
  saved after install, before the tests. A uv.lock change now gets a
  partial hit instead of a cold rebuild.
- One saver per Python version: service-tests saves 3.11, the
  redis-py 8.x x redis:8.4 leg saves the others; every other job is
  restore-only. docs and lint's lock job no longer cache.
- HuggingFace cache: versioned key (-v2), restore-only in the matrix
  and notebooks, saved only by the canary; off actions/cache@v4.
- test-fork-pr.yml runs the service-tests action from this repository
  with save-cache false, so a fork PR cannot save main-scoped caches.
- Cancel superseded PR runs in test.yml and lint.yml; never cancel
  pushes, schedule or dispatch.
- Pin runs-on: ubuntu-24.04 (the cache key names the OS), drop the docs
  group from test legs, setup-python v5 -> v6.
…-205)

- test-fork-pr.yml: cache-mode: read on the job that runs fork code,
  and persist-credentials: false on the fork checkout; the comment now
  says what this does and does not stop.
- Pick the non-3.11 uv saver by redis:latest, the image value that
  never rotates, and note the dependency beside the matrix.
- Correct comments on the docs group, the canary's HF save and the
  runs-on pins.
Dropping `needs: service-tests` was wrong: besides the shared HF cache,
it orders the notebook job after the job that saves the Python 3.11 uv
cache, which the notebook job restores. Restore it with the same
`!cancelled()` guard the test matrix uses.

Move the notebook HF restore and save steps to actions/cache@v5, the
version the service-tests action already uses.
A prefix restore brought back the previous entry whole, so a model
removed from prefetch_notebook_models.py stayed in every later entry.
A notebook still loading it would pass nbval offline until the chain
of entries was evicted, which hid exactly the drift HF_HUB_OFFLINE=1
is there to catch. A model-list change now costs one cold download in
the prefetch step, outside nbval's per-cell timeout.
@vishal-bala vishal-bala added the auto:ci Updates to CI/CD workflows and processes label Nov 19, 2026
Resolve the run-service-tests action and test.yml conflicts with the
coverage change (#826): keep both the save-cache and pytest-args inputs,
and save the HF cache after the coverage-enabled test run. Bring the new
coverage and cluster-tests jobs onto the same caching rules: coverage
does not cache, cluster-tests restores the 3.11 uv and v2 HF caches
without saving, and both pin ubuntu-24.04.
…(FDE-205)

- auto-release.yml: enable-cache false in all three setup-uv steps. Its
  saves competed with the test caches for the 10 GB, and the publish job
  should not restore anything from the shared cache.
- test-fork-pr.yml: cache-mode read is enforced through a read-only
  cache token, so say so; the trusted-actions checkout is now described
  as the second guard it is.
- test.yml: name PYTHON_VERSION rather than 3.11 where the code keys off
  it, and drop two stale reasons from the coverage and docs comments.
@vishal-bala
vishal-bala changed the base branch from main to ci/FDE-205-cache-and-concurrency November 19, 2026 15:25
@vishal-bala
vishal-bala added this pull request to stack #860 November 19, 2026 15:25
…d-concurrency' into fix/notebook-hf-model-cache
@vishal-bala vishal-bala changed the title ci: prefetch notebook HF models into their own cache ci(notebooks): give Notebook Validation its own HuggingFace model cache Nov 19, 2026
@codecov-commenter

codecov-commenter commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.02%. Comparing base (afb688b) to head (8b952bb).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #840      +/-   ##
==========================================
- Coverage   80.21%   80.02%   -0.19%     
==========================================
  Files         121      121              
  Lines       14862    14862              
  Branches     2600     2600              
==========================================
- Hits        11922    11894      -28     
- Misses       2219     2258      +39     
+ Partials      721      710      -11     
Flag Coverage Δ
cluster ?
core 79.18% <ø> (ø)
service 79.86% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vishal-bala
vishal-bala marked this pull request as ready for review November 20, 2026 10:12
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T10:14:05.633719Z db65dca Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@limjoobin limjoobin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks! This PR moves the notebook model downloads out of nbval's cell timeout by prefetching into a notebook-owned cache and running nbval offline.

Base automatically changed from ci/FDE-205-cache-and-concurrency to main November 25, 2026 08:56
…fix/notebook-hf-model-cache

# Conflicts:
#	.github/workflows/test.yml
@vishal-bala
vishal-bala merged commit 1a64961 into main Nov 25, 2026
60 checks passed
@vishal-bala
vishal-bala deleted the fix/notebook-hf-model-cache branch November 25, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto:ci Updates to CI/CD workflows and processes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants