Skip to content

Studio: stop converting the model twice when exporting GGUF to the Hub - #10317

Merged
danielhanchen merged 18 commits into
unslothai:mainfrom
NilayYadav:fix-gguf-hub-export-double-convert
Sep 6, 2026
Merged

danielhanchen merged 18 commits into
unslothai:mainfrom
NilayYadav:fix-gguf-hub-export-double-convert

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Exporting to GGUF with Hugging Face Hub as the destination runs the whole merge, convert and quantize sequence twice. The first run writes the files to your save folder. The second run happens inside push_to_hub_gguf, which converts everything again into the system temp folder instead of uploading the files that already exist.

That doubles the wait, needs a second full size copy of the model in temp, and can push a run past the export timeout, which is one hour per quantization.

Now the Hub upload sends the files that were already built. Tested against a real Hub repo. Before: two conversion calls, and nothing from the local folder reached the Hub. After: one conversion call, and the repo gets the .gguf file, the Modelfile and a model card.

@NilayYadav

NilayYadav commented Sep 4, 2026 •

Copy link
Copy Markdown
Collaborator Author

GitHub Actions reproduction: the double conversion, and two regressions the first fix introduced

Three fork branches on fresh upstream main (49dac87ab89a037a83e29776ae9c80296daf4314), running a byte-identical workflow and probe — only studio/backend/core/export/export.py differs. The probe drives the real ExportBackend.export_gguf; the model conversion and the Hub calls are the only doubles, and the push_to_hub_gguf double mirrors unsloth/save.py::unsloth_push_to_hub_gguf — tempfile.mkdtemp(prefix="unsloth_gguf_"), a full re-convert, then an upload of the GGUF, the Modelfile and config.json from that directory. Each conversion writes a real 64 MiB artifact, so the byte and second counts are measured.

