Repository navigation
ci(notebooks): give Notebook Validation its own HuggingFace model cache - #840
Conversation
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.
…otebook-hf-model-cache
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.
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.
…d-concurrency' into fix/notebook-hf-model-cache
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
limjoobin
left a comment
There was a problem hiding this comment.
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.
…fix/notebook-hf-model-cache # Conflicts: # .github/workflows/test.yml
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-v2andBAAI/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 loadlangcache-embed-v2timed out insidehuggingface_hub'sxet_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 throughHFTextVectorizerorHFCrossEncoderReranker, 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 anOSErrornaming 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 besideHF_HUB_OFFLINEsays so. The restore has norestore-keysfallback, 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.ipynbusedlangcache-embed-v2for its first cache, but its private and multi-field caches passed no vectorizer and so loaded theSemanticCachedefault,langcache-embed-v1.10_embeddings_cache.ipynbnamed v1 explicitly. Both now use v2:03_llmcachebuilds 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(theHFTextVectorizerdefault) andBAAI/bge-reranker-base. The saved outputs that depend on the model were refreshed by re-running those cells. The filteredcheck()results in03_llmcacheare the same under v2, and the stored key hash and printed model name in10_embeddings_cachechanged. The library default is unchanged.HF_TOKENmoves from the nbval step, where offline mode makes it unused, to the download step.service-testscomment 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-testswith the!cancelled()guard. It no longer reads the shared HuggingFace cache, but it still restores thePYTHON_VERSIONuv cache thatservice-testssaves, and the ordering is what lets it.AI Assistance
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: withHF_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 asSemanticCache()orHFTextVectorizer(), now fails rather than downloading; check that the list covers every model a non-NBVAL_SKIPcell loads.docs/user_guide/03_llmcache.ipynband10_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
OSErrorfrom 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.ipynbpasses under nbval offline apart from its Cohere and VoyageAI cells, run without keys; the changed cells of03_llmcacheand10_embeddings_cacheran without errors against Redis 8.4 withHF_HUB_OFFLINE=1.Since the last brief:
ca4e2a74) asdb65dca8; this PR's own lines are unchanged, apart from where they sit intest.yml.mainand this branch mergedmainas8b952bbd, keeping this PR's notebook-job hunks; its own lines are unchanged, and the uv cache it restores is nowPYTHON_VERSION3.12.Reviewed
38de9eb8, fixes in9439e87a· Claude Code (claude-opus-5-5) · lenses: correctness, security, design, tests, docsNote
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 withHF_HUB_OFFLINE=1so 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, andBAAI/bge-reranker-basethrough the sameHFTextVectorizer/HFCrossEncoderRerankerclasses the guides use.User-guide updates align models with that list:
03_llmcache.ipynbbuilds one shared v2 vectorizer for allSemanticCacheexamples (fewer loads, cleaner outputs), and10_embeddings_cache.ipynbswitches fromlangcache-embed-v1to 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.