-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quantizer class to perform quantization #2824
base: main
Are you sure you want to change the base?
Conversation
This pull request introduces a quantizer class allowing quantization and dequantization with different schemes. The goal is to offer users more choices when dealing with various types of quantization. Initial support targets include affine quantization (per tensor and per channel) and binary-code-based quantization. This pull request presents the basic structure of these classes, and further implementation details will be added in future updates. **Self-evaluation:** 1. Build test: [X]Passed [ ]Failed [ ]Skipped 2. Run test: [X]Passed [ ]Failed [ ]Skipped Signed-off-by: Donghyeon Jeong <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice draft! but think you need to add this file for tizen spec file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except for CI.
If you are trying factory method pattern so that
Make the base class (quantizer) a pure virtual class and design a proper creator class. Then, you can let an application add arbitrary quantizers without changing nntrainer. |
First of all, thank you for the kind guidance! I really appreciate it :)
However, in later development, the parameters of the constructors will differ from one another as follows.
Also, scale could be fp16 and zero_point can be float for other quantizer. |
Having such a switch-case clauses for pre-defined subclasses is fine. You need to think the opposite way for such user-defined subclasses.
A derived class is built as an independent shared object (.so), and when it's loaded, You may use both "name" and "enum" for faster execution; however, you will need a proper Runtime efficiency of loading quantizers matters. So, I recommend to use enum as key (keep name as reference to fine the enum?) and keep the switch-case structure for predefined quantizers. In nnstreamer, we didn't need that kind of efficiency. |
One more thing to add: As long as the custom plugins (derived classes supplied by applications) are used only by the supplier (the application), your implementation does need to be as complex as my example. The example (tensor-filter-cppsubplugin) is to allow applications to access the derived classed from other entities (applications share derived classes). Using enum instead of string as the key will be much easier with such conditions. You don't need things like The most important requirement here is: enum ( If you want factory-method you've suggested,
let the derived classes have:
and let the application call Then, at your factory method:
If you feel "emptyinstance" and having create as non-static method too awkward (I feel awkward.. but this is the limitation of C++), you may consider https://coliru.stacked-crooked.com/a/afdb9c8f6cef344a |
Someone needs to check if similar changes are required for other classes in nntrainer.... but I believe most.. at least "classic".. "extensible" classes of nntrainer can get new subclasses from application without changes or rebuilding of nntrainer. |
This pull request introduces a quantizer class allowing quantization and dequantization with different schemes. The goal is to offer users more choices when dealing with various types of quantization. Initial support targets include affine quantization (per tensor and per channel) and binary-code-based quantization. This pull request presents the basic structure of these classes, and further implementation details will be added in future updates.
Self-evaluation: