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

Interpreter API (Java) - GpuDelegateV2 support #65114

Open
cfasana opened this issue Apr 5, 2024 · 3 comments
Open

Interpreter API (Java) - GpuDelegateV2 support #65114

cfasana opened this issue Apr 5, 2024 · 3 comments
Assignees
Labels
Android comp:lite TF Lite related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower TF 2.15 For issues related to 2.15.x TFLiteGpuDelegate TFLite Gpu delegate issue type:feature Feature requests

Comments

@cfasana
Copy link

cfasana commented Apr 5, 2024

Hi,
I am trying to run a TFLite model on the GPU of an Android device.
According to this documentation, it is possible to use both the Interpreter API and the Native c++ API to achieve this.

At the moment, I am using the following dependencies:

implementation 'org.tensorflow:tensorflow-lite:2.15.0'
implementation 'org.tensorflow:tensorflow-lite-select-tf-ops:2.15.0'
implementation 'org.tensorflow:tensorflow-lite-support:0.4.4'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.15.0'
implementation 'org.tensorflow:tensorflow-lite-gpu-api:2.15.0'
implementation 'org.tensorflow:tensorflow-lite-gpu-delegate-plugin:0.4.4'

I was able to successfully run my model using the GPUDelegate provided by the Java Interpreter API. However, this delegate does not allow to specify inference priority options (TFLITE_GPU_INFERENCE_PRIORITY_MIN_LATENCY, TFLITE_GPU_INFERENCE_PRIORITY_MIN_MEMORY_USAGE, TFLITE_GPU_INFERENCE_PRIORITY_MAX_PRECISION).

These options can be specified if the Native C++ API is used given the presence of GpuDelegateV2. However, at the moment I don't see this option in the Interpreter API since there is no class named GpuDelegateV2.

Is there a way to make use of this new delegate without the need of using the Native C++ API?

@LakshmiKalaKadali LakshmiKalaKadali added comp:lite TF Lite related issues TFLiteGpuDelegate TFLite Gpu delegate issue TF 2.15 For issues related to 2.15.x type:feature Feature requests labels Apr 8, 2024
@LakshmiKalaKadali
Copy link
Contributor

Hi @cfasana,

The Java Interpreter API currently doesn't have GpuDelegateV2 directly. However if you would like to achieve the faster inference speed you can use GpuDelegate class by setting the isPrecisionLossAllowed flag to true in the following way as a workaround. But for memory usage and max precision, feature requests will be raised. Thanks for letting us know.

GpuDelegateOptions options = new GpuDelegateOptions();
options.isPrecisionLossAllowed = true;  
GpuDelegate gpuDelegate = new GpuDelegate(options);
InterpreterOptions interpreterOptions = new InterpreterOptions();
interpreterOptions.addDelegate(gpuDelegate);
Interpreter interpreter = new Interpreter(modelBuffer, interpreterOptions);

or
Also try with tflite_flutter library which will provide access to GpuDelegateV2 through DART API.

Hi @pkgoogle,
As @cfasana mentioned, GpuDelegateV2 need to be included in Java Interpreter API with the support of (TFLITE_GPU_INFERENCE_PRIORITY_MIN_LATENCY, TFLITE_GPU_INFERENCE_PRIORITY_MIN_MEMORY_USAGE, TFLITE_GPU_INFERENCE_PRIORITY_MAX_PRECISION). Raised a feature request.

Thank You

@cfasana
Copy link
Author

cfasana commented Apr 12, 2024

Hi @LakshmiKalaKadali,
thanks for the feedback.
I will proceed as you suggested while awaiting the Java Interpreter API update.

@pkgoogle
Copy link

Hi @sirakiin, can you please take a look a this feature request? Thanks.

@pkgoogle pkgoogle added Android stat:awaiting tensorflower Status - Awaiting response from tensorflower labels Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android comp:lite TF Lite related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower TF 2.15 For issues related to 2.15.x TFLiteGpuDelegate TFLite Gpu delegate issue type:feature Feature requests
Projects
None yet
Development

No branches or pull requests

5 participants