tensorflow / tensorflow/model-optimization
Allow quantization of tied weights
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.6k
- Forks
- 349
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 1
Description
System information
- TensorFlow version (you are using): 2.6.0 (TFMOT 0.7.2)
- Are you willing to contribute it (Yes/No): Potentially, with some advice on how to implement it
Motivation
Numerous common networks use tied weights of some kind (i.e. the same weights used more than one place in the model), for example autoencoders or language models with shared embedding/deembedding weights. Currently, these models are not supported for quantization because quantize_apply uses keras.models.clone_model internally, which "will not preserve the uniqueness of shared objects within the model" (as per the docstring).
Describe the feature
The feature is to support quantization of models with tied weights. The same underlying variable would be used in multiple locations (as per the original unquantized model). Ideally, different layers using the same variable would have separate control over quantization (i.e. some layers could have the shared weights be quantized, while others have them unquantized).
Describe how the feature helps achieve the use case
I don't have a clear idea about how this feature should be implemented, which is the motivation for this issue. TensorFlow does have some support for serialization with shared objects (e.g. saving models in the "tf" format, which uses SharedObjectSavingScope internally), but I'm not sure if anything is compatible with clone_model, or if quantize_apply would have to be completely redone in a way that avoids clone_model.
Describe how existing APIs don't satisfy your use case (optional if obvious)
I've tried to quantize a model with shared weights, and run into various problems (depending on how exactly I do the sharing). All of these problems are expected, because clone_model does not support shared weights and will re-instantiate the model with separate variables for each location where the shared variable occurs.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing quantize_apply and its use of keras.models.clone_model, then review TensorFlow's SharedObjectSavingScope and tf-format serialization support. Determine how tied variables could remain shared while allowing separate quantization control, and define tests showing that quantized models preserve weight sharing without breaking existing models.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, tensorflow
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100