Skip to content
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

[FC] Add dequantize action to FC layer #2936

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

EunjuYang
Copy link
Contributor

@EunjuYang EunjuYang commented Feb 11, 2025

  • This commit is temporary one to realize a fc layer with QINT weight.
  • This should be fixed in the way to move the dequantize operations under the tensor op.
  • dequantization overhead :
Without SWAP   With SWAP (LA=2)
FP32-FP32 QINT8-FP32 FP32-FP32 QINT8-FP32
0.162787 0.166505 0.0487955 0.127012


///@todo this quantizaer should be moved to tensor, not layer!
switch (context.getWeightDataType()) {
case ml::train::TensorDim::DataType::QINT4:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about adding 'not supported yet' message till implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It intends to make a quantizerfor all QINT4, QINT8, QINT16 cases. AFIK, QINT4, 8, 16 all work with a quantizer. Please let me know if I missed something!

Copy link
Contributor

@baek2sm baek2sm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@EunjuYang
Copy link
Contributor Author

EunjuYang commented Feb 12, 2025

FYI)

I tested the case where QINT8-FP32 is used (weight dtype-tensor dtype).
Please refer to the result below:

$  ./nntrainer_simplefc 100 false 0 FP32 FP32
$  ./nntrainer_simplefc 100 false 0 QINT8 FP32
$  ./nntrainer_simplefc 100 true 2 FP32 FP32
$  ./nntrainer_simplefc 100 true 2 QINT8 FP32
Without SWAP   With SWAP (LA=2)
FP32-FP32 QINT8-FP32 FP32-FP32 QINT8-FP32
0.162787 0.166505 0.0487955 0.127012

bin file size is 400 MB vs. 100 MB.
Result was not tested (no suitable initialization method for scale is implemented yet)

- This commit is temporary one to realize a fc layer with QINT weight.
- This should be fixed in the way to move the dequantize operations
  under the tensor op.

Signed-off-by: Eunju Yang <[email protected]>
Comment on lines +206 to +208
///@todo This dequantization action should be moved to tensor.dot()
if (quantizer != nullptr) {
Tensor weight_ = quantizer->dequantize(weight, input_.getDataType());
Copy link
Member

@skykongkong8 skykongkong8 Feb 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, I wonder how should it be expected to work at Tensor::dot().
Maybe something like:

Tensor::dot() {
...
int8_t data = getData();
int8_t input_data = input;
Tensor qinput = quantizer->dequantize(...);
GEMM(data, qinput.getData(), output);
...
}

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants