Add HQQ model serialization support#32056
Closed
mobicham wants to merge 2 commits intohuggingface:mainfrom
mobiusml:main
Closed
Add HQQ model serialization support#32056mobicham wants to merge 2 commits intohuggingface:mainfrom mobiusml:main
mobicham wants to merge 2 commits intohuggingface:mainfrom
mobiusml:main
Conversation
Closed
Contributor
|
Gentle ping @SunMarc |
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?
The goal of this PR is to add support for saving/loading transformers models quantized via HQQ.
Currently, it's not possible to directly save/load HQQ-quantized models via
model.save_pretrained. The workaround is to use thehqqlib which offers serialization but without safetensors support.The first thing to do was making the
HQQLinear.state_dictcompatible with safetensors: dropbox/hqq@74bbe01Since safetensors only support
torch.Tensordtype and no nested dictionaries are allowed, I had to implement an encoding/decoding logic for the parameters, which works fine for the moment.The second step was integrating the new
HQQLinearstate_dict loading with the transformers lib, which I found a bit tricky because of the following issues:dispatch_modelbreaks withHQQLinearmodule, I am not sure what's the issue here. Before it reaches that function, the layer is already loaded from the state_dict. If I skip the dispatching function, I a get a model with meta device for all the layers exceptHQQLinearSince this is a draft pull-request, I am commenting out some stuff while debugging, will fix that later (you'll see there's a
TODO @mobichamcomment so I can get back to it).Will need to drop support for quantized scale/zero, so I will need to update the HqqConfig and the documentation, as well as add tests later.
Any help is highly appreciated , thank you!
Who can review?
@SunMarc
Example