gallery icon indicating copy to clipboard operation
gallery copied to clipboard

App is crashing when switching to gpu acceleration (during configuration)

Open Heril555 opened this issue 6 months ago • 14 comments

Bug Description: The app is crashing when gpu acceleration is selected in configuration, everything is working perfectly when cpu acceleration is selected. Model used : Gemma 3n (4.4 gb)

To Reproduce: Steps to reproduce the behavior:

https://github.com/user-attachments/assets/44da3edb-c873-4e11-9dde-3ff702503b1a

Expected behavior:
After selecting gpu acceleration, configuration should be done successfully instead of the app crashing.

Smartphone:

  • Device: Realme GT neo 2 5G
  • OS: Android 15

Heril555 avatar Jun 06 '25 14:06 Heril555

The video attached doesn't show any crash or bad behaviour.

dr3adl0rd avatar Jun 07 '25 20:06 dr3adl0rd

The video attached doesn't show any crash or bad behaviour.

The screen recording was also crashing along with this app(so the crash was impossible to record) so I just recorded what I did before crash.

Heril555 avatar Jun 07 '25 21:06 Heril555

This also happens on a Samsung Galaxy S24 Ultra

AliaArianna avatar Jun 13 '25 01:06 AliaArianna

Same issue with same model on oneplus 12 . To note this does not occur with gpu as accelerator on the smaller gemma model

hrishikeshp7 avatar Jun 14 '25 04:06 hrishikeshp7

Same issue with same model on oneplus 12 . To note this does not occur with gpu as accelerator on the smaller gemma model

I have the same issue on a oneplus 12R.

tecknight avatar Jun 17 '25 09:06 tecknight

Crashes when I switch from CPU to GPU

tecknight avatar Jun 17 '25 09:06 tecknight

Hi everyone,

Thank you all for the feedback. We see the reports of the app crashing with GPU acceleration on various devices, including the Realme GT neo 2 and Samsung S24 Ultra, particularly with larger models like Gemma 3n.

For context, I have also been able to reproduce a crash on a Samsung Galaxy S24 Ultra under certain conditions. In my testing, the crash seemed more likely to occur when multiple models were downloaded and potentially occupying memory.

As a potential workaround, could those experiencing this crash please try the following?

  1. Clear the app's cache.
  2. Ensure only one model (specifically the one you want to test with GPU, e.g., in "Ask Image") is downloaded and also enough RAM. Please note that it might take a while loading when you switch CPU to GPU.

Please let us know if this makes a difference in stability when using GPU acceleration. Your feedback on this will be very helpful.

Thank you!

dpknag avatar Jun 17 '25 23:06 dpknag

Yes it works . I deleted all other models and ran the e4b version which kept crashing and for now it works . Although loading model on gpu is way slower than on cpu .

Another fix that I tried and which was working for me was in the model allowlist file I changed the peak memory to the maximum amount that remains available on my phone for each model and this has also resolved the issue .

On Wed, 18 Jun 2025, 04:57 Deepak Nagaraj, @.***> wrote:

