Repository navigation
Fix BAD_MAPPINGS not redirecting the -unsloth-bnb-4bit dynamic quants - #6949
Conversation
get_model_name applied BAD_MAPPINGS only to the resolver's output, but the -unsloth-bnb-4bit dynamic-quant names (e.g. unsloth/Qwen3-32B-unsloth-bnb-4bit) are keys of the mappers rather than values, so _resolve_with_mappers returns None for them. The BAD_MAPPINGS remap is guarded by new_model_name is not None, so it was skipped and get_model_name returned the oversized name unchanged, loading the large dynamic quant (high VRAM / OOM) instead of the intended smaller model that BAD_MAPPINGS points to. When the resolver returns None, also remap the input name through BAD_MAPPINGS. The already-working -bnb-4bit entries (which the resolver does resolve) and all other names are unchanged. Adds a CPU regression test that asserts every BAD_MAPPINGS entry redirects, ast-extracting the resolver so it needs no GPU.
There was a problem hiding this comment.
Code Review
This pull request fixes a bug in get_model_name where certain bad model names (such as -unsloth-bnb-4bit dynamic quants) were not redirected by BAD_MAPPINGS because the resolver returned None for them. The fix directly remaps the input model name when the resolved name is None. A regression test has also been added to verify this behavior. The review feedback recommends specifying encoding="utf-8" when opening files in the test to prevent potential UnicodeDecodeError on platforms like Windows.
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.
|
|
||
| def _load_get_model_name(): | ||
| mapper_ns = {} | ||
| with open(os.path.join(_MODELS, "mapper.py")) as f: |
There was a problem hiding this comment.
Specify encoding="utf-8" when opening files to prevent potential UnicodeDecodeError on platforms where the default system encoding is not UTF-8 (such as Windows).
| with open(os.path.join(_MODELS, "mapper.py")) as f: | |
| with open(os.path.join(_MODELS, "mapper.py"), encoding="utf-8") as f: |
| with open(os.path.join(_MODELS, "mapper.py")) as f: | ||
| exec(compile(f.read(), "mapper.py", "exec"), mapper_ns) | ||
|
|
||
| with open(os.path.join(_MODELS, "loader_utils.py")) as f: |
There was a problem hiding this comment.
Specify encoding="utf-8" when opening files to prevent potential UnicodeDecodeError on platforms where the default system encoding is not UTF-8 (such as Windows).
| with open(os.path.join(_MODELS, "loader_utils.py")) as f: | |
| with open(os.path.join(_MODELS, "loader_utils.py"), encoding="utf-8") as f: |
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
Verified your fix by running I pushed a small follow-up: |
Summary
BAD_MAPPINGSredirects a few oversized dynamic quants to smaller models, e.g.:But the
-unsloth-bnb-4bitentries never fire.get_model_nameappliesBAD_MAPPINGSonly to the resolver's output:The
-unsloth-bnb-4bitnames are keys ofINT_TO_FLOAT_MAPPER, not values ofFLOAT_TO_INT_MAPPER, so withload_in_4bit=True_resolve_with_mappersreturnsNonefor them. The remap is guarded bynew_model_name is not None, so it is skipped, andget_model_namefalls through tonew_model_name = model_name, returning the oversized name unchanged. SoFastLanguageModel.from_pretrained("unsloth/Qwen3-32B-unsloth-bnb-4bit")loads the large dynamic quant (much higher VRAM / OOM) instead ofunsloth/Qwen3-32B-bnb-4bit, which is exactly whatBAD_MAPPINGSis meant to prevent. The-bnb-4bitentries work because the resolver does resolve those, so the existing block catches them.Fix
When the resolver returns
None, also remap the input name throughBAD_MAPPINGS:This activates the
-unsloth-bnb-4bitentries. Names the resolver does resolve (including the working-bnb-4bitentries) and all other names are unchanged, since this branch only runs when the resolver returnedNone.Test
tests/test_bad_mappings_redirect.pyasserts thatget_model_name(name, load_in_4bit=True) == BAD_MAPPINGS[name.lower()]for everyBAD_MAPPINGSentry. It fails on the current code (the three-unsloth-bnb-4bitnames come back unchanged) and passes with this fix. The mapper table and resolver have no heavy imports, so the test execs the import-freemapper.pyand ast-extracts the resolver functions (no GPU, noimport unsloth); it is wired into the Bucket-A CPU CI step.