Skip to content

CI: share the gemma-3-270m-it model cache across Linux, macOS and Windows - #8068

Merged
danielhanchen merged 1 commit into
mainfrom
ci/share-gemma3-270m-cache-cross-os
Aug 7, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci/share-gemma3-270m-cache-cross-os

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

What

One actions/cache entry for the gemma-3-270m-it model instead of three.

Every job that primes HF_HOME with unsloth/gemma-3-270m-it-GGUF / UD-Q4_K_XL already
used the identical path: hf-cache. The only thing splitting them into three separate cache
entries was ${{ runner.os }} at the front of the key. This drops it, bumps v2 -> v3, and
sets enableCrossOsArchive: true so Windows can join the same entry.

Ten cache steps across nine jobs now resolve to one key,
hf-unsloth/gemma-3-270m-it-GGUF-UD-Q4_K_XL-v3:

runner workflow / job
ubuntu-latest studio-api-smoke / api-smoke
ubuntu-latest studio-ui-smoke / ui-smoke
ubuntu-latest studio-inference-smoke / openai-anthropic
ubuntu-latest local-agent-guides-ci / prompt-cache
macos-15 studio-mac-ui-smoke / ui-smoke
macos-15 studio-mac-inference-smoke / inference-smoke (phase 1)
windows-latest studio-windows-api-smoke / api-smoke
windows-latest studio-windows-ui-smoke / ui-smoke
windows-latest studio-windows-inference-smoke / inference-smoke (phase 1)
windows-latest studio-windows-inference-smoke / no-vs-cpu

Live caches on main today hold Linux-hf-..., macOS-hf-... and Windows-hf-... for this
model, 0.22 GiB each, byte-identical.

Why this is safe: the payload really is identical

I did not infer this from the toolkit source. I ran a probe on a staging repo that downloads
this exact model on ubuntu-latest, macos-15 and windows-latest and dumps a sorted
inventory of everything under hf-cache with per-file sha256, symlink targets, and a check
for Windows-illegal characters.

All three OSes produce the same tree:

hub/models--unsloth--gemma-3-270m-it-GGUF/blobs/e5420636...   253934624   sha256=e5420636...
hub/models--unsloth--gemma-3-270m-it-GGUF/refs/main                   40   sha256=a21cf7fe...
hub/models--unsloth--gemma-3-270m-it-GGUF/snapshots/c90975db.../gemma-3-270m-it-UD-Q4_K_XL.gguf
    -> ../../blobs/e5420636...   (symlink, not dangling)
  • The blob filename is the file's own sha256, the snapshot directory is the repo commit sha.
    Both are content-derived, so both are OS-independent.
  • WIN_NAME_PROBLEMS=0 and CASE_COLLISIONS=0 on all three: no : ? * < > | ", no trailing
    dot or space, no reserved device name, no case-only collisions. The GGUF and hub filenames
    are already cross-OS safe as they stand.
  • Windows-hosted runners do create the snapshot symlink, so the hub layout is reproduced
    there identically rather than degraded to a copy.