dpknag left a comment (google-ai-edge/gallery#106) https://github.com/google-ai-edge/gallery/issues/106#issuecomment-2982101232

Hi everyone,

Thank you all for the feedback. We see the reports of the app crashing with GPU acceleration on various devices, including the Realme GT neo 2 and Samsung S24 Ultra, particularly with larger models like Gemma 3n.

For context, I have also been able to reproduce a crash on a Samsung Galaxy S24 Ultra under certain conditions. In my testing, the crash seemed more likely to occur when multiple models were downloaded and potentially occupying memory.

As a potential workaround, could those experiencing this crash please try the following?

  1. Clear the app's cache.
  2. Ensure only one model (specifically the one you want to test with GPU, e.g., in "Ask Image") is downloaded and also enough RAM. Please note that it might take a while loading when you switch CPU to GPU.

Please let us know if this makes a difference in stability when using GPU acceleration. Your feedback on this will be very helpful.

Thank you!

— Reply to this email directly, view it on GitHub https://github.com/google-ai-edge/gallery/issues/106#issuecomment-2982101232, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQL2ACBNT5ACKXQ524SHAHL3ECP67AVCNFSM6AAAAAB6YIV2DWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSOBSGEYDCMRTGI . You are receiving this because you commented.Message ID: @.***>

hrishikeshp7 avatar Jun 18 '25 03:06 hrishikeshp7

Hi everyone,

Thank you all for the feedback. We see the reports of the app crashing with GPU acceleration on various devices, including the Realme GT neo 2 and Samsung S24 Ultra, particularly with larger models like Gemma 3n.

For context, I have also been able to reproduce a crash on a Samsung Galaxy S24 Ultra under certain conditions. In my testing, the crash seemed more likely to occur when multiple models were downloaded and potentially occupying memory.

As a potential workaround, could those experiencing this crash please try the following?

  1. Clear the app's cache.
  2. Ensure only one model (specifically the one you want to test with GPU, e.g., in "Ask Image") is downloaded and also enough RAM. Please note that it might take a while loading when you switch CPU to GPU.

Please let us know if this makes a difference in stability when using GPU acceleration. Your feedback on this will be very helpful.

Thank you!

I only downloaded one model from the very start i.e I never downloaded any other model and also I don't think it's memory issue either because it worked perfectly fine with CPU.

Heril555 avatar Jun 18 '25 05:06 Heril555

Hi everyone, Thank you all for the feedback. We see the reports of the app crashing with GPU acceleration on various devices, including the Realme GT neo 2 and Samsung S24 Ultra, particularly with larger models like Gemma 3n. For context, I have also been able to reproduce a crash on a Samsung Galaxy S24 Ultra under certain conditions. In my testing, the crash seemed more likely to occur when multiple models were downloaded and potentially occupying memory. As a potential workaround, could those experiencing this crash please try the following?

  1. Clear the app's cache.
  2. Ensure only one model (specifically the one you want to test with GPU, e.g., in "Ask Image") is downloaded and also enough RAM. Please note that it might take a while loading when you switch CPU to GPU.

Please let us know if this makes a difference in stability when using GPU acceleration. Your feedback on this will be very helpful. Thank you!

I only downloaded one model from the very start i.e I never downloaded any other model and also I don't think it's memory issue either because it worked perfectly fine with CPU.

True though , any model on CPU runs just fine without any added configuration .

hrishikeshp7 avatar Jun 18 '25 14:06 hrishikeshp7

Hi @hrishikeshp7 and @Heril555,

Apologies for the delayed response, and thank you both for this detailed follow-up. This is exactly the kind of feedback that helps us solve complex bugs.

I've carefully reviewed your comments, and here are the key takeaways for our team:

  1. Workaround: We see that deleting other models to free up memory can work as a temporary fix, as @hrishikeshp7 confirmed.
  2. Memory Estimation: The most important insight is that manually increasing the "peak memory" value in the model_allowlist.json file also fixes the crash. This suggests the app is underestimating the memory needed on certain GPUs.
  3. GPU-Specific Problem: You are right that this is not a general memory issue, because it works perfectly fine on the CPU. This confirms the problem is specific to how the app handles memory when using the GPU.

This is all very valuable information. We have logged these specific findings and passed them to our team. Thank you again for your excellent help.

dpknag avatar Jun 30 '25 18:06 dpknag

Hi everyone,

In my case , it happens if i run this repo but APK works fine. Isnt APK and repo same?

Repo Steps

  1. I cloned latest repo.

  2. I built and run it on android studio 2025.1.1 with my samsung phone A34 8GB RAM. OS is Android 14. gpu is Mali-G68 MC4. Pc is windows.

  3. It worked fine on CPU but failed in GPU. It returns nothing, just stucks. It shows stats idk how if i cancel response .

  4. I always wait untill it activates GPU btw. I dont take action without seeing success log in android studio saying model inited successfully.

APK steps

I downloaded APK from https://github.com/google-ai-edge/gallery/releases/latest/download/ai-edge-gallery.apk

I installed app. It worked completely fine on both CPU and GPU.

nurullah44 avatar Aug 03 '25 05:08 nurullah44

With the latest version (https://github.com/google-ai-edge/gallery/releases/tag/1.0.4) the app does not crash when I try GPU mode on my Galaxy S25, but the AI model runs into text repetition. See screenshot.

Image

Danmoreng avatar Aug 19 '25 08:08 Danmoreng

There have been issues with GPU for a long time , cannot seem to find a permanant fix for this. Cant even understand why the problem is occuring .

hrishikeshp7 avatar Aug 22 '25 17:08 hrishikeshp7