Repository navigation
Fix duplicate gemma-2b-bnb-4bit key routing the base model to the instruct model - #6891
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
Code Review
This pull request fixes a duplicate key issue in unsloth/models/mapper.py where unsloth/gemma-2b-bnb-4bit was used for both the base and instruct models, and adds a regression test to verify the fix. The feedback suggests explicitly specifying the UTF-8 encoding when opening files in Python to ensure cross-platform compatibility.
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.
| namespace = {} | ||
| exec(compile(source, MAPPER_PATH, "exec"), namespace) |
There was a problem hiding this comment.
When opening files in Python, it is best practice to explicitly specify the encoding (e.g., encoding="utf-8") to ensure cross-platform compatibility. On some platforms (like Windows), the default system encoding might not be UTF-8, which can lead to UnicodeDecodeError if non-ASCII characters are ever introduced to the file.
| namespace = {} | |
| exec(compile(source, MAPPER_PATH, "exec"), namespace) | |
| with open(MAPPER_PATH, encoding="utf-8") as f: | |
| source = f.read() |
|
@codex review |
|
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". |
…bit repo to the instruct model The INT_TO_FLOAT_MAPPER had two entries keyed the identical "unsloth/gemma-2b-bnb-4bit"; Python keeps the last, so the base gemma-2b 4bit repo resolved to the instruct model, the base lost its reverse FLOAT_TO_INT mapping, and gemma-2b-it-bnb-4bit was unregistered. Rename the second key to "unsloth/gemma-2b-it-bnb-4bit" to mirror the gemma-7b base/it pair. Adds tests/test_gemma_2b_mapper_key.py, wired into the Bucket-A CPU CI step.
2a5a59b to
d7e2408
Compare
|
Rebased onto current |
|
Verified your fix by diffing the built mappers imported from Thanks @vineethsaivs. Merging. |
Summary
__INT_TO_FLOAT_MAPPERinunsloth/models/mapper.pyhas two entries keyed with the exact same string"unsloth/gemma-2b-bnb-4bit":The line-137 entry was clearly meant to register the 4bit instruction-tuned model, but its key is missing the
-itsuffix (compare the adjacentgemma-7bpair, which correctly usesunsloth/gemma-7b-bnb-4bitandunsloth/gemma-7b-it-bnb-4bit). Because a Python dict literal keeps only the last value for a duplicate key, the base-model mapping is silently discarded.Impact
After the module builds
INT_TO_FLOAT_MAPPER/FLOAT_TO_INT_MAPPER/MAP_TO_UNSLOTH_16bit:INT_TO_FLOAT_MAPPER["unsloth/gemma-2b-bnb-4bit"]resolves to"unsloth/gemma-2b-it", so loading the base 4bit repo withload_in_4bit=Falsereturns the instruct model instead of the base model.FLOAT_TO_INT_MAPPERhas no entry for"unsloth/gemma-2b"or"google/gemma-2b", so the base model does not get routed to its 4x-faster 4bit repo."google/gemma-2b-it"reverse-maps to the base 4bit repo."unsloth/gemma-2b-it-bnb-4bit"is never registered at all.Fix
Give the instruct entry its correct key
"unsloth/gemma-2b-it-bnb-4bit", mirroring thegemma-7bbase/it pattern. This is a one-line change; the value tuple is unchanged. The Hugging Face repounsloth/gemma-2b-it-bnb-4bitexists (the mapping now points at a real model), and the new key does not collide with any existing entry.Out of scope: there is also a duplicate
"unsloth/llama-2-7b-chat-bnb-4bit"key, but both of its entries have identical values, so it is harmless redundancy and left untouched.Test
mapper.pyhas no imports, so the newtests/test_gemma_2b_mapper_key.pyexecs the module directly and asserts the base and instruct 4bit repos map to distinct models in both directions. It fails on the current code (the base repo resolves to the instruct model) and passes with this fix. It runs on CPU with no GPU, so it is wired into the Bucket-A CPU step inconsolidated-tests-ci.yml.