Fix TypeError when loading model in MoE router without bitsandbytes#690
Merged
Merged
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
Collaborator
|
Thanks for the PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I was trying to run
mergekit-moeto merge some Qwen models on my CPU. Even though I wasn't using any 4-bit or 8-bit quantization flags, the merge kept crashing with:TypeError: Qwen2ForCausalLM.__init__() got an unexpected keyword argument 'load_in_4bit'It turns out that
mergekitwas passingload_in_4bit=Falseandload_in_8bit=Falseby default to the Hugging Facefrom_pretrainedmethod. In newer versions oftransformers, passing these options when you don't have a CUDA GPU orbitsandbytesconfigured causes a crash because the library doesn't know what to do with them.Instead of always passing
load_in_4bitandload_in_8bitasFalse, this change constructs the arguments dynamically. They are only sent tofrom_pretrainedif they are set toTrue.This keeps CPU merges (and any merge not using quantization) running smoothly without crashing!
Note
Low Risk
Narrow change to optional kwargs for model loading; behavior unchanged when 4/8-bit flags are explicitly enabled.
Overview
Fixes CPU / non-quantized MoE routing by only passing
load_in_4bitandload_in_8bittoAutoModelForCausalLM.from_pretrainedwhen those flags areTrue, instead of always forwarding them asFalse.In
get_gate_params(hidden / hidden_avg / hidden_last modes), quantization options are collected in akwargsdict and spread intofrom_pretrained, so models like Qwen2 no longer receive unsupported keyword arguments on CPU or without bitsandbytes.Reviewed by Cursor Bugbot for commit 07bae36. Bugbot is set up for automated code reviews on this repo. Configure here.