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

[QNN] Multiplication operator #3927

Closed
wants to merge 1 commit into from
Closed

Conversation

tristan-arm
Copy link
Contributor

@tristan-arm tristan-arm commented Sep 10, 2019

Implementation of the qnn multiplication operator following the same pattern as the addition operator.

Copy link
Contributor

@anijain2305 anijain2305 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! Please feel free to ping me for any QNN related PRs :)

I have a concern about the lowering.

* \param arg_types The types of input and output.
* \return The sequence of Relay ops for mul op.
*/
Expr QnnMulCanonicalize(const Attrs& attrs, const Array<Expr>& new_args,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that there is a mistake in the lowering. Can you please provide description of how the lowering instructions are decided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that there is a mistake in the lowering. Can you please provide description of how the lowering instructions are decided?

Same as the addition operator - only difference is that the requantized tensors are multiplied to provide the output. Let me know which part of the instructions you see an issue with and I'll take a closer look - Thanks

@tqchen
Copy link
Member

tqchen commented Oct 10, 2019

@tristan-arm @anijain2305 please followup on this thread :)

@anijain2305
Copy link
Contributor

@tristan-arm Sorry for the huge delay. This is what the lowering should look like. Let me know what do you think about this.

Quantized mul operation

    scale_c * (Q_c - zp_c) = (scale_a * (Q_a - zp_a))   *   (scale_b * (Q_b - zp_b))

    scale_c * (Q_c - zp_c) = (scale_a * scale_b)   *   [  (Q_a - zp_a) *  (Q_b - zp_b) ]


Going from right to left on the RHS
1) Shifted_input_A = Subtract Q_a - zp_a (Precision int32)
2) Shifted_input_B = Subtract Q_b - zp_b (Precision int32)
3) Int_tensors_muliplication = Shifted_input_A * Shifted_input_B


Our equation looks like this

    scale_c * (Q_c - zp_c) = (scale_a * scale_b)   *    Int_tensors_muliplication

RHS can be thought of quantized tensor with (scale, zero_point) = (scale_a * scale_b, 0)
So, we can requantize.

4) Requantize the  Int_tensors_muliplication with (input_scale, input_zero_point) = (scale_a * scale_b, 0)
    And (output_scale, output_zero_point) = (scale_c, zp_c)

@tqchen
Copy link
Member

tqchen commented Oct 24, 2019

ping @tristan-arm please follow up :)

@tqchen tqchen added the status: need update need update based on feedbacks label Oct 24, 2019
@u99127
Copy link
Contributor

u99127 commented Oct 24, 2019

@tqchen - tristan is on holidays , the other PR by @ekalda in #4141 should supersede this work and I think this PR should be abandoned.

@tqchen tqchen closed this Oct 24, 2019
@tqchen
Copy link
Member

tqchen commented Oct 24, 2019

thanks @u99127 @tristan-arm @anijain2305

@tqchen tqchen added status: suprceded PR is superceded by another one and removed status: need review status: need update need update based on feedbacks labels Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: suprceded PR is superceded by another one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants