Repository navigation
feat(studio): Mac adapter-format option for LoRA export, with GGUF adapters on macOS - #7539
Merged
danielhanchen merged 16 commits intoSep 29, 2026
Merged
Conversation
…s on macOS
Adds adapter_format ('mlx' | 'peft') to the LoRA export API, threaded through the route, orchestrator, worker, and export backend. Omitting the field resolves to the platform's native format — MLX servers keep writing MLX adapters, CUDA servers keep writing PEFT adapters, byte-identical to today — so existing clients are unaffected. Explicit 'peft' on an MLX server converts through unsloth-zoo's adapter exporter (an older unsloth-zoo without that capability surfaces an actionable upgrade error via a signature probe, so genuine zoo exceptions propagate untouched); explicit 'mlx' on a non-MLX server, or combined with gguf=True, is an error.
GGUF LoRA adapter export is now available on macOS/MLX: the backend materializes a PEFT adapter via unsloth-zoo, refuses adapters GGUF LoRA cannot represent (per-module alpha values, rsLoRA with per-module ranks, DoRA, full-module state, expert-parameter adapters) before checking dependencies, then runs llama.cpp's convert_lora_to_gguf.py with the same script discovery and source-checkout fallback the CUDA path uses, forwarding the approved trust_remote_code decision. A conversion failure removes the just-published directory so retries are not refused as existing destinations.
Adapter directories and Hub repos never mix formats: local exports refuse a destination already carrying the other format's weight files (recursively, covering peft named-adapter subdirectories and the legacy adapter_model.bin spelling), and Hub pushes go through a single create_commit pinned to a pre-checked revision (parent_commit) so the Hub itself rejects concurrent writers — with fresh single-use operations per attempt, one re-check retry, a post-commit verification covering the client's all-unchanged short-circuit, and preservation of a repo-authored README.
Adapter listings gain a compact adapter_features summary (dora / full_state / moe_target_parameters / non_uniform) parsed from adapter configs with typed checks and a safetensors header probe for auto-saved embedding state, as the data source for format-compatibility UI copy.
…ility tips The LoRA export card on Apple-silicon hosts gains a Safetensors-format choice (MLX, the default and today's native output, or PEFT via the new backend conversion), and its GGUF adapter toggle is enabled there — dispatching through the LoRA-adapter export path with the conversion limitations named in the helper copy (per-module alpha values, rsLoRA with per-module ranks, DoRA, replaced embeddings or modules_to_save, expert-parameter targets). The GGUF / Llama.cpp method is untouched: it stays a CUDA-side surface, and Mac hosts export GGUF LoRA adapters only through the LoRA card's toggle. Payloads carry an explicit adapter_format only from Mac hosts for non-GGUF adapter exports; other platforms keep omitting the field, preserving their native behavior. Compatibility copy is driven by real adapter metadata: checkpoint listings now expose an adapter_features summary (dora / full_state / moe_target_parameters / non_uniform) parsed per training run. full_state is tri-state in both artifact formats — a config marker is a verified positive, a weight-header probe verifies a negative, and a skipped (bulk listings) or failed probe stays unknown — because absence of a marker proves nothing: PEFT auto-saves embedding state only as weight keys, and native MLX trainer checkpoints can carry unmarked non-LoRA trainable tensors. The vLLM compatibility claim renders only when all four flags are verified false; DoRA and full-module state render a not-supported-by-vLLM note, per-module patterns note vLLM's single global rank/alpha, expert-parameter adapters note that support varies, and non-uniform MLX exports carry the stock-mlx-lm loading caveat. Unknown or missing metadata always gets neutral copy. The repository intentionally gains no JS test harness; the selector, tips, payload, and error-surface behaviors are validated by recorded checks kept outside the repo, and the in-repo gates remain typecheck and build.
Adds --adapter-format (mlx | peft) to the export command's lora format, forwarding the value to the export backend, which resolves omission to the platform's native format. The option is registered everywhere but advertised only on Apple-silicon hosts, where the format choice exists; explicit use elsewhere — or with a non-lora format, or with an invalid value — errors on stderr with exit 2 before any backend work. Conversion failures (for example an unsloth-zoo without PEFT export support) surface through the command's existing error path: the backend's actionable message on stderr and a non-zero exit.
… over them parent_commit pinned the adapter commit to a pre-checked head so the Hub rejects a concurrent writer, but the handler then re-read the head and committed on top, replacing an adapter another process had just published. Raise instead of retrying, and claim only what holds for every create_commit failure: the commit was not confirmed and was not re-applied over a newer head.
Lyxot
force-pushed
the
feat/studio-lora-adapter-format
branch
from
August 17, 2026 12:36
218acd2 to
5430db5
Compare
Resolve conflicts against main's Hub push rework (_open_hub_repo, model card, reused-folder staging). Keep main's Hub upload path instead of the compare-and-swap commit rewrite, which is split out of this PR. PEFT and GGUF adapter exports on MLX now stage in a fresh sibling and move into the destination, so a repeat export into the same folder overwrites like the native save instead of failing the zoo's fresh-destination check.
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Sep 29, 2026
A Hub push always saves locally first, and the Hub destination hides the folder picker, so after a native MLX export the PEFT push to the same default folder hit the one-format-per-folder refusal with no way out.
install_llama_cpp probes apt-get for build dependencies even with just_clone_repo=True, so GGUF adapter export failed on macOS with 'apt-get does not exist'. A shallow clone is all convert_lora_to_gguf.py needs; UNSLOTH_AUTO_INSTALL=0 is still honored. The converter test no longer depends on torch being installed on the runner.
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Sep 29, 2026
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Sep 29, 2026
Without safetensors installed, a config-only adapter raised instead of reporting full_state as unverified.
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Sep 29, 2026
Clone llama.cpp at the revision zoo resolves for the installed binaries (the latest release otherwise) instead of the moving default branch, in a per-revision folder. Grant the converter child its credential through apply_token_to_child_env, which also resets an inherited HF_HUB_DISABLE_IMPLICIT_TOKEN=1 for explicit tokens.
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Sep 29, 2026
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Sep 29, 2026
danielhanchen
pushed a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Sep 29, 2026
danielhanchen
pushed a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Sep 29, 2026
danielhanchen
added a commit
to Datta0/unsloth-staging-3
that referenced
this pull request
Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Surfaces the new PEFT↔MLX adapter interop through Studio and the CLI, so a LoRA trained on Apple silicon can be exported in the standard Hugging Face format and used on a GPU machine, and vice versa.
Depends on unslothai/unsloth-zoo#957, which adds the conversion itself. Without that zoo change the new option surfaces a clear upgrade message rather than failing obscurely.
Three surfaces change:
export_loraaccepts anadapter_formatof"mlx"or"peft". Omitting it resolves to the platform default, which keeps every existing call byte-identical on both platforms.unsloth export --format loragains--adapter-format.Training and checkpoint output are untouched. Checkpoints remain MLX-format; only export is affected.
Why the option is Mac-only
On a CUDA machine PEFT already is the native format, so a selector there would offer a choice between one format and itself. The flag is registered on every platform so that explicit off-Mac use gets an actionable error instead of an unknown-argument failure, but it is advertised only where it applies.
GGUF LoRA adapters on macOS
GGUF LoRA files are built from a PEFT-format adapter, so this change also unlocks GGUF adapter export on Apple silicon: the MLX adapter is materialized as PEFT, then converted with llama.cpp's
convert_lora_to_gguf.py— the same pipeline the CUDA path uses.The GGUF method card is deliberately unchanged. Its LoRA-adapter target is not offered on Mac; GGUF adapters ship through the LoRA method's own toggle there, so the existing GGUF flow behaves exactly as before on both platforms.
Conversions that GGUF LoRA cannot represent are refused before converting rather than producing a misleading file: per-module alpha patterns (the format has one global alpha, and rsLoRA sources surface here because export bakes their scales into alphas), DoRA, full-module state, and expert-parameter adapters.
Feature detection is tri-state
The compatibility tip depends on knowing what an adapter contains, and a config marker alone cannot prove absence: PEFT auto-saves embedding and base state only as weight keys, and MLX trainer checkpoints may carry non-LoRA trainable tensors with no marker at all. Detection is therefore three-valued — a marker means true, a weight-header read can prove a negative, and a skipped or failed probe stays unverified.
This matters for one claim in particular. The tip only states vLLM compatibility when every relevant field is a verified false; an unverified field never earns that claim. Bulk listings skip the header probe for cost, which is safe because config markers still classify training-run adapters correctly.
Hub pushes
Hub uploads keep main's existing path (
_open_hub_repo+upload_folder); the compare-and-swap commit rewrite was split out of this PR. On MLX, PEFT and GGUF adapter exports are built in a fresh sibling folder and moved into the destination, so repeating an export into the same folder overwrites it like the native save does. On a Mac, PEFT and GGUF adapter exports default to their own-peftfolder, since one folder holds one adapter format.Validation
Frontend
tsc --noEmitis clean and the production build succeeds.The backend's six-cell platform × field matrix is covered by tests: omission stays byte-identical to the pre-existing native call on both platforms, and explicit native values match it. That is the property that keeps this change inert for existing users.
End-to-end, the export path was exercised against a real CUDA host: a Studio-style PEFT export of an MLX-trained adapter loads in
transformers/PEFT on a GPU machine and continues training there.Notes for reviewers
_resolve_adapter_formatis the single place platform policy is decided; the backend never infers the format anywhere else.AttributeError.Screenshots
Export page, LoRA Only card, merge base (BEFORE) vs this PR (AFTER). Both Studios were built from source on Linux with
/api/healthreporting an Apple-silicon Mac host, which is the only thing that switches the card to its Mac branch.MLX selected (default): the GGUF adapter button is enabled and the Safetensors format selector appears.
PEFT selected: the compatibility tip switches to the PEFT copy.