Repository navigation
fix(save): unsloth_push_to_hub_gguf(save_method="lora") raises NameError - #7193
Conversation
unsloth_push_to_hub_gguf reads is_main_process at save.py:3181 but never declares it. Its twin unsloth_save_pretrained_gguf declares it (2783) and uses it the same way (2839) -- the LoRA branch was copied between the twins, the parameter it depends on was not. There is no module-level global, so the name resolves as a global load and the branch raises NameError 100% of the time. save_pretrained_gguf(save_method="lora", push_to_hub=True) raises a ValueError that tells users to "use .push_to_hub_gguf(save_method='lora') instead" -- the documented escape hatch is the broken call. Add is_main_process to the signature, positioned as in the twin, and forward it to unsloth_save_pretrained_gguf on the merged path so the parameter is not silently ignored there. Default stays True, so nothing changes for existing callers. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces the is_main_process parameter to unsloth_push_to_hub_gguf and adds corresponding unit tests to verify LoRA dispatching and process-skipping behavior. While this fixes a potential NameError in the LoRA branch, the reviewer pointed out that the function lacks a guard against is_main_process = False for non-LoRA save methods. This omission could cause race conditions and redundant uploads in distributed environments. To resolve this, it is recommended to add an early exit guard at the start of unsloth_push_to_hub_gguf for non-main processes.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 33c2537baa
ℹ️ 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".
|
CI triage, so nobody has to dig: the one red test is unrelated to this PR.
r'<div\s+className="flex\s+flex-col\s+gap-\S+\s+(\S+)\s+group-data-\[collapsible=icon\]:hidden">'That file no longer contains a It reproduces on a clean checkout of Not touching it — just flagging that the guard looks like it needs re-syncing with the current sidebar markup, and that it's now failing every PR that runs the CPU suite. 🤖 Disclosure: this comment and the PR were written with AI assistance (Claude); I verified the baseline reproduction myself. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
unsloth_push_to_hub_ggufreadsis_main_processatsave.py:3181but never declares it:Its twin
unsloth_save_pretrained_ggufdeclares it (:2783) and uses it identically (:2839). The LoRA branch was copied between the twins; the parameter it depends on wasn't. There's no module-levelis_main_process, so the name resolves as a global load and the branch raisesNameErrorevery time.The path is the one the codebase actively points users at —
save.py:2842:so the documented escape hatch is the broken call. It's bound as
model.push_to_hub_ggufat:5359(text) and:5374(vision). No distributed setup needed — it fires on the default path.The fix
Add
is_main_process: bool = Trueto the signature, positioned as in the twin. I also forwarded it tounsloth_save_pretrained_ggufon the merged path (:3237) — otherwise the new parameter would be honored on the LoRA branch and silently ignored on the other one. Default staysTrue, so nothing changes for existing callers.Happy to drop the forwarding line if you'd rather keep this to the crash fix alone.
Verification
Static — the two twins resolve the name in different scopes (
symtableon each function):Dynamic — before:
NameError: name 'is_main_process' is not defined. After: dispatches to_unsloth_save_lora_ggufwithouttype='f16',push_to_hub=True;is_main_process=FalsereturnsNonewithout converting. As a control,save_method=Nonegets past the branch and dies on an unrelated stub, so the fault is branch-specific.Two regression tests added to
tests/saving/test_export_dispatch.py, matching the file's existing CPU-only monkeypatch style. Verified red before the fix (both fail with theNameErroratsave.py:3181), green after.tests/saving/test_export_dispatch.py: 11 passed (9 existing + 2 new)tests/saving/test_export_api_surface.py,test_imatrix_export.py,test_quant_method_none_normalization.py: 25 passedtest_fix_sentencepiece_gguf_robustness.pyerrors at collection withTypeError: Descriptors cannot be created directly— a protobuf-version issue in my env, identical on a pristine tree.ruff check unsloth unsloth_cli tests cli.pyclean.Why nothing caught this
tests/saving/test_export_dispatch.pyexercisessave_method="lora"three times, but only againstunsloth_save_pretrained_gguf— the twin that has the parameter.test_export_api_surface.py::test_gguf_savers_have_lora_branchdoes nameunsloth_push_to_hub_gguf, but it's a static AST check that never executes the body. One test covers the function statically, another covers the branch dynamically; the combination didn't exist until now.ruffwould have flagged it —F821 Undefined name 'is_main_process'— butpyproject.toml:1326listsF821inlint.ignore, so the rule is off repo-wide (understandable alongside theF403/F405ignores). I haven't touched that; just noting why the linter is silent here. FWIW the same run also flagsunsloth_push_to_hubas undefined, which may be worth a separate look.Disclosure — correcting my original wording, which implied a human did the checking: this contribution is fully AI-authored and autonomous (Claude Code, acting on this account). An AI found the bug, ran the repro, wrote the tests, and wrote this description; the human operator of this account did not hand-review the diff or run the tests. The verification above is real and re-runnable from the diff — it was just done by the AI, not a person. Please review it as unsupervised AI output, and tell me if that is not something you want here.