Repository navigation
fix: map None quant method to q8_0 before lowercasing in GGUF export - #6889
Conversation
In unsloth_save_pretrained_gguf and save_to_gguf_generic, the quant-method normalization loop ran `quant_method = quant_method.lower()` as its first statement, before the `elif quant_method is None: quant_method = "q8_0"` branch. Because `.lower()` executed first, a None element in the quantization_method list (e.g. quantization_method=[None] or ["q4_k_m", None]) raised `AttributeError: 'NoneType' object has no attribute 'lower'`, and the intended None -> q8_0 mapping was unreachable dead code. Handle None before lowercasing, matching the sibling loop in save_to_gguf, so a None element resolves to q8_0. Behavior is unchanged for string inputs. Add tests/saving/test_quant_method_none_normalization.py, a CPU-only test that extracts each loop via ast and checks that a None element maps to q8_0 instead of raising, alongside strings.
There was a problem hiding this comment.
Code Review
This pull request fixes an AttributeError in unsloth/save.py that occurred when a None element was present in the quantization_method list. The fix ensures that None values are checked and mapped to 'q8_0' before calling .lower(). Additionally, a new CPU-only regression test has been added to verify this behavior using AST parsing and execution. There are no review comments to address.
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.
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! 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". |
danielhanchen
left a comment
There was a problem hiding this comment.
Confirmed a None element in the list raised AttributeError before the fix and that handling None ahead of lowercasing resolves it, with the added regression test passing. Thanks.
Because
.lower()runs first, aNoneelement inside the list (for examplequantization_method=[None]or["q4_k_m", None]) raisesAttributeError: 'NoneType' object has no attribute 'lower', and theelif quant_method is None:branch is dead code that never runs. A barequantization_method=Noneis fine, it is guarded by the surroundingif quantization_method is not None:; the problem is specifically aNoneelement within the list.
The sibling loop in
save_to_ggufalready handles this correctly: it checksNoneviaelifand does not call.lower()up front. This change brings thetwo loops in line with it.
Fix
Handle
Nonebefore lowercasing and drop the now-redundantelif:A
Noneelement now resolves toq8_0. Behavior is unchanged for every stringinput.
Test
Adds
tests/saving/test_quant_method_none_normalization.py. Importingunsloth.savepulls inunsloth_zoo/Torch, so, following the existingtests/saving/test_is_gpt_oss_detection.pypattern, the test extracts eachloop's source with
astand execs it against sample inputs. It asserts that[None]maps to["q8_0"],["Q4_K_M", None]maps to["q4_k_m", "q8_0"],and that ordinary string inputs are unchanged. The test fails on the old
ordering (
AttributeError) and passes with this fix (6 passed).ruff checkon the touched files passes.