Skip to content

Add support for half type for the http restful api #1753

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

venuswu
Copy link

@venuswu venuswu commented Oct 20, 2020

Half type is widely used in the deeplearning inference, but the tf-serving doesn't support half type in the restful api,
I submit a pr to solve this problem, please check.

@google-cla
Copy link

google-cla bot commented Oct 20, 2020

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no label Oct 20, 2020
@venuswu
Copy link
Author

venuswu commented Oct 20, 2020

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.

What to do if you already signed the CLA

Individual signers
Corporate signers

Googlers: Go here for more info.

@googlebot I signed it!

@google-cla google-cla bot added cla: yes and removed cla: no labels Oct 20, 2020
@netfs netfs self-requested a review December 2, 2020 06:20
case DT_HALF:
int src = tensor.half_val(*offset);
float dst;
dst = toFloat16( &src, &dst);
Copy link
Collaborator

Choose a reason for hiding this comment

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

dont roll your own version for float16 conversion (its hard to get that correct). instead use standard @FP16 library that is used in TF. specifically use fp16_ieee_from_fp32_value() API (from fp16.h), and write the output as decimal number.

example code:
https://github.com/tensorflow/tensorflow/blob/2ba6502de549c20c7498f133792cf3223eabc274/tensorflow/lite/delegates/gpu/common/convert.cc#L303

you can refer to the fp16 library via @FP16 bazel target in the BUILD file.

also your change is incomplete. you need to handle input conversion (json -> tensor) for DT_HALF. please update AddValueToTensor() method.

and finally add unit tests for your code.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you , I'll try.

@teamwong111
Copy link

I think you can adjust the type of input through tf.cast(), so that you don't need to add support for Half type.

@Hanyu-Jin
Copy link

Hi, I'm facing the same problem and I'd like to know when this pr will be approved.

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

Successfully merging this pull request may close these issues.

Why the restful http server does not support type DT_HALF ?
4 participants