Repository navigation
Fix GGUF export writing outside the chosen save directory on Windows (#7897) - #7937
Merged
Merged
Conversation
…7897) unsloth_save_pretrained_gguf derived the GGUF filename stem with base_model_name.split("/")[-1]. For a LoRA whose base model is a local Windows directory, config._name_or_path has no forward slash, so the whole path survived as the stem. Every output name was then built with os.path.join(gguf_directory, stem + ".Q5_K_M.gguf"), and ntpath.join discards its first argument when the second carries a drive: ntpath.join(r"C:\exp\_gguf", r"D:\M\X.Q5_K_M.gguf") == r"D:\M\X.Q5_K_M.gguf" so the finished GGUF landed next to the base model rather than in the export directory. Studio then globbed an empty directory, logged "Final files in <save_dir>: (none)", and still returned success. _model_basename strips both separators on every host and never returns an empty stem. os.path.basename is not enough: it returns the whole "D:\..." string on POSIX, so a fix built on it would pass CI while Windows stayed broken. _unsloth_save_lora_gguf already had this logic; it now shares the helper. Studio also consumes the gguf_files manifest save_pretrained_gguf already returns, instead of guessing from cwd, new subdirs and the checkpoint sibling, and falls back to those heuristics when the manifest is absent (older unsloth). A local export that produced no GGUF is now a failure rather than a silent success over an empty directory. Separately, the training bar sat at 100% labelled "training" for the whole post-training save, which emits no step updates and so looked identical to a hang. A non-terminal "finalizing" phase names it; completion still comes only from progress.is_completed.
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Closed
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.
Fixes #7897.
The bug
unsloth_save_pretrained_ggufderived the GGUF filename stem withbase_model_name.split("/")[-1]. For a LoRA whose base model is a local Windows directory,config._name_or_pathhas no forward slash, so the whole path survived as the stem. Every output name was then built withos.path.join(gguf_directory, stem + ".Q5_K_M.gguf"), andntpath.joindiscards its first argument when the second carries a drive.Confirmed on a real
windows-latestrunner, not simulated:So the finished GGUF landed next to the base model instead of the export directory. Studio's three relocation strategies look in cwd, in new subdirectories of the save dir, and for a
<checkpoint>_ggufdirectory, and a loose sibling file matches none of them. It then globbed an empty directory, loggedFinal files in <save_dir>: (none), and still returned success.That is exactly what the reporter's log shows, on all four of their exports. It affects anyone on Windows calling
save_pretrained_ggufwith a local base-model directory, not just Studio.The fix
unsloth/save.py:_model_basenamestrips both separators on every host and never returns an empty stem.os.path.basenameis not sufficient, because it returns the wholeD:\...string on POSIX, so a fix built on it would pass CI while Windows stayed broken._unsloth_save_lora_ggufalready carried this logic under the comment "Windows-safe basename"; the sibling function was simply missed, and both now share the helper.The helper is module level on purpose.
unsloth_save_pretrained_ggufdoesarguments = dict(locals())and splats it intounsloth_generic_save(**arguments), so a new local bound before that line becomes an unexpected keyword argument and breaks every GGUF export on every OS. There is an AST test guarding that.studio/backend/core/export/export.py: consumes thegguf_filesmanifestsave_pretrained_ggufalready returns (and already printed, via theexample usage ... --modelline), instead of guessing. Falls back to the existing heuristics when the manifest is absent, which is what an older bundled unsloth produces. Also:rglobbefore the unconditionalrmtree, since a sharded GGUF one level deeper was being destroyed;iterdirinstead ofglob.globfor the final listing, since glob hides dot-leading names; the Modelfile is rescued from the temp dir; and a local export that produced no GGUF now fails instead of reporting success over an empty directory.Training phase: the bar sat at 100% labelled "training" for the whole post-training save, which emits no step updates and so looked identical to a hang. A non-terminal
finalizingphase names it. Completion still comes only fromprogress.is_completed; reaching the last step means the optimizer loop ended, not that the save succeeded.Compatibility
No
unsloth_zoochange is required, so the two packages do not need to ship together.Noneor a str, falls back to today's behaviour.split("/")[-1]for every input that already worked, and only differs on inputs that were already broken._model_basenameis pure string and stat work; a test asserts it imports nothing and references no GPU library.Testing
Bug proven red before the fix, green after:
tests/test_gguf_model_basename.py(61)studio/backend/tests/test_export_gguf_discovery.py(20)Full validation:
windows-latest, basename + native NTFSwindows-latest, export discoverymacos-14, real APFS (case-insensitive confirmed)ubuntu-latest, py3.10 and py3.13node:test[Windows, Linux, WSL, macOS] x [NVIDIA, ROCm, CPU]The py3.10 leg is deliberate: it is the canary for
glob(..., include_hidden=), which is 3.11+ and would silently break CI.The 12-cell matrix is an invariance check, and the tests say so. This is path arithmetic with no GPU involvement, so the assertion is that the stem and its destination are identical in every cell. The ROCm cell uses gfx1100, the card in the report, and a harness self-guard confirms the spoof really set
torch.version.hipso the cells are not vacuous. macOS x NVIDIA and macOS x ROCm are labelled as non-products rather than counted as coverage.Still open on #7897
The reporter's attached log is
segment_index=1of a multi-segment set and captures a healthy session: every phase returned 200 and there is noPOST /api/train/stopin it. Thefinalizingphase makes a slow save legible instead of looking frozen, but reproducing the hang itself needs the segment covering an actual stall, the desktop renderer log, and confirmation of which tab showed 100%.