The three entries that do vary are not content: hub/CACHEDIR.TAG is 191 bytes on
Linux/macOS and 195 on Windows (CRLF), the hub/.locks/*.lock placeholder is absent on
Windows, and xet/logs/xet_<timestamp>_<pid>.log is per-run noise. None of them is read back
by huggingface_hub, and a single shared entry means only one of the three variants is ever
stored anyway.

Empirical proof of the cross-OS restore

The same probe saves on one OS and restores on another. Run:
https://github.com/danielhanchen/unsloth-staging-2/actions/runs/31141007275

saved on restored on enableCrossOsArchive result
ubuntu-latest macos-15 not set Cache restored from key: xosprobe-g1-flat
ubuntu-latest windows-latest not set Cache not found for input keys: xosprobe-g1-flat
ubuntu-latest macos-15 true Cache restored from key: xosprobe-g1-flatx
ubuntu-latest windows-latest true Cache restored from key: xosprobe-g1-flatx
ubuntu-latest (HF_HOME tree) macos-15 true Cache restored from key: xosprobe-g1-hf
ubuntu-latest (HF_HOME tree) windows-latest true Cache restored from key: xosprobe-g1-hf
windows-latest ubuntu-latest true Cache restored from key: xosprobe-g1-winsave

Linux and macOS share with no flag at all (both runners have zstd 1.5.7 on PATH, so both
compute the same compression component of the cache version hash). Windows needs
enableCrossOsArchive: true and then works in both directions; it extracts with
"C:\Program Files\Git\usr\bin\tar.exe" ... --force-local --use-compress-program "zstd -d".

After the cross-OS restore on Windows, the relative snapshot symlink is intact and
huggingface_hub resolves the model offline from the Linux-written tree:

OFFLINE_RESOLVE ok D:\a\...\hf-cache\hub\models--unsloth--gemma-3-270m-it-GGUF\snapshots\c90975db...\gemma-3-270m-it-UD-Q4_K_XL.gguf 253934624

Same on macOS. The restored inventories on macOS and Windows are 21-for-21 identical to the
Linux one that produced them, including every sha256.

Cost

path is unchanged, so this is a pure key rename. The new key is cold, and prefix
restore-keys cannot rescue it (the old keys have the OS as a prefix, so nothing matches).
The first main run after merge therefore re-downloads 254 MiB once per OS, about 10 s each
on the runners I measured, then one of them saves and the other two log the benign
"Unable to reserve cache with key ... another job may be creating this cache" they already log
today when two Linux workflows race for the same key.

Steady state: one 0.22 GiB entry instead of three, and macOS/Windows jobs now restore from
whatever the far more frequent Linux workflows seeded, which is the real win here.

Also in this change

The save gates gain hashFiles('hf-cache/**/*.gguf') != ''. With a per-OS key a bad save only
hurt that OS; with a shared key it would poison all three, so the saves now require an actual
.gguf to be present. studio-mac-inference-smoke already had this guard and keeps its
!= 'skipped' semantics so a partial, resumable download still gets stored.

Deliberately not changed

The other five cache families are single-OS and have nothing to share with:
gemma-4-E4B-it (Linux only, 4.6 GiB), gemma-4-E2B-it + mmproj (macOS only, 3.26 GiB),
Qwen3-VL-2B-Instruct UD-Q4_K_XL + mmproj (Linux only, 1.62 GiB) and
Qwen3-VL-2B-Instruct UD-IQ2_XXS + mmproj (Windows only, 1.14 GiB). Renaming their keys would
buy a cold re-download and no sharing. The two Qwen3-VL entries are the same repo at different
quants, so they are not interchangeable either.

…dows

The tree under hf-cache is byte-identical on all three runners, so the
runner.os prefix in the key only ever bought three copies of the same
254 MiB download. Drop it, bump v2 -> v3, and set enableCrossOsArchive
so Windows can join the same entry.

Also require hashFiles('hf-cache/**/*.gguf') != '' before saving: a
shared key means a bad save now poisons three OSes, not one.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f39f1768fe

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

with:
path: hf-cache
key: ${{ runner.os }}-hf-${{ env.GGUF_REPO }}-${{ env.GGUF_VARIANT }}-v2
key: hf-${{ env.GGUF_REPO }}-${{ env.GGUF_VARIANT }}-v3

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include the validation GGUF in every shared-cache producer

When the prompt-cache job wins the main-branch save race, this shared key contains only the Gemma GGUF because its prime step downloads no ggml-org/models/tinyllamas/stories260K.gguf. The API/UI and macOS/Windows workflows use the same immutable key, treat that restore as a hit, and skip their prime steps that explicitly add stories260K; their installer then has to fetch the validation model live (studio/install_llama_prebuilt.py:7049-7051), so an HF outage or transient download failure can break jobs that otherwise restored successfully. Add the validation GGUF here as well, or keep producers with different payloads on separate keys.

Useful? React with 👍 / 👎.

@danielhanchen

Copy link
Copy Markdown
Member Author

