Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
CI: let staging repos save dependency caches on upstream-main (#13711)
Daniel Hand594b8cb5651
diff --git a/.github/actions/frontend-dist-save/action.yml b/.github/actions/frontend-dist-save/action.ymlindex b3f6279a1f2..6157873c353 100644--- a/.github/actions/frontend-dist-save/action.yml+++ b/.github/actions/frontend-dist-save/action.yml@@ -118,7 +118,7 @@ runs:# simply skips this step, which is the behaviour wanted.- name: Save the built frontendif: >-- github.ref == 'refs/heads/main' && inputs.cache-hit != 'true'+ (github.ref == 'refs/heads/main' || (github.ref == 'refs/heads/upstream-main' && github.repository != 'unslothai/unsloth')) && inputs.cache-hit != 'true'&& inputs.save != 'false'uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0continue-on-error: truediff --git a/.github/actions/pip-cache-save/action.yml b/.github/actions/pip-cache-save/action.ymlindex bd28cd56ad1..18e729a45df 100644--- a/.github/actions/pip-cache-save/action.yml+++ b/.github/actions/pip-cache-save/action.yml@@ -6,6 +6,13 @@# Runs on the default branch ONLY. That is the whole point: an entry written on a# pull_request ref is restorable only by re-runs of that same PR, so it buys no# hit rate and evicts the copy on main that every PR can read.+#+# One other branch ref saves too: `upstream-main` in a repository that is NOT+# unslothai/unsloth. Staging repos (scripts/pr_review/staging_ci.py) open their PRs+# against that branch and never push their own main, so main-only saves left them+# restoring stale seeds forever. A PR can restore from its base branch, so a seeding+# run dispatched on upstream-main gives every staged PR a current entry. Still never+# a PR ref, and never in this repository.name: Save the pip cachedescription: Save pip's cache under the restore step's key, on the default branch only.@@ -31,7 +38,7 @@ runs:# because a LATER step in the job failed. The install itself is what fills# this directory, and a failed test does not make its downloads wrong.if: >-- always() && github.ref == 'refs/heads/main'+ always() && (github.ref == 'refs/heads/main' || (github.ref == 'refs/heads/upstream-main' && github.repository != 'unslothai/unsloth'))&& inputs.cache-hit != 'true'uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0continue-on-error: truediff --git a/.github/actions/uv-cache-save/action.yml b/.github/actions/uv-cache-save/action.ymlindex 95dc9e1eee8..cdc8c883ca2 100644--- a/.github/actions/uv-cache-save/action.yml+++ b/.github/actions/uv-cache-save/action.yml@@ -39,7 +39,7 @@ runs:steps:- name: Prune the uv download cache to what is worth carryingif: >-- github.ref == 'refs/heads/main' && inputs.cache-hit != 'true'+ (github.ref == 'refs/heads/main' || (github.ref == 'refs/heads/upstream-main' && github.repository != 'unslothai/unsloth')) && inputs.cache-hit != 'true'&& inputs.save != 'false'shell: bashrun: |@@ -57,7 +57,7 @@ runs:- name: Save the uv download cacheif: >-- github.ref == 'refs/heads/main' && inputs.cache-hit != 'true'+ (github.ref == 'refs/heads/main' || (github.ref == 'refs/heads/upstream-main' && github.repository != 'unslothai/unsloth')) && inputs.cache-hit != 'true'&& inputs.save != 'false'uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0continue-on-error: truediff --git a/.github/workflows/studio-backend-ci.yml b/.github/workflows/studio-backend-ci.ymlindex dcb3d90c727..7eaca683fe4 100644--- a/.github/workflows/studio-backend-ci.yml+++ b/.github/workflows/studio-backend-ci.yml@@ -99,6 +99,9 @@ on:- '.github/workflows/woa-wheelhouse.yml'- '.github/scripts/retry-with-apt-lock.sh'- '.github/workflows/security-audit.yml'+ # Staging repos dispatch this on `upstream-main` to seed their dependency caches+ # (scripts/pr_review/staging_ci.py); see .github/actions/pip-cache-save.+ workflow_dispatch:concurrency:# One group per workflow, ref and event. On a PR branch a new push cancels the old run.@@ -112,7 +115,7 @@ concurrency:# keeps a nightly or a dispatch from being replaced by a push. The contract is enforced# by tests/studio/test_main_runs_survive_merge_bursts.py.group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/studio-frontend-ci.yml b/.github/workflows/studio-frontend-ci.ymlindex 9bbd23a2c12..4b49c721ba9 100644--- a/.github/workflows/studio-frontend-ci.yml+++ b/.github/workflows/studio-frontend-ci.yml@@ -91,13 +91,16 @@ on:- 'scripts/lockfile_supply_chain_audit.py'- '.github/workflows/studio-frontend-ci.yml'- '.github/scripts/retry-with-apt-lock.sh'+ # Staging repos dispatch this on `upstream-main` to seed their dependency caches+ # (scripts/pr_review/staging_ci.py); see .github/actions/pip-cache-save.+ workflow_dispatch:concurrency:group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}# Latest-only on a PR branch. On main, cancel-in-progress is false so a RUNNING run is# never killed, and a newer push replaces only the PENDING one: a merge burst runs the# commit already executing plus the tip. See studio-backend-ci.yml for the trade.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: read@@ -405,7 +408,7 @@ jobs:# test_cache_budget_discipline.py fails the build if either save reaches for# always() again.- name: Save the Playwright browser cache- if: github.ref == 'refs/heads/main' && steps.pw-cache.outputs.cache-hit != 'true'+ if: (github.ref == 'refs/heads/main' || (github.ref == 'refs/heads/upstream-main' && github.repository != 'unslothai/unsloth')) && steps.pw-cache.outputs.cache-hit != 'true'uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0continue-on-error: truewith:@@ -413,7 +416,7 @@ jobs:key: ${{ steps.pw-cache.outputs.cache-primary-key }}- name: Save the apt archive cache- if: github.ref == 'refs/heads/main' && steps.apt-cache.outputs.cache-hit != 'true'+ if: (github.ref == 'refs/heads/main' || (github.ref == 'refs/heads/upstream-main' && github.repository != 'unslothai/unsloth')) && steps.apt-cache.outputs.cache-hit != 'true'uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0continue-on-error: truewith:diff --git a/.github/workflows/studio-ui-smoke.yml b/.github/workflows/studio-ui-smoke.ymlindex 49d5342cc51..78a0e245cde 100644--- a/.github/workflows/studio-ui-smoke.yml+++ b/.github/workflows/studio-ui-smoke.yml@@ -492,7 +492,7 @@ jobs:# restored by re-runs of that same PR while still counting against the shared# budget, evicting the copy every PR can read.if: >-- github.ref == 'refs/heads/main'+ (github.ref == 'refs/heads/main' || (github.ref == 'refs/heads/upstream-main' && github.repository != 'unslothai/unsloth'))&& steps.apt-cache.outputs.cache-hit != 'true'continue-on-error: trueuses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0@@ -502,7 +502,7 @@ jobs:- name: Save the Playwright browser cacheif: >-- always() && github.ref == 'refs/heads/main'+ always() && (github.ref == 'refs/heads/main' || (github.ref == 'refs/heads/upstream-main' && github.repository != 'unslothai/unsloth'))&& steps.pw-cache.outputs.cache-hit != 'true'&& steps.pw-install.outcome == 'success'uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0@@ -1250,7 +1250,7 @@ jobs:# restored by re-runs of that same PR while still counting against the shared# budget, evicting the copy every PR can read.if: >-- github.ref == 'refs/heads/main'+ (github.ref == 'refs/heads/main' || (github.ref == 'refs/heads/upstream-main' && github.repository != 'unslothai/unsloth'))&& steps.apt-cache.outputs.cache-hit != 'true'continue-on-error: trueuses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0@@ -1260,7 +1260,7 @@ jobs:- name: Save the Playwright browser cacheif: >-- always() && github.ref == 'refs/heads/main'+ always() && (github.ref == 'refs/heads/main' || (github.ref == 'refs/heads/upstream-main' && github.repository != 'unslothai/unsloth'))&& steps.pw-cache.outputs.cache-hit != 'true'&& steps.pw-install.outcome == 'success'uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0diff --git a/.github/workflows/studiobench-ci.yml b/.github/workflows/studiobench-ci.ymlindex 34345f8e959..904f6f10ca3 100644--- a/.github/workflows/studiobench-ci.yml+++ b/.github/workflows/studiobench-ci.yml@@ -262,7 +262,7 @@ jobs:# reports cache-hit, skips the download, and leaves every later run with# engines that are not there. Same reasoning as studio-ui-smoke.yml.if: >-- always() && github.ref == 'refs/heads/main'+ always() && (github.ref == 'refs/heads/main' || (github.ref == 'refs/heads/upstream-main' && github.repository != 'unslothai/unsloth'))&& steps.pw-cache.outputs.cache-hit != 'true'&& steps.pw-install.outcome == 'success'uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0diff --git a/tests/studio/test_cache_budget_discipline.py b/tests/studio/test_cache_budget_discipline.pyindex 56f845e3f2f..66135a580c3 100644--- a/tests/studio/test_cache_budget_discipline.py+++ b/tests/studio/test_cache_budget_discipline.py@@ -167,6 +167,15 @@ _MAIN_ONLY = re.compile(r"github\.ref\s*==\s*['\"]refs/heads/main['\"]")_LEAF_MAIN = re.compile(r"github\.ref\s*==\s*['\"]refs/heads/main['\"]|['\"]refs/heads/main['\"]\s*==\s*github\.ref")+# Staging repos (scripts/pr_review/staging_ci.py) open PRs against `upstream-main` and never+# push their own main, so their dependency caches are seeded by a run dispatched on that branch.+# The equality counts as restricted ONLY next to an AND-ed guard that excludes this repository:+# a branch ref is never a PR ref, but here upstream-main has no business saving anything.+_LEAF_SEED = re.compile(+ r"github\.ref\s*==\s*['\"]refs/heads/upstream-main['\"]"+ r"|['\"]refs/heads/upstream-main['\"]\s*==\s*github\.ref"+)+_NOT_THIS_REPO = re.compile(r"github\.repository\s*!=\s*['\"]unslothai/unsloth['\"]")def _restricted_to_main(expr: str) -> bool:@@ -187,18 +196,27 @@ def _restricted_to_main(expr: str) -> bool:if not expr.strip():return False- def restricted(part: str) -> bool:+ def strip(part: str) -> str:part = part.strip()while part.startswith("(") and part.endswith(")") and _balanced(part[1:-1]):part = part[1:-1].strip()+ return part++ def restricted(part: str, seed_ok: bool = False) -> bool:+ part = strip(part)ors = _split_top(part, "||")if len(ors) > 1:return all(restricted(p) for p in ors)ands = _split_top(part, "&&")if len(ands) > 1:- return any(restricted(p) for p in ands)+ # The staging seed branch is accepted only when a SIBLING of this same AND+ # excludes this repository; the guard cannot come from an outer level.+ guarded = any(_NOT_THIS_REPO.fullmatch(strip(p)) for p in ands)+ return any(restricted(p, seed_ok = guarded) for p in ands)if re.search(r"!(?!=)", part):return False+ if seed_ok and _LEAF_SEED.fullmatch(part):+ return True# The leaf must BE the equality, not contain it. Searching inside accepted# every wrapper that quotes it and inverts it: `(...) == false`, `... != true`,# and `startsWith(..., 'false')`, which is true off main because GitHub casts@@ -247,6 +265,28 @@ def _restricted_to_main(expr: str) -> bool:# The reversed operand order is the same guard and stays accepted.("'refs/heads/main' == github.ref", True),("always() && (github.ref == 'refs/heads/main' && !cancelled())", True),+ # The staging seed: upstream-main, and only outside this repository.+ (+ "always() && (github.ref == 'refs/heads/main' || (github.ref == 'refs/heads/upstream-main'"+ " && github.repository != 'unslothai/unsloth')) && x != 'true'",+ True,+ ),+ ("github.ref == 'refs/heads/upstream-main'", False),+ ("github.ref == 'refs/heads/upstream-main' && always()", False),+ # The repository guard must be an AND sibling of the seed equality itself.+ (+ "github.repository != 'unslothai/unsloth' && (github.ref == 'refs/heads/upstream-main'"+ " || github.event_name == 'pull_request')",+ False,+ ),+ (+ "github.ref == 'refs/heads/upstream-main' && github.repository == 'unslothai/unsloth'",+ False,+ ),+ (+ "github.ref == 'refs/heads/upstream-main' || github.repository != 'unslothai/unsloth'",+ False,+ ),],)def test_the_main_only_expression_check_reads_the_expression(expr, restricted):