Fix GGUF to Work Better with modules_to_not_convert / keep_in_fp32_modules#13697
Open
Fix GGUF to Work Better with modules_to_not_convert / keep_in_fp32_modules#13697
modules_to_not_convert / keep_in_fp32_modules#13697Conversation
6 tasks
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
This PR contains several fixes so the GGUF loading and inference work better with
module_to_not_convertand_keep_in_fp32_modules.Changelist
src/diffusers/quantizers/gguf/utils.py_replace_with_gguf_linear: adds a check to see if any of the current module'snamed_childrenare inmodules_to_not_convert, and if so, skip it. This allows us skip containers, rather than just leaf-levelnn.Linearsubmodules as in the current code. For example,TimestepEmbeddingmodules are commonly added to_keep_in_fp32_modules(e.g.time_embedderinWanTransformer3DModel'sWanTimeTextImageEmbeddingcondition embedder), but since they themselves contain leafnn.Linearsubmodules such aslinear_1, the current code will only check against leaf modules such aslinear_1, and conclude incorrectly that they should be converted._fused_mul_mat_gguf: in theUNQUANTIZED_TYPEScase, also cast the dequantizedweightto the activationx'sdtypebefore performing the matrix multiplication, which should prevent dtype errors for BF16 weights.src/diffusers/quantizers/gguf/gguf_quantizer.pyGGUFQuantizer.create_quantized_param: handlesmodules_to_not_convertby dequantizing them, so that they end up in their original unquantized form. This is intended to handle the case where a module inself.modules_to_not_convert(or one of its children) is in the GGUF file. Since it is in the file, it will be converted to aGGUFParameter, but we don't want it to be quantized, so we convert it back here.Inspired by GGUF debugging in #13551, in particular #13551 (comment).
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@DN6
@sayakpaul