The export folder is pre-seeded with a notes.txt, a dataset.jsonl and a _tmp_model_earlier/ merge, because the save directory is user-picked: the export panel has a folder browser, and resolve_export_write_dir passes absolute paths through by design (#6082).

A — main B — PR as submitted C — PR at e6321ec93
run 33919715772 ❌ 33919718668 ❌ 33921387454 ✅
conversions 2 1 1
bytes converted 134,217,728 67,108,864 67,108,864
convert seconds 0.097 0.075 0.074
second conversion landed in /tmp/unsloth_gguf_kac0njbj_gguf — —
bytes written outside the chosen folder 67,108,864 0 0
Hub upload read from that temp directory the export folder the export folder
published Modelfile, config.json, model.Q4_K_M.gguf Modelfile, model.Q4_K_M.gguf, notes.txt, dataset.jsonl, _tmp_model_earlier/model/model-00001-of-00002.safetensors Modelfile, config.json, model.Q4_K_M.gguf

A is the reported defect: the model is converted twice, the second pass into the system temp directory, and the upload comes out of that temp copy rather than the folder the user asked for.

B removes the second conversion but upload_folder(output_path) published the whole folder, so a notes.txt, a dataset.jsonl and a leftover merged checkpoint were pushed to the repo — and config.json, which push_to_hub_gguf had uploaded from its merge directory, stopped arriving. Neither happens on main: run A published none of the seeded files and did publish config.json.

C is the current head. The bottom row is the point — C's published set is exactly A's, reached with one conversion instead of two. Getting there took four rounds of narrowing what counts as "this export's output":

  • the upload is an allow-list built from the files this run actually relocated, so unrelated files, a _tmp_model_* merge a failed export kept, and GGUFs from an earlier export of a different model all stay on disk;
  • names go through glob.escape, since the allow-list is fnmatch — llama-3[8b].Q4_K_M.gguf does not match its own unescaped pattern and would have been skipped silently, and a name containing * would have matched files the export never produced;
  • Modelfile is allow-listed only when this conversion actually produced one, so a stale Modelfile pointing at another model is not republished;
  • AppleDouble companions (._model.Q4_K_M.gguf) are filtered out, matching what final_ggufs already did;
  • config.json is read from the exporter-reported merge directory before that temp root is deleted, and uploaded from memory. Deliberately not written into the export folder: utils/models/checkpoints.py::_is_model_dir treats any directory holding a config.json as a checkpoint directory;
  • the card carries the exporter's is_vlm through as the vision-language-model tag, and both llama.cpp and llama-cpp, all of which the Hub filters on as exact strings.

Each has a unit test that fails on the preceding commit. Thanks to @codex, which caught the stale-GGUF, stale-Modelfile, AppleDouble, config.json and VLM-tag cases.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-06T15:47:44.065258Z 61e5c03 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: b046c3a587

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 9a625f0616

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

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: e6321ec93a

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: e6321ec93a

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

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Review convergence

Codex returned clean twice on the same head, e6321ec93a — 21:33:45Z and again at 21:36:47Z with no code change in between. The second was a deliberate re-sample rather than a new round: it had returned clean on 9a625f06 earlier and then found a real P2 on a tree one whitespace-only line join away, so a single green was not something I was willing to read as convergence.

Eight rounds, nine findings, all genuine, all fixed, none disputed:

# Finding Where it came from
1 the Hub upload published the whole user-chosen folder found here, reproduced on Actions
2 allow-list still shipped stale .ggufs already in the folder Codex
3 filenames matched as glob patterns, not literals found here
4 model card committed before the files it advertises Codex
5 stale Modelfile from an earlier export republished Codex
6 AppleDouble ._*.gguf companions published Codex
7 config.json stopped reaching the Hub Codex
8 vision-language-model tag dropped Codex
9 llama-cpp tag dropped Codex

Findings 7, 8 and 9 are Hub-metadata parity: each is a tag or file the Hub filters on as an exact string, so losing one silently removes the repository from that filter. All three were checked against unsloth/save.py before being accepted — add_tags at 5502-5513 really does emit llama-cpp while the card it writes says llama.cpp, so upstream repositories carry both spellings and now so do these.

Two of the nine — config.json and the VLM tag — I had noticed early and filed as cosmetic. That was the wrong call in both cases, and Codex's reachability argument is what corrected it.

Not carried over from unsloth_push_to_hub_gguf's README, deliberately: the Ollama section, the BOS-token note and the "trained 2x faster" footer. Those are prose rather than classification, and nothing filters on them.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: e6321ec93a

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

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Studio UI evidence: the export panel, before and after

Pinned head: e6321ec93a45c94194922da8e6ee361c7da75f06, against the PR's own merge base e8a88546ddef77ac6efc3d034ba4a142e7f61179.

Two Studios, each installed with install.sh --local from its own checkout into an isolated home and stamped with its SHA, identical dependency set on both sides (unsloth 2026.9.2, unsloth_zoo 2026.9.1 with a byte-identical mlx/utils.py, transformers 5.5.0, huggingface-hub 1.30.0). Same real flow driven through the export page on both: Qwen2.5-0.5B-Instruct as a plain directory typed into Local Model, method GGUF / Llama.cpp, quant Q4_K_M, destination Push to Hub as evidence-user/Qwen2.5-0.5B-Instruct-GGUF, Start Export, then the panel photographed once it reached Done.

The one stand-in: both Studios were launched with HF_ENDPOINT pointed at a local server that answers whoami-v2, repos/create, preupload, commit and validate-yaml, and logs what each commit carried. Everything else in the pictures is Studio's own — the model load, the merge, the llama.cpp convert and quantize, the streamed log, the elapsed timer and the banner.

Log scrolled to the Pushing GGUF model to Hub line. On the left, that line is followed by Merging LoRA weights…, Converting to GGUF format…, INFO:hf-to-gguf:Loading model: merged — the whole pipeline running again after the export had already finished. On the right it is the last line in the log.

PR 10317 export panel, scrolled to the push line, before/after

Tail of the log. On the left the second pass's llama_quantize output ends in GGUF export complete -> evidence-user/Qwen2.5-0.5B-Instruct-GGUF — a directory named after the repo id, not the folder the user chose. On the right the single pass ends in Relocated GGUF → Wrote export metadata → Pushing.

PR 10317 export panel tail, before/after

Read from the same Studio's /api/export/logs and the stand-in Hub's log while each panel was photographed:

BEFORE e8a88546d AFTER e6321ec93
Converting to GGUF format passes 2 1
Quantizing to q4_k_m lines 4 2
export log lines 1,818 913
GGUF export complete -> the export folder, then evidence-user/Qwen2.5-0.5B-Instruct-GGUF the export folder
panel elapsed 19 s 12 s
files the Hub received Qwen2.5-0.5B-Instruct.Q4_K_M.gguf Qwen2.5-0.5B-Instruct.Q4_K_M.gguf, README.md
banner Export finished and pushed to Hugging Face Hub. same

Two things to read alongside the table. A 0.5B model converts in about seven seconds on this machine, so the elapsed gap is small in absolute terms; the extra pass is a full merge, convert and quantize, and grows with the model. And on macOS the exporter is unsloth_zoo's MLX path, whose push_to_hub_gguf re-runs save_pretrained_gguf with the repo id as its save directory — that is why the second pass lands where it does here. The CUDA path (unsloth/save.py) re-converts the same way into a system temp directory, which is what the Actions comment above measured. On this platform main uploaded only the .gguf; the head uploads it with the model card.

@NilayYadav

NilayYadav commented Sep 4, 2026 •

Copy link
Copy Markdown
Collaborator Author

Real Hugging Face Hub round trip on the head

Every earlier push in this thread went to a stand-in Hub. This one went to huggingface.co, with a real token, from the head Studio (e6321ec93a45c94194922da8e6ee361c7da75f06, macOS / MLX exporter), through the backend's own export API exactly as the panel calls it: POST /api/export/load-checkpoint on a plain-directory Qwen2.5-0.5B-Instruct, then POST /api/export/export/gguf with quantization_method: "Q4_K_M", push_to_hub: true, private: true. The repo was then read back through the Hub API and compared with what the export left on disk.

value
repository yNilay/pr10317-evidence-Qwen2.5-0.5B-Instruct-GGUF, private, commit c8f01edba7e0c3d1607d2a80621f21390699f3ce
files the Hub holds Qwen2.5-0.5B-Instruct.Q4_K_M.gguf 397,807,552 B, README.md 495 B, .gitattributes (the Hub's own)
files the export left on disk Qwen2.5-0.5B-Instruct.Q4_K_M.gguf 397,807,552 B, export_metadata.json
export_metadata.json on the Hub no
tags the Hub computed gguf, llama.cpp, llama-cpp, unsloth (+ its own conversational, endpoints_compatible, region:us)
card lists Qwen2.5-0.5B-Instruct.Q4_K_M.gguf
conversion passes in the export log 1 (912 lines)
export API response {"success": true, "message": "GGUF model exported successfully (q4_k_m)"}, 95 s including the upload

The repository as the Hub renders it (captured during a sixteen-second public window, then set private again):

Files and versions: .gitattributes, Qwen2.5-0.5B-Instruct.Q4_K_M.gguf 398 MB via xet, README.md; commits "Upload folder using huggingface_hub" and "Unsloth Model Card"

The three commits are the PR's Hub leg in order: repo creation, upload_folder (the commit message is huggingface_hub's own), then ModelCard.push_to_hub. No export_metadata.json, no _tmp_model_*, nothing the user did not export.

Model card: tags GGUF, llama.cpp, llama-cpp, unsloth; Hub-parsed GGUF metadata qwen2 0.5B params Q4_K_M 398 MB

The right rail is the Hub reading the uploaded file's own header — architecture qwen2, 0.5B params, Q4_K_M — so what landed is a loadable GGUF, not merely the right number of bytes.

So on a real endpoint the allow-list publishes exactly this run's GGUF, the card lands with both llama.cpp spellings, the Studio-local metadata stays off the repo, and the GGUF the Hub holds is byte-identical to the one on disk. The repo is private under my account and can be made public or deleted on request.

Two things this surfaced that are not this PR's, both reproduced on main's code:

  • hub/dependencies.py caps the X-Unsloth-HF-Token header at 512 characters, so an OAuth token from hf auth login (825 characters here) gets HTTP 422 from every hub route that reads the header — token/validate, the settings sync, and the remote-code check inside the export page's handleExport, which then never starts the export and shows nothing. The request body's hf_token has no such cap, which is why this run drove the API directly rather than the panel (the panel path is photographed above, against the stand-in).
  • On macOS a multi-quant GGUF export fails before anything is written: unsloth_zoo/mlx/utils.py:17327 save_pretrained_gguf → TypeError: unhashable type: 'list'. The MLX exporter takes one quant; the UI allows several, and export.py hands it the list on a line this PR leaves identical to main.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 6, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 6, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 6, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 6, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 6, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 6, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 6, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 6, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 6, 2026
@unslothai unslothai deleted a comment from NilayYadav Sep 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 6, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 57f7f11030

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

Second sweep now that the review rounds have settled: 70 comment lines down to
37 across the files this PR touches, 124 to 37 counting the first pass. Cuts the
duplicates and the restatements; every load-bearing fact stays, one line each.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 6, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 61e5c03ee4

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

@danielhanchen
danielhanchen merged commit 7b1d8ed into unslothai:main Sep 6, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants