Skip to content

Studio: push only the exported merged model to the Hub on a Mac - #12239

Merged
Lyxot merged 2 commits into
unslothai:mainfrom
NilayYadav:push-only-exported-merged-model
Sep 29, 2026
Merged

Lyxot merged 2 commits into
unslothai:mainfrom
NilayYadav:push-only-exported-merged-model

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

On a Mac, pushing a merged model to the Hugging Face Hub uploads the whole save folder. Even the first push sends export_metadata.json, which holds the full local path of your training run (like /Users/you/.unsloth/studio/outputs/run). If the folder already held a LoRA adapter exported there earlier, the adapter files land in the merged repo too.

The Mac merged push now uploads the way the other platforms already do, with a single upload of the folder instead of the resumable large-folder upload it used before. The local metadata file stays out, and a folder that was not empty gets a clean copy of the merged model uploaded instead. The model card is still uploaded, and the local export is unchanged.

Because the merged push now opens the repo like every other Studio push, an unticked Private switch no longer makes an existing private repo public here.

@NilayYadav NilayYadav left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Codex coverage

Mirror: NilayYadav#154, pinned to upstream head 47c76bb19445454712c71597f8a73af7b8774426 (same commit and tree as this PR's current head).

Rounds: 2. Converged: Codex answered "Didn't find any major issues" on 47c76bb in round 2.

  • Round 1, P1, pass the Hub token to the second (staged) MLX save for a reused folder: rejected: on the MLX path the bound save_pretrained_merged only reads token inside its push branch (unsloth_zoo mlx/utils.py save_pretrained_merged, push_to_hub False here) and save_merged_model takes no token, so forwarding it changes nothing; the reused-folder push also succeeded on Apple Silicon with no ambient Hugging Face credential in the Studio home.

Final Codex result on 47c76bb: no major issues.

@NilayYadav NilayYadav left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review + reproduction evidence

Pinned review: 47c76bb19445454712c71597f8a73af7b8774426. No blocking findings.

I reproduced the Mac merged push on this PR's merge base and on the PR head. Setup: Apple Silicon, macOS 26, Studio from ./install.sh --local in a throwaway home, logged in through the form, and a LoRA on unsloth/gemma-3-270m-it. I ran Export > Merged Model > Push to Hub, then listed the repo files with huggingface_hub:

  • main (1a46fe1):
    • Fresh folder: the repo gets export_metadata.json with "source_checkpoint": "/private/tmp/pr12239/base-home/studio/outputs/unsloth_gemma-3-270m-it_pr12239".
    • A merged push to the default folder after a LoRA save to it: the repo also gets adapter_config.json and adapters.safetensors. It is missing tokenizer.model, added_tokens.json, generation_config.json and special_tokens_map.json, because the .cache/ that upload_large_folder leaves in the export folder marks them as already committed.
    • A pre-created private repo with Private off: the repo was made public.
  • PR head (47c76bb): all three repos hold the same 11 model files, no metadata and no adapter files. The private repo stays private. No staging dir is left and no .cache/ is written into the export folder.
  • Adjacent flows, identical on both: LoRA push (5 files) and local-only merged export.

PR 12239 before/after

  • Same flows through a real Apple Silicon probe: it builds a real gemma-3-270m-it LoRA, then runs the real ExportBackend and unsloth_zoo save and push, with only the HfApi network calls recorded. On main it fails all 3 scenarios: upload_large_folder sends export_metadata.json, the reused folder also sends adapter_config.json and adapters.safetensors, and the private repo is left public. On the PR head all 3 pass with one upload_folder each. The macOS Actions A/B mirrors of this harness sat in the fork's queue for over an hour without starting, so I closed them. This result is from the same harness run on my Mac.

  • Upstream CI on this PR: 33 pass. The 2 red jobs fail only test_every_playwright_driver_is_invoked_by_ci on playwright_user_message_time.py. That test fails the same way on main 501b15f (Backend CI run 36489139211), so it is not caused by this PR.

  • Tests on Modal: the 4 new tests fail on the merge base and pass on the head. The other 38 tests in test_export_hub_push.py are unchanged.

  • Blast radius: only the _IS_MLX branch of the merged push changes. Non-Mac pushes, and Mac local, GGUF and LoRA exports, take the same code as before. A reused folder costs one extra merged save, the same as the non-Mac path.

Follow-up, not blocking: export_base_model has the same MLX push_to_hub_merged call (export.py around line 1283). The Export page never calls /export/base, so only raw API callers reach it.

Unrelated to this PR, and the same on main: the Push to Hub token field refuses Hugging Face OAuth tokens longer than 512 characters (PUT /api/settings/hugging-face-token returns 422). A merged push with the field empty also stops with "Repository ID and Hugging Face token required" instead of using the CLI login.

Conclusion: The bug is real on every Mac merged push, and the PR fixes it. The fix matches the non-Mac merged path. Ready to merge once upstream CI is green.

The Mac base-model push still handed the save folder to push_to_hub_merged, which uploads everything in it: export_metadata.json with the absolute path of the source checkpoint, leftovers of an earlier export to the same folder, and an unticked Private switch made an existing private repo public. Both Mac full-model pushes now share one upload helper that opens the repo like every other Studio push, skips the local metadata, and uploads a clean second save when the folder was reused.
@Lyxot

Lyxot commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Pushed 1fc1b7b on top of this PR: the Mac base-model push had the same problem as the merged one. export_base_model still handed the save folder to push_to_hub_merged, so it uploaded export_metadata.json (absolute source_checkpoint path), leftovers from an earlier export to the same folder, and made an existing private repo public when Private was unticked.

  • Both Mac full-model pushes (merged and base) now go through one helper, _push_mlx_merged, which opens the repo with _open_hub_repo, uploads with _HUB_UPLOAD_IGNORE, and uploads a clean second save when the folder was reused.
  • The MLX tests now run for merged 16-bit, merged 4-bit and base, and check the uploaded repo id and that a failed second save leaves the Hub untouched.

Validated with a real MLX load and LoRA merge on a tiny Qwen2 checkpoint, pushed to a recording fake HfApi: merged and base, fresh and reused folders, public and private, with and without a local save all upload only the model files, and the re-saved weights hash-match the local export.

@Lyxot

Lyxot commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Codex and CI on 1fc1b7b42e (staging mirror Lyxot#107, same head, based on this PR's merge base):

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. The Mac merged and base Hub pushes now upload only the exported model and never loosen repo visibility. Validated on a real MLX merge against a fake Hub, and Codex found no major issues. The remaining upstream failures come from main's own Playwright CI registration, which main has since fixed.

@Lyxot
Lyxot merged commit 852795d into unslothai:main Sep 29, 2026
43 of 45 checks passed
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.

2 participants