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

TFLiteConverter: Support QuantizeAndDequantizeV4 #48410

Merged

Conversation

lgeiger
Copy link
Contributor

@lgeiger lgeiger commented Apr 8, 2021

This PR adds support for tf.quantization.quantize_and_dequantize_v2 to the TFLite converter.

Under the hood it is implemented as a canonicalizer that converts QuantizeAndDequantizeV2 (used by tf.quantization.quantize_and_dequantize) to QuantizeAndDequantizeV4 (used by tf.quantization.quantize_and_dequantize_v2). This can be done since both ops share the same kernel implementation in the forward pass. Secondly the pattern in the TFLite converter is changed to handle QuantizeAndDequantizeV4 including a unittest that verifies the behaviour.

This PR is a follow up on #47225 /cc @smit-hinsu

@abattery
Copy link
Contributor

abattery commented Apr 8, 2021

@liufengdb @teijeong @jpienaar could you review this PR?

@abattery abattery added ModelOptimizationToolkit TF Model Optimization Toolkit TFLiteConverter For issues related to TFLite converter type:feature Feature requests labels Apr 8, 2021
Copy link
Member

@jpienaar jpienaar left a comment

Choose a reason for hiding this comment

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

LGTM code wise, are there any differences between 2 and 4 representationally?

@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Apr 8, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Apr 8, 2021
@lgeiger
Copy link
Contributor Author

lgeiger commented Apr 8, 2021

Thanks for the fast review!

are there any differences between 2 and 4 representationally?

Not as far as I can tell. They share the same implementation in the forward pass:

REGISTER_KERNEL_BUILDER(Name("QuantizeAndDequantizeV4") \
.Device(DEVICE_CPU) \
.TypeConstraint<T>("T"), \
QuantizeAndDequantizeV2Op<CPUDevice, T>); \

so the only difference is in the gradient op which is not relevant in this case.

@copybara-service copybara-service bot merged commit d8fdfcb into tensorflow:master Apr 8, 2021
@lgeiger lgeiger deleted the support-quantize-dequant-v4 branch April 8, 2021 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes ModelOptimizationToolkit TF Model Optimization Toolkit ready to pull PR ready for merge process size:S CL Change Size: Small TFLiteConverter For issues related to TFLite converter type:feature Feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants