mlc-llm icon indicating copy to clipboard operation
mlc-llm copied to clipboard

[Bug] how to accurately measure the real memory usage on Android ?

Open MrRace opened this issue 1 year ago • 5 comments

After deploying Qwen-4B, Qwen-1.8B, and Qwen-0.5B to an Android phone using mlc-llm, I used the following commands to check the system memory usage:

adb shell ps |  findstr "mlc"
adb shell dmabuf_dump PID
adb shell dumpsys meminfo PID

However, the results were all similar, showing only a few hundred MB, so I suspect there might be an issue with the method I'm using. Could you please advise on how to accurately measure the real memory usage when mlc-llm is deployed on a phone, both during model loading and runtime? For example, are there any specific commands you would recommend?

MrRace avatar Aug 05 '24 09:08 MrRace

Android Studio may have some tools for memory profiling https://developer.android.com/studio/profile/memory-profiler.

MasterJH5574 avatar Aug 05 '24 15:08 MasterJH5574

a few hundred MB must be the CPU memory usage. However, the model is stored in the GPU memory, so OS-level memory command is not enough

Hzfengsy avatar Aug 06 '24 01:08 Hzfengsy

a few hundred MB must be the CPU memory usage. However, the model is stored in the GPU memory, so OS-level memory command is not enough

@Hzfengsy Is there a more detailed command?

MrRace avatar Aug 06 '24 06:08 MrRace

Android Studio may have some tools for memory profiling https://developer.android.com/studio/profile/memory-profiler.

@MasterJH5574 You can try, but this method also cannot accurately display memory usage, only a few hundred megabytes.

MrRace avatar Aug 06 '24 06:08 MrRace

I used Android Studio tools for memory profiling, and got the result. It seems to be correct. The left and right peaks represent two models of different sizes c393468577ea85cd54aaa77057f39dc7

ponytaill avatar Aug 06 '24 08:08 ponytaill

Yes I could also see accurate memory usage of gigabytes when I used it last time.

MasterJH5574 avatar Aug 16 '24 18:08 MasterJH5574

Almost perfect sollution:

watch -n0.1 'adb shell "cat /proc/meminfo | head"'
  • read how memory works on android (e.g. https://developer.android.com/topic/performance/memory-management)

pfk-beta avatar Aug 26 '24 11:08 pfk-beta