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.
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
[QNN] Implement 'qnn.softmax' #14536
[QNN] Implement 'qnn.softmax' #14536
Changes from 1 commit
35b5548
0f50244
f0d8560
8bad5b5
7475c71
ee6ccb1
4f571bb
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Is it necessary to cast input_zero_point to int32? It is assumed that input_zero_point is of type int32.
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.
This is apparently a redundant cast. I should remove it.
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.
This is in
ShiftExp
underalgorithm 1
First off, if S > 1 then we already have issues as
x_0
(I_0
in paper) maybe 0...For attention I would expect output activation range to potentially be very large (see LLM int8 paper) so having a high scale factor is not unreasonable for some schemes.
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.
Maybe I am not understanding something but seems like an obvious flaw...
I think you can get around this by not rounding I_0 in
algorithm1
but keeping it a float and rounding when needed. However this would introduce runtime FLOPS.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.
Another option is when decomposing
2^(S * I_p)
into integer and decimal components, you instead decompose:2^[(S * 2^-n * I_p) * 2^n]
. At compile time we can choose ann
to makeS * 2^-n << 1
to get around this problem. You can then apply the decomposition routine to the internal terms in parentheses and the outer2^n
now merely becomes another shift.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.
I believe S here is defined as:
Which can be be artbirary depending on the range m.
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.
We can fallback to the fp32-based impl when S > 1.
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.
Yeah I think that is another reasonable thing to do.
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.
Looks like this test does not allow to check accuracy in full.
I have printed out output and found that ~70% of output values is equal to 0.0 in this test. This is because output after
qnn.quantize
operation is equal to "-128". It is not very interesting/representative case for "int8" data type.Can you slightly modify this test in the following way:
qnn.dequantize
. Let's check output ofqnn.dequantize
+softmax
+qnn.quantize
onlyP.S.
I have checked output after
qnn.quantize
and see that some of value have diff by 7. I think it is too much and the accuracy is unsatisfactory... any thoughts?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.
I'm not sure why we need to modify QNN parameters (of
qnn.quantize
).I think that it's enough to change the value range specified in
x_np = np.random.randint(-128, 127, ...)
to satisfy theqnn.quantize
output to be in the range of [-100, +100].(Sorry if my understanding is wrong)
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.
In case all computation performed in integer-only arithmetic, how big diff is allowed for
softmax
operation generally? I'm not sure about this.I'm also not sure if any other algorithms outperform the current implementation.
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.
Yes, sure, it's up to you. My main concern here is to avoid the case when all (or almost all) output values are equal to "-128" (it is not representative case for "int8" data type.)
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.
Things we probably want to test: