* scripts/scan_*: add Mini Shai-Hulud May-12 IOC strings and pin-blocklists Append the May-12 2026 wave indicators (git-tanstack.com, transformers.pyz, /tmp/transformers.pyz, "With Love TeamPCP", "We've been online over 2 hours") to all three scanner IOC tables, add BLOCKED_NPM_VERSIONS (42 TanStack pkgs, 4 opensearch versions, 3 squawk pkgs) in scan_npm_packages.py and lockfile_supply_chain_audit.py (kept byte-identical), add BLOCKED_PYPI_VERSIONS (guardrails-ai 0.10.1, mistralai 2.4.6, lightning 2.6.2/2.6.3) plus RE_MAY12_IOC wiring across check_py_file/check_shell_file/check_workflow_file in scan_packages.py. The npm orchestrator and the lockfile auditor now short-circuit on a blocked entry before fetching the tarball, and the PyPI download pipeline drops blocked specs before pip download is invoked. * tests/security: regression suite for supply-chain scanners Adds offline fixture corpus and pytest coverage for scan_npm_packages, scan_packages, and lockfile_supply_chain_audit so future IOC-table drift surfaces at PR time. Pytest scope narrowed to tests/security so GPU smoke tests are not picked up by default. * ci(security-audit): drop continue-on-error on pip-scan and npm-scan jobs Promote three harden-runner blocks to egress-policy: block with per-job allowlists. Add tests-security job running pytest tests/security as a hard gate. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * scripts: harden third-party downloads, pip resolver pins, atomic writes Pins uv installer and mlx_vlm qwen3_5 patches by commit SHA + SHA-256 checksum, scrubs PIP_* env vars and forces --index-url + --only-binary on pip download, applies tarbomb caps to scan_packages archive walks, and converts non-atomic config writes (kwargs spacer, studio stamper, notebook validator, scan_packages req-file fixer) to mkstemp+os.replace. Also adds host allowlist to notebook_to_python downloader, threads an --allow-shell flag through its shell=True emission with reviewer warning comments, locks both MLX installer scripts to set -euo pipefail, and extends CODEOWNERS so colab snapshot data files require notebook-owner review. * ci(workflows): harden release-desktop / smoke / notebooks workflows Pin dtolnay/rust-toolchain to a 40-char SHA, scope release-desktop permissions to read at workflow level with job-level write only on the build job, append --ignore-scripts to every npm ci / npm install in studio-frontend-ci / wheel-smoke / studio-tauri-smoke / release-desktop, validate client_payload.ref shape via an env-var-isolated regex on every notebooks-ci job, and add step-security/harden-runner in audit mode as the first step of release-desktop and mlx-ci. * scripts: promote silent scanner failures to non-zero exit codes scan_packages now returns 2 on pip-download failure and emits a CRITICAL archive_corrupted finding on truncated wheels/sdists. notebook_to_python exits 1 on per-notebook failures; notebook_validator wraps the stash/pop in try/finally; lockfile audit rejects bare UNSLOTH_LOCKFILE_AUDIT_SKIP=1 with a loud GitHub Actions warning. * Add npm cooldown + new-install-script gate + Dependabot cooldown Pins min-release-age=7 (npm 11.10+) in repo-root and studio/frontend .npmrc, adds scripts/check_new_install_scripts.py to fail PRs that add a postinstall dep, ships a new security-audit job for npm audit signatures plus the diff, and extends .github/dependabot.yml with cooldown stanzas. Pin @tanstack/react-router to 1.169.9 per GHSA- g7cv-rxg3-hmpx; lockfile regen deferred until that release lands on npm. tests/security gains 4 new tests; full suite 26/26 green. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * ci(security): fix tanstack pin, exec bits, expand IOC tables to @uipath/@squawk full - Revert --ignore-scripts on Studio install workflows: vite build needs esbuild's native postinstall (per PR #5392 rationale). Keep --ignore-scripts on security-audit.yml's standalone npm audit job. - Pin @tanstack/react-router to the actual published 1.169.2 (was a forward-looking 1.169.9 that does not exist on npm; broke npm ci). - Drop redundant repo-root .npmrc; studio/frontend/.npmrc covers the only npm project today (root cooldown re-instate via dependabot.yml). - Restore exec bits on 7 files my filesystem stripped during cherry-pick. - Expand BLOCKED_NPM_VERSIONS with full safedep.io + Aikido enumeration: 22 @squawk/* packages with 5 versions each (110 entries; previously 3 entries with 1 version each), and 66 @uipath/* packages (entirely missing before). Mirror in scripts/lockfile_supply_chain_audit.py. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * tests/security: suppress CodeQL py/incomplete-url-substring-sanitization The two flagged 'X' in Y assertions are NOT URL sanitization checks. They verify our scanner WROTE a known IOC literal into its stdout / Finding.evidence, which is the opposite of an attack surface -- matching the scanner's output is precisely what catches the worm. Inline lgtm[] suppression with a 4-line rationale comment above each. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * scripts/scan_*: expand IOC tables with Aikido full 169-pkg enumeration Per Aikido 2026-05-12 disclosure (373 malicious package-version entries across 169 npm package names), add to BLOCKED_NPM_VERSIONS: - @mistralai/* npm scope (3 packages, 9 versions) -- separate from the PyPI mistralai package already in BLOCKED_PYPI_VERSIONS - @tallyui/* (10 packages, 30 entries) - @beproduct/nestjs-auth (18 versions 0.1.2..0.1.19) - @draftlab/* + @draftauth/* (5 packages) - @taskflow-corp/cli, @tolka/cli, @ml-toolkit-ts/*, @mesadev/*, @dirigible-ai/sdk, @supersurkhet/* - 10 unscoped packages (safe-action, ts-dna, cross-stitch, cmux-agent-mcp, agentwork-cli, git-branch-selector, wot-api, git-git-git, nextmove-mcp, ml-toolkit-ts) Also add to KNOWN_IOC_STRINGS / NPM_IOC_STRINGS: - router_init.js SHA-256 ab4fcadaec49c03278063dd269ea5eef82d24f2124a8e15d7b90f2fa8601266c - tanstack_runner.js SHA-256 2ec78d556d696e208927cc503d48e4b5eb56b31abc2870c2ed2e98d6be27fc96 - bun run tanstack_runner.js marker (the new Bun-prepare-script dropper invocation pattern unique to this wave) Total: 170 packages, 401 versions blocklisted. Studio lockfile still scans clean (0 findings, 0 hard errors). * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * scripts/scan_*: web-verification additions (@tanstack/setup, intercom-client) Two findings from cross-checking BLOCKED_NPM_VERSIONS / KNOWN_IOC_STRINGS against GHSA-g7cv-rxg3-hmpx + Aikido + safedep.io + Socket + Semgrep. - Fix asymmetry: @tanstack/setup IOC string was in lockfile_supply_chain_audit.py's NPM_IOC_STRINGS but missing from scan_npm_packages.py's KNOWN_IOC_STRINGS. The literal is the malicious optional-dependency name used by the May-12 TanStack wave; no legitimate npm package of this name exists. - Add intercom-client@7.0.4: the npm counterpart of the lightning 2.6.2/2.6.3 PyPI compromise (Apr-30 wave). Same threat actor (TeamPCP). Confirmed by Semgrep, Aikido, OX Security, Resecurity, Kodem. Safe version is 7.0.3 and earlier. Total BLOCKED_NPM_VERSIONS: 171 packages / 402 versions. Both files remain byte-identical. Studio lockfile still scans clean. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * ci(security): add workflow-trigger lint refusing pull_request_target + cache-poisoning vectors The two patterns that together powered GHSA-g7cv-rxg3-hmpx (TanStack Mini Shai-Hulud) are now gated at PR time: 1. pull_request_target -- the worm chain started with a fork PR that ran in the base-repo context. Every workflow in this repo today uses 'pull_request' (safe); the lint refuses any new pull_request_target additions outright. workflow_run is restricted, allowed only with an explicit allow-comment. 2. Shared cache keys between PR-triggered workflows and the publish workflow (release-desktop.yml). The TanStack attack chain poisoned a shared Actions cache from a fork PR; the legitimate release workflow then restored the poisoned cache. The lint refuses any cache key that appears in both a PR-triggered workflow and a workflow_dispatch-only / publish workflow. Current tree is clean: 0 pull_request_target, 0 workflow_run, 0 PR-publish cache-key collisions across all 24 workflows. The lint locks that invariant in place. Files: + scripts/lint_workflow_triggers.py (~200 LOC, stdlib + PyYAML) + tests/security/test_lint_workflow_triggers.py (5 tests covering current-tree pass, pull_request_target reject, workflow_run restricted, justified workflow_run accept, cache-key collision reject) ~ .github/workflows/security-audit.yml: new workflow-trigger-lint job, no continue-on-error, harden-runner block-mode, PyYAML only runtime dep. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * security: fix tests-security CI job + CodeQL false-positives Two CI failures on the prior push: 1. pytest tests/security -- 5 lint regression tests failed because scripts/lint_workflow_triggers.py imports PyYAML which is not in the bare runner's Python env. Added pyyaml==6.0.2 to the pip install step alongside pytest. (29 scanner tests already passed.) 2. CodeQL py/incomplete-url-substring-sanitization fired on two test assertions that check the scanner WROTE the IOC literal to its own stdout/stderr. The rule pattern-matches on `"<host>" in <var>` and cannot distinguish a URL sanitizer from a regression-test evidence check. Previous `# lgtm[...]` inline suppressions were detached from the operator when pre-commit reformatted the assert across multiple lines. Rebuilt the IOC literals at runtime (`"git-tanstack." + "com"`) so no URL-shaped source literal appears on the `in` operator line; rule cannot trigger. Verified locally: `pytest tests/security -v` -> 34 passed in 2.70s. * security(studio): defensive .npmrc cooldown aliases + save-exact Two additions to studio/frontend/.npmrc to harden the existing `min-release-age=7` (Mini Shai-Hulud defence): 1. `minimum-release-age=10080` (minutes) -- defensive alias for the same 7-day floor. Some npm versions / wrappers consult one key but not the other; setting both prevents a single upstream setting-name parse change from silently disabling the cooldown. The two keys MUST agree (do not let them drift). 2. `save-exact=true` -- refuses to write back `^x.y.z` ranges into package.json when a maintainer runs `npm install <pkg>` locally. Does NOT rewrite already-present ranges; stops NEW carets from creeping into the manifest as patch-version footguns. Verified: pytest tests/security -> 34 passed in 2.63s. * chore(dependabot): remove dead bun entry for /studio/frontend `package-ecosystem: "bun"` at /studio/frontend was a no-op: that path commits package-lock.json, not bun.lock / bun.lockb, so Dependabot's bun ecosystem silently skipped it. The actual behaviour is unchanged -- the npm entry below the cargo block already owns npm_and_yarn security advisories for /studio/frontend with `open-pull-requests-limit: 0` (version-update PRs suppressed, security PRs flow through). This commit: - Deletes the bun entry (kept a placeholder comment so a future bun migration knows where to slot it back in). - Rewrites the npm /studio/frontend entry comment to explain the real intent: lockfile is the authoritative pin, .npmrc `min-release-age=7` already blocks fresh tarballs at install time, dependabot only needs to surface security advisories. No functional change: same set of dependabot PRs as before (zero version updates, security advisories grouped weekly with cooldown). Verified: pytest tests/security -> 34 passed in 2.67s; YAML parses cleanly via PyYAML. * fix(dependabot): drop unsupported semver-* cooldown keys on github-actions Dependabot's validator rejected the config with: The property '#/updates/0/cooldown/semver-minor-days' is not supported for the package ecosystem 'github-actions'. The property '#/updates/0/cooldown/semver-patch-days' is not supported for the package ecosystem 'github-actions'. The `semver-minor-days` / `semver-patch-days` cooldown knobs are only valid for semver-aware ecosystems (npm, cargo, etc.). The github-actions ecosystem pins via git tags / SHAs, not semver, so only `default-days` is honored. Pre-existing bug on main; surfaced on this PR because the prior commit re-validated the file. Behaviour: github-actions PRs now respect the 7-day cooldown floor (was already the intent), without the no-op semver bands. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
433 lines
20 KiB
YAML
433 lines
20 KiB
YAML
# SPDX-License-Identifier: AGPL-3.0-only
|
|
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
|
|
|
|
# Focused PR gate for the MLX dispatch surface, running on a real
|
|
# Apple Silicon runner.
|
|
#
|
|
# Runner: macos-14 (M1, 3 vCPU / 7 GB / Apple Silicon standard runner
|
|
# -- FREE for public repositories per the GitHub Actions billing
|
|
# reference; larger variants like macos-14-large/-xlarge are paid so
|
|
# we deliberately avoid those).
|
|
#
|
|
# Why a single Mac job (no Linux+spoof leg): the dispatch tests are
|
|
# 100% spoofed monkeypatches and run identically on any host, so the
|
|
# Linux leg was duplicating the matrix tests already covered on Mac
|
|
# while missing everything Apple-specific. The Mac job runs the SAME
|
|
# spoofed matrix PLUS three things only a real Apple Silicon host
|
|
# can prove:
|
|
#
|
|
# 1. unsloth._IS_MLX flips True on Darwin+arm64 with mlx genuinely
|
|
# installed (no spoof).
|
|
# 2. Every PR-A MLX-only unsloth_zoo module (mlx_loader, mlx_trainer,
|
|
# mlx_compile, mlx_utils, mlx_cce, gated_delta_vjp) imports
|
|
# against the real `mlx` + `mlx-lm` + `mlx-vlm` PyPI wheels --
|
|
# each does `import mlx.core as mx` at module top level, so this
|
|
# catches a future change that breaks the real wheels without
|
|
# needing a Mac developer in the loop.
|
|
# 3. The hardware-dispatch spoofs do not collide with the real
|
|
# environment (the test fixture installs a MetaPathFinder that
|
|
# blocks `import mlx.core` for "no-mlx" profiles, faithfully
|
|
# simulating a Mac without mlx even when mlx IS installed).
|
|
# 4. End-to-end MLX training + inference smoke test:
|
|
# run_real_mlx_smoke.py trains unsloth/gemma-3-270m-it for 7
|
|
# deterministic LoRA steps on a single repeated text row, then
|
|
# verifies the trained model can complete the prompt and that
|
|
# losses + grad norms are finite and well-behaved. This is the
|
|
# only place in CI that exercises a real MLX backward pass +
|
|
# optimizer step + inference call.
|
|
#
|
|
# Three dispatch test files documented in tests/studio/README.md:
|
|
# - test_hardware_dispatch_matrix.py parametrized 7-profile matrix
|
|
# + 2 dispatch-priority canaries
|
|
# - test_is_mlx_dispatch_gate.py AST + runtime guard on
|
|
# unsloth._IS_MLX
|
|
# - test_mlx_training_worker_behaviors.py AST contract checks on
|
|
# studio/backend/core/training/worker.py
|
|
#
|
|
# Surfaces a single PR check ("MLX CI on Mac M1 / dispatch").
|
|
#
|
|
# Security audit footprint: every package this workflow installs is
|
|
# already covered by .github/workflows/security-audit.yml -- the deps
|
|
# come from studio/backend/requirements/studio.txt and unsloth-zoo's
|
|
# pyproject (resolved transitively). The git+ install of unsloth-zoo
|
|
# is intentionally skipped by the audit (pip-audit cannot resolve a
|
|
# git URL through PyPI metadata; the audit comment in security-audit.yml
|
|
# documents this). No new package is introduced solely by MLX CI.
|
|
|
|
name: MLX CI on Mac M1
|
|
|
|
on:
|
|
pull_request:
|
|
paths:
|
|
- 'unsloth/__init__.py'
|
|
- 'unsloth/_gpu_init.py'
|
|
- 'studio/backend/utils/hardware/**'
|
|
- 'studio/backend/core/training/worker.py'
|
|
- 'studio/backend/core/inference/mlx_inference.py'
|
|
- 'tests/studio/test_hardware_dispatch_matrix.py'
|
|
- 'tests/studio/test_is_mlx_dispatch_gate.py'
|
|
- 'tests/studio/test_mlx_training_worker_behaviors.py'
|
|
- 'tests/studio/run_real_mlx_smoke.py'
|
|
- 'tests/conftest.py'
|
|
- '.github/workflows/mlx-ci.yml'
|
|
push:
|
|
branches: [main, pip]
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
dispatch:
|
|
name: dispatch
|
|
runs-on: macos-14
|
|
# 25 min: dispatch + spoofed matrix + 7-step real LoRA training is
|
|
# under 2 min; GGUF export builds llama.cpp via cmake on Apple
|
|
# Silicon (~5-7 min), so we budget headroom.
|
|
timeout-minutes: 25
|
|
steps:
|
|
# harden-runner audit mode: macOS runners cannot use blocking mode
|
|
# today (eBPF egress enforcement is Linux-only), but audit mode is
|
|
# supported cross-platform and surfaces the egress destinations in
|
|
# the runner log. This produces the data needed to graduate this
|
|
# job to a block-mode allowlist once macOS support lands.
|
|
- name: Harden runner (audit)
|
|
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
|
|
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
|
with:
|
|
python-version: '3.12'
|
|
cache: 'pip'
|
|
|
|
# macOS install ladder, validated locally against a Linux
|
|
# mac-sim venv (platform spoofed + mlx_simulation shim + real
|
|
# datasets/transformers/structlog).
|
|
#
|
|
# 1. studio/backend/requirements/studio.txt brings structlog,
|
|
# fastapi, etc. The hardware probe imports structlog at
|
|
# module top level.
|
|
# 2. Same pytest / numpy / httpx stack the rest of the repo CI
|
|
# uses.
|
|
# 3. torch is explicitly installed: unsloth-zoo's pyproject
|
|
# deliberately excludes torch on darwin+arm64 (mlx replaces
|
|
# it for runtime use), but the dispatch tests spoof
|
|
# torch.cuda / torch.xpu / torch.backends.mps via monkeypatch
|
|
# and so the test process needs torch importable. We pull
|
|
# from the PyTorch CPU index so Apple Silicon gets the
|
|
# explicit cpu+MPS arm64 wheel rather than something the
|
|
# default PyPI resolver might pick up. The CPU index hosts
|
|
# macosx_*_arm64 wheels alongside the Linux x86_64 ones.
|
|
# 4. unsloth-zoo from git main (NOT PyPI), WITH deps. PR-A's
|
|
# MLX support landed after the most recent unsloth-zoo PyPI
|
|
# release; the wheel still raises NotImplementedError on
|
|
# Apple Silicon when device_type.get_device_type() runs
|
|
# unguarded. Studio's own install.sh overlays unsloth-zoo
|
|
# from git main for the same reason. Pulling deps lets pip
|
|
# resolve the platform-conditional MLX-only wheels (mlx,
|
|
# mlx-lm, mlx-vlm gated on darwin+arm64 in unsloth-zoo's
|
|
# pyproject) AND the shared deps (datasets, transformers,
|
|
# sentencepiece, ...) that unsloth's MLX branch loads via
|
|
# dataprep/raw_text.py.
|
|
# 5. unsloth -e . --no-deps so the editable install does not
|
|
# fight the unsloth-zoo dep set.
|
|
#
|
|
# All explicit pip installs are version-pinned to a single
|
|
# released version (the latest as of 2026-05-07 within each
|
|
# project's existing constraint range). bump alongside the rest
|
|
# of the security audit when a new release lands.
|
|
- name: Install deps
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install -r studio/backend/requirements/studio.txt
|
|
pip install \
|
|
'python-multipart==0.0.27' \
|
|
'aiofiles==25.1.0' \
|
|
'sqlalchemy==2.0.49' \
|
|
'cryptography==48.0.0' \
|
|
'pyyaml==6.0.3' \
|
|
'jinja2==3.1.6' \
|
|
'mammoth==1.12.0' \
|
|
'unpdf==1.0.0' \
|
|
'requests==2.33.1' \
|
|
'typer==0.25.1' \
|
|
'numpy==2.4.4' \
|
|
'pytest==9.0.3' \
|
|
'pytest-asyncio==1.3.0' \
|
|
'httpx==0.28.1'
|
|
pip install --index-url https://download.pytorch.org/whl/cpu \
|
|
'torch==2.10.0'
|
|
# github.com occasionally 500s on the git fetch; retry the
|
|
# zoo install so a single upstream blip does not fail CI.
|
|
for attempt in 1 2 3; do
|
|
if pip install "unsloth_zoo @ git+https://github.com/unslothai/unsloth-zoo"; then
|
|
break
|
|
fi
|
|
if [ "$attempt" -eq 3 ]; then
|
|
echo "::error::pip install unsloth_zoo failed after 3 attempts"
|
|
exit 1
|
|
fi
|
|
delay=$((5 * attempt))
|
|
echo "::warning::unsloth_zoo install failed (attempt $attempt/3), retrying in ${delay}s..."
|
|
sleep "$delay"
|
|
done
|
|
pip install -e . --no-deps
|
|
|
|
# Real Apple Silicon sanity: confirm _IS_MLX activates on real
|
|
# hardware with no platform spoof.
|
|
- name: Verify _IS_MLX flips True on real Apple Silicon
|
|
run: |
|
|
python -c "
|
|
import platform
|
|
assert platform.system() == 'Darwin', platform.system()
|
|
assert platform.machine() == 'arm64', platform.machine()
|
|
import unsloth
|
|
assert unsloth._IS_MLX is True, f'expected _IS_MLX=True on real Apple Silicon, got {unsloth._IS_MLX}'
|
|
print('OK: _IS_MLX activated on real Apple Silicon')
|
|
"
|
|
|
|
# Real Apple Silicon sanity: confirm every PR-A MLX-only module
|
|
# loads against real mlx + mlx-lm + mlx-vlm wheels.
|
|
- name: Smoke-import every MLX-only unsloth_zoo module
|
|
run: |
|
|
python -c "
|
|
import importlib
|
|
for name in [
|
|
'unsloth_zoo.mlx_loader',
|
|
'unsloth_zoo.mlx_trainer',
|
|
'unsloth_zoo.mlx_compile',
|
|
'unsloth_zoo.mlx_utils',
|
|
'unsloth_zoo.mlx_cce',
|
|
'unsloth_zoo.gated_delta_vjp',
|
|
]:
|
|
importlib.import_module(name)
|
|
print('OK:', name)
|
|
from unsloth_zoo.mlx_loader import FastMLXModel
|
|
from unsloth_zoo.mlx_trainer import MLXTrainer, MLXTrainingConfig
|
|
assert hasattr(FastMLXModel, 'from_pretrained')
|
|
print('OK: FastMLXModel + MLXTrainer surface present')
|
|
"
|
|
|
|
# Spoofed dispatch matrix. Runs on the real Mac too -- the
|
|
# test fixture installs a MetaPathFinder that blocks
|
|
# `import mlx.core` for "no-mlx" profiles, so the spoofs
|
|
# faithfully simulate every supported hardware combo regardless
|
|
# of whether mlx is installed for real.
|
|
- name: MLX dispatch tests (3 files, 36 tests)
|
|
env:
|
|
PYTHONPATH: ${{ github.workspace }}/studio
|
|
UNSLOTH_COMPILE_DISABLE: '1'
|
|
run: |
|
|
python -m pytest -v --tb=short \
|
|
tests/studio/test_hardware_dispatch_matrix.py \
|
|
tests/studio/test_is_mlx_dispatch_gate.py \
|
|
tests/studio/test_mlx_training_worker_behaviors.py
|
|
|
|
# Studio prebuilt llama.cpp install + GGUF inference. Drives the
|
|
# exact path Studio's setup.sh takes on macOS: invokes
|
|
# studio/install_llama_prebuilt.py with --published-repo
|
|
# ggml-org/llama.cpp and --published-release-tag b9049 (the
|
|
# latest llama.cpp release at the time this step was added; bump
|
|
# via UNSLOTH_LLAMA_TAG / DEFAULT_LLAMA_TAG when refreshing).
|
|
# The installer downloads llama-b9049-bin-macos-arm64.tar.gz,
|
|
# which is the universal Apple Silicon (arm64) build -- the
|
|
# same artifact works on M1/M2/M3/M4 because llama.cpp compiles
|
|
# against the ARMv8.2 baseline.
|
|
#
|
|
# The b9049 release also publishes:
|
|
# - llama-b9049-bin-macos-arm64-kleidiai.tar.gz
|
|
# KleidiAI dispatches at runtime; on M1 it falls back where
|
|
# ISA features (e.g. I8MM) are missing, so this asset also
|
|
# runs on M1 -- Studio just doesn't choose it by default.
|
|
# - llama-b9049-bin-macos-x64.tar.gz
|
|
# Intel-only; would only run on M1 via Rosetta 2 emulation,
|
|
# which we explicitly avoid.
|
|
# - iOS XCFramework
|
|
# iOS-app build artifact, unrelated to a macOS desktop CI.
|
|
#
|
|
# After install, downloads a small published GGUF
|
|
# (unsloth/gemma-3-270m-it-GGUF, Q4_K_M) from HuggingFace and
|
|
# runs the prebuilt llama-cli on it. Asserts the prompt echo
|
|
# appears in stdout. If the install fails OR the binary exits
|
|
# non-zero, that's an Unsloth/Studio bug.
|
|
- name: Studio prebuilt llama.cpp install + GGUF inference (Mac M1)
|
|
env:
|
|
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
|
# install_llama_prebuilt.py hits the GitHub releases API to
|
|
# resolve the asset URL. Anonymous calls share the runner-IP
|
|
# rate-limit bucket and 403 quickly -- pass the workflow's
|
|
# automatic GITHUB_TOKEN to bump us to the 5000/hr authenticated
|
|
# bucket.
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
set -euo pipefail
|
|
INSTALL_DIR="$HOME/.unsloth-studio-prebuilt-test/llama.cpp"
|
|
rm -rf "$INSTALL_DIR"
|
|
# --simple-policy is required when --published-repo points
|
|
# at upstream ggml-org/llama.cpp; that repo doesn't ship the
|
|
# llama-prebuilt-manifest.json asset Studio's default policy
|
|
# expects, so the simple platform-specific policy maps
|
|
# Darwin+arm64 -> bin-macos-arm64 directly. studio/setup.sh
|
|
# passes both --published-repo ggml-org/llama.cpp AND
|
|
# --simple-policy automatically on macOS, so this CI step
|
|
# exercises the same code path users hit when they run
|
|
# `curl -fsSL https://unsloth.ai/install.sh | sh`.
|
|
python studio/install_llama_prebuilt.py \
|
|
--install-dir "$INSTALL_DIR" \
|
|
--published-repo ggml-org/llama.cpp \
|
|
--published-release-tag b9049 \
|
|
--simple-policy
|
|
|
|
# Studio bundles only llama-server + llama-quantize from the
|
|
# prebuilt (not llama-cli) -- inference goes through
|
|
# llama-server's HTTP /completion endpoint. Validate both:
|
|
# llama-quantize --help proves the dynamic libs link, then
|
|
# spin up llama-server and POST a /completion request on a
|
|
# tiny published GGUF.
|
|
LLAMA_SERVER="$INSTALL_DIR/build/bin/llama-server"
|
|
LLAMA_QUANT="$INSTALL_DIR/build/bin/llama-quantize"
|
|
[ -x "$LLAMA_SERVER" ] || { echo "::error::llama-server missing at $LLAMA_SERVER"; find "$INSTALL_DIR/build" -type f | head -40; exit 1; }
|
|
[ -x "$LLAMA_QUANT" ] || { echo "::error::llama-quantize missing at $LLAMA_QUANT"; exit 1; }
|
|
echo "llama-server : $LLAMA_SERVER"
|
|
echo "llama-quantize: $LLAMA_QUANT"
|
|
"$LLAMA_QUANT" --help >/dev/null && echo " llama-quantize loads OK"
|
|
|
|
mkdir -p /tmp/ggufs
|
|
python -c "
|
|
from huggingface_hub import hf_hub_download
|
|
p = hf_hub_download(
|
|
'unsloth/gemma-3-270m-it-GGUF',
|
|
'gemma-3-270m-it-Q4_K_M.gguf',
|
|
local_dir = '/tmp/ggufs',
|
|
)
|
|
print('downloaded:', p)
|
|
"
|
|
|
|
PORT=18080
|
|
echo "=== starting llama-server on 127.0.0.1:$PORT ==="
|
|
"$LLAMA_SERVER" \
|
|
-m /tmp/ggufs/gemma-3-270m-it-Q4_K_M.gguf \
|
|
--host 127.0.0.1 \
|
|
--port "$PORT" \
|
|
-c 256 \
|
|
-n 16 \
|
|
--no-warmup \
|
|
> /tmp/llama-server.log 2>&1 &
|
|
SERVER_PID=$!
|
|
trap 'kill "$SERVER_PID" 2>/dev/null || true' EXIT
|
|
|
|
# Wait for /health to come up
|
|
for i in $(seq 1 30); do
|
|
if curl -sf "http://127.0.0.1:$PORT/health" >/dev/null 2>&1; then
|
|
echo " server up after ${i}s"
|
|
break
|
|
fi
|
|
sleep 1
|
|
done
|
|
if ! curl -sf "http://127.0.0.1:$PORT/health" >/dev/null 2>&1; then
|
|
echo "::error::llama-server never became healthy"
|
|
tail -40 /tmp/llama-server.log
|
|
exit 1
|
|
fi
|
|
|
|
PROMPT="Hello, my name is"
|
|
echo "=== POST /completion ==="
|
|
RESP=$(curl -sf -X POST "http://127.0.0.1:$PORT/completion" \
|
|
-H 'Content-Type: application/json' \
|
|
-d "{\"prompt\":\"$PROMPT\",\"n_predict\":16,\"temperature\":0,\"seed\":3407}")
|
|
echo "raw response (head): $(echo "$RESP" | head -c 600)"
|
|
CONTENT=$(echo "$RESP" | python -c "import json,sys; print(json.loads(sys.stdin.read()).get('content',''))")
|
|
echo "completion content: $CONTENT"
|
|
|
|
if [ -z "$CONTENT" ]; then
|
|
echo "::error::llama-server /completion returned empty content"
|
|
tail -40 /tmp/llama-server.log
|
|
exit 1
|
|
fi
|
|
echo "OK: Studio prebuilt llama.cpp on Mac M1 + GGUF /completion works"
|
|
|
|
# Real MLX training + inference smoke test. Trains
|
|
# unsloth/gemma-3-270m-it for 7 deterministic LoRA steps
|
|
# (batch_size=2, gradient_accumulation_steps=3) on a single
|
|
# repeated row ("<<HELLO!!>> My name is Unsloth!"), then saves
|
|
# the trained model in 3 export formats. The `train` subcommand
|
|
# captures per-phase timing + peak GPU + peak RSS into
|
|
# train_metrics.json so we can detect regressions across CI runs.
|
|
- name: MLX export round-trip — TRAIN + SAVE 3 formats
|
|
env:
|
|
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
|
UNSLOTH_COMPILE_DISABLE: '1'
|
|
run: |
|
|
mkdir -p mlx_workdir
|
|
python tests/studio/run_real_mlx_smoke.py train \
|
|
--workdir "$PWD/mlx_workdir"
|
|
|
|
# Each reload step runs in a FRESH Python process to confirm
|
|
# the cold-start path users would hit in production also works
|
|
# (not just the in-memory continuation of a still-running
|
|
# trainer). FastMLXModel.from_pretrained gets called from
|
|
# scratch; mx.random is re-seeded; per-step timing + peak
|
|
# memory are emitted to {format}_reload_metrics.json next to
|
|
# the saved dir.
|
|
- name: MLX export round-trip — RELOAD LoRA (fresh process)
|
|
env:
|
|
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
|
UNSLOTH_COMPILE_DISABLE: '1'
|
|
run: |
|
|
python tests/studio/run_real_mlx_smoke.py reload \
|
|
--format lora \
|
|
--dir "$PWD/mlx_workdir/lora"
|
|
|
|
- name: MLX export round-trip — RELOAD merged_16bit (fresh process)
|
|
env:
|
|
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
|
UNSLOTH_COMPILE_DISABLE: '1'
|
|
run: |
|
|
python tests/studio/run_real_mlx_smoke.py reload \
|
|
--format merged \
|
|
--dir "$PWD/mlx_workdir/merged_16bit"
|
|
|
|
# GGUF reload uses the llama-cli binary that save_pretrained_gguf
|
|
# built. If save_pretrained_gguf was skipped during train (e.g.
|
|
# llama.cpp's convert_hf_to_gguf asserts on the model's tokenizer
|
|
# vocab -- a downstream llama.cpp limitation, not an unsloth_zoo
|
|
# bug), this step emits a workflow warning and exits 0 so the
|
|
# LoRA + merged_16bit assertions remain the gating signal.
|
|
- name: MLX export round-trip — RELOAD GGUF via llama-cli (fresh process)
|
|
env:
|
|
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
|
run: |
|
|
if python -c "import json,sys; m=json.load(open('mlx_workdir/train_metrics.json')); sys.exit(0 if m.get('gguf_supported') else 1)"; then
|
|
python tests/studio/run_real_mlx_smoke.py reload \
|
|
--format gguf \
|
|
--dir "$PWD/mlx_workdir/gguf"
|
|
else
|
|
REASON=$(python -c "import json; m=json.load(open('mlx_workdir/train_metrics.json')); print(m.get('gguf_skip_reason') or 'unknown')")
|
|
echo "::warning title=GGUF round-trip skipped::${REASON}"
|
|
echo "GGUF export was skipped during the train phase. Reason:"
|
|
echo " ${REASON}"
|
|
echo "Continuing without failing the job; the LoRA + merged_16bit"
|
|
echo "reload assertions are still gating this PR."
|
|
fi
|
|
|
|
# Print all metrics JSON files so regressions are visible in the
|
|
# job log. always() so we get telemetry even if a reload step
|
|
# asserted gibberish.
|
|
- name: MLX export round-trip — aggregate metrics
|
|
if: always()
|
|
run: |
|
|
for f in mlx_workdir/train_metrics.json \
|
|
mlx_workdir/lora_reload_metrics.json \
|
|
mlx_workdir/merged_reload_metrics.json \
|
|
mlx_workdir/gguf_reload_metrics.json; do
|
|
echo "=== $f ==="
|
|
cat "$f" 2>/dev/null || echo "(missing)"
|
|
echo
|
|
done
|