Source-level confirmation of why the staging results above come out the way they do, for anyone
reviewing this without re-running the probe. All line references are actions/toolkit at
e827417593127a004d22536bfe2ec916e191d15d, the commit that pins packages/cache to 5.0.5,
which is what actions/[email protected] bundles (package-lock.json pins @actions/cache 5.0.5
and the npm tarball's function bodies are byte-identical to the committed dist/).

The key really is the only thing that was splitting these.
getCacheVersion (internal/cacheUtils.ts L136-159) hashes
paths.join('|') + '|' + compressionMethod + ('|windows-only' if win32 and not enableCrossOsArchive) + '|1.0'.
'windows-only' is the sole platform component, and it is skipped entirely when
enableCrossOsArchive is set. So on Windows with the flag the version is byte-identical to
Linux and macOS.

Why Linux and macOS already matched without the flag.
getCompressionMethod (L101-112) is not OS-aware at all:

const versionOutput = await getVersion('zstd', ['--quiet'])
...
if (versionOutput === '') { return CompressionMethod.Gzip }
else { return CompressionMethod.ZstdWithoutLong }

zstd present at any version gives zstd-without-long. actions/runner-images ships zstd 1.5.7
on ubuntu-24.04, macos-15-arm64 and windows-2025 alike, all three installed deliberately by
install-zstd.sh / Install-Zstd.ps1. The probe agreed: /usr/local/bin/zstd,
/opt/homebrew/bin/zstd and /c/tools/zstd/zstd, all v1.5.7.

enableCrossOsArchive changes nothing about the archive. It appears in cache.ts,
cacheUtils.ts, cacheHttpClient.ts and contracts.d.ts, and never in tar.ts. It is purely
a cache-version input. --force-local and the backslash-to-slash normalisation are pushed
unconditionally for GNU tar on win32.

Why the snapshot symlink survives the round trip. There is no -h / --dereference
anywhere in tar.ts, so links are stored as links. On Windows getTarPath() prefers
%PROGRAMFILES%\Git\usr\bin\tar.exe (GNU tar, present because windows-2025 ships
Git 2.55.0.windows.3) over System32\tar.exe (bsdtar), and execCommands passes
MSYS: 'winsymlinks:nativestrict', which makes it emit native NTFS symlinks. That matches the
probe log exactly:
"C:\Program Files\Git\usr\bin\tar.exe" -xf ... --force-local --use-compress-program "zstd -d",
and the restored snapshots/.../gemma-3-270m-it-UD-Q4_K_XL.gguf -> ../../blobs/e5420636... dangling=False.
The old bsdtar symlink failures (actions/cache#1010, #1043, toolkit#1293) are the path we do
not take on a hosted runner.


One caveat that is worth writing down even though it does not affect this PR.

The reason the hub layout is portable is that every name it generates is content-derived or a
literal: models--org--name, a hex etag for the blob, a commit sha for the snapshot directory.
What is not guarded is the repo's own filenames. _local_folder._validate_relative_filename
rejects only .. segments and absolute/UNC paths; nothing rejects : ? * < > |, a trailing
dot or space, or a reserved device name, and the Hub itself permits them - HF's own install
docs say so under "Windows limitations", and there are live repos with ?, :, |, \ and
trailing-space filenames.

So the general statement "an HF_HOME cache is cross-OS portable" is only true for repos whose
filenames happen to be Windows-safe. For the four models this repo caches it is true and I
verified it directly: WIN_NAME_PROBLEMS=0 and CASE_COLLISIONS=0 on all three runners for
both the hub layout and the flat --local-dir layout. I am not adding a guard for it, because
every model here is an unsloth/* GGUF with a plain [A-Za-z0-9._-] name and the check would
be protecting against an input CI never receives. It is worth knowing before pointing one of
these cache steps at an arbitrary third-party repo.

@danielhanchen
danielhanchen merged commit 292c479 into main Aug 7, 2026
31 of 33 checks passed
@danielhanchen
danielhanchen deleted the ci/share-gemma3-270m-cache-cross-os branch August 7, 2026 03:40
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.

1 participant