Repository navigation
Notebook GGUF export: keep the converter to the load's trust_remote_code decision - #17397
Conversation
save_pretrained_gguf / push_to_hub_gguf now give the convert_hf_to_gguf.py child an uncreatable HF_MODULES_CACHE unless the model was loaded with trust_remote_code=True (or its model / tokenizer class came from auto_map code), matching Studio's export guard. Checkpoints without auto_map never read that cache, so standard exports are unchanged. FastLlamaModel now stamps _unsloth_trust_remote_code like FastBaseModel, and the SentenceTransformer GGUF export forwards its stamp to the inner model.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
|
@codex security review |
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…rgs (#17404) ## Summary #17397 added a `remote_code_approved` local to `unsloth_save_pretrained_gguf` (read before the processor is unwrapped, so the converter follows the load's `trust_remote_code` decision). That function snapshots its locals with `arguments = dict(locals())` and forwards them to `unsloth_generic_save(**arguments)`, deleting every local that is not a save kwarg. The new local was never deleted, so every merged GGUF export on main now fails before the merge: ``` RuntimeError: Failed to save/merge model: TypeError: unsloth_generic_save() got an unexpected keyword argument 'remote_code_approved' ``` This adds the one missing `del arguments["remote_code_approved"]`, next to the other local-only names. The value is still read later by `_gguf_converter_remote_code(remote_code_approved)`, so #17397's behaviour is unchanged. ## Why CI did not stop it The existing guard `tests/test_gguf_model_basename.py::test_helper_is_module_level_and_adds_no_locals_to_the_gguf_entrypoint` catches exactly this and fails on main. #17397's own CI runs were cancelled rather than failed, so the guard never reported on it. Every PR based on main since then fails: - `Repo tests (CPU, rest)`: the guard above - `Repo tests (CPU, fsdp2)`: `test_gguf_runs_on_rank0_only_from_the_same_merge`, `test_push_to_hub_gguf_uploads_from_rank0_only`, `test_a_rank0_failure_raises_on_every_rank` in `tests/test_fsdp2_exports_gloo.py`, which run a real export end to end ## Testing - `tests/test_gguf_model_basename.py`: 1 failed on main, all 61 pass with the fix - `tests/test_fsdp2_exports_gloo.py` GGUF cases plus the guard: 64 passed with the fix
Summary
Studio's GGUF export already keeps the GGUF converter to the load's
trust_remote_codedecision (#14437), so a checkpoint loaded withouttrust_remote_code=Truecannot have itsauto_mapcode run during conversion. The notebook paths,model.save_pretrained_ggufandpush_to_hub_gguf, did not have the same guard: the converter subprocess could import and run a repo's remote code even though the user never opted in.Changes
unsloth/save.py:_gguf_remote_code_approved(model, tokenizer)treats any of these as consent:_unsloth_trust_remote_code);transformers_modules;transformers_modules._gguf_converter_remote_code(approved)mirrors Studio's_converter_remote_code. When the load did not opt in, it pointsHF_MODULES_CACHEat an unusable path for the length of the conversion, then restores the previous value. The converter child copies the environment, so it cannot importauto_mapmodules.save_to_ggufcall inunsloth_save_pretrained_gguf(whichpush_to_hub_ggufuses) andsave_to_gguf_generic.unsloth/models/llama.py:FastLlamaModel.from_pretrainedrecords_unsloth_trust_remote_code, asFastModelalready does, so a trusted load keeps converting as before.unsloth/models/sentence_transformer.py: the GGUF export passes a trusted stamp on to the inner model it converts.Impact
auto_map(Llama, Qwen, Gemma, Mistral and the rest) never touch the module cache, so they convert exactly as before. Loads withtrust_remote_code=Trueare untouched.trust_remote_codewhose saved folder carries remote code the converter would need now fails to convert instead of running that code, which matches Studio.Tests
New
tests/saving/test_gguf_notebook_remote_code_guard.py: 3 of 5 fail on main, and all 5 pass on this branch.unsloth_save_pretrained_ggufwith the converter stubbed.auto_mapcode runs when unguarded, and that it does not run under the guard.169 related save and export tests pass on this branch.