pytorch / executorch

On-device AI across mobile, embedded and edge for PyTorch
https://pytorch.org/executorch/
Other
2.22k stars 370 forks source link

Llava 1.5 model not loading in LlamaDemo #6369

Open Astuary opened 1 month ago

Astuary commented 1 month ago

🐛 Describe the bug

I have tried to load llava.pte and tokenizer.bin generated from python -m executorch.examples.models.llava.export_llava --pte-name llava.pte --with-artifacts in LlamaDemo, following these instructions.

For the Android Studio emulator, I even tried with 16GB RAM, but the model never gets loaded. It reaches around 15.5GB (or reached around 7.5GB if it's an 8GB RAM in an actual device, or around 11.5GB if the RAM of the emulator is 12GB), then the app just crashes.

Is there anyway to download prebuilt llava.pte and tokenizer.bin to debug?

Edit: Running python -m executorch.examples.models.llava.test.test_pte models/xnnpack_with_sdpa/llava.pte gives

[INFO 2024-10-20 00:29:00,426 sdpa_with_kv_cache.py:29] Loading custom ops library: /work/pi_huiguan_umass_edu/kunjal/atom_venv_310/lib/python3.10/site-packages/executorch/extension/llm/custom_ops/libcustom_ops_aot_lib.so
I 00:00:00.238826 executorch:program.cpp:133] InternalConsistency verification requested but not available
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
/work/pi_huiguan_umass_edu/kunjal/atom_venv_310/lib/python3.10/site-packages/transformers/models/llava/configuration_llava.py:100: FutureWarning: The `vocab_size` argument is deprecated and will be removed in v4.42, since it can be inferred from the `text_config`. Passing this argument has no effect
  warnings.warn(
Loading checkpoint shards: 100%|████████████| 3/3 [00:13<00:00,  4.54s/it]
tensor([[ 2.1032,  3.3883, -0.6067,  ..., -0.6447, -0.5723, -0.1141]])
[WARNING 2024-10-20 00:31:27,901 test_pte.py:58] Image encoder started
[WARNING 2024-10-20 00:32:13,415 test_pte.py:60] Image encoder finished
[WARNING 2024-10-20 00:32:13,415 test_pte.py:61] Image token prefill started
[WARNING 2024-10-20 00:34:15,814 test_pte.py:69] Image token prefill finished
tensor([[ 0.3437, -0.5741,  0.4265,  ..., -1.5019, -1.3079, -0.9044]])
[WARNING 2024-10-20 00:34:15,815 test_pte.py:75] Text token prefill started
[WARNING 2024-10-20 00:35:58,648 test_pte.py:83] Text token prefill finished
tensor([[-2.5387, -5.9057,  1.4276,  ..., -0.8143, -0.5545, -0.1734]])
0 幸
1 幸
2 幸
3 幸
幸幸幸幸幸

Versions

PyTorch version: 2.6.0.dev20241007+cpu Is debug build: False CUDA used to build PyTorch: Could not collect ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.6 LTS (x86_64) GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0 Clang version: 10.0.0-4ubuntu1 CMake version: version 3.30.5 Libc version: glibc-2.31

Python version: 3.10.15 (main, Oct 3 2024, 07:27:34) [GCC 11.2.0] (64-bit runtime) Python platform: Linux-5.4.0-190-generic-x86_64-with-glibc2.31 Is CUDA available: False CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: N/A GPU models and configuration: GPU 0: NVIDIA L40S Nvidia driver version: 535.183.01 cuDNN version: Could not collect HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian Address sizes: 46 bits physical, 57 bits virtual CPU(s): 64 On-line CPU(s) list: 0-31 Off-line CPU(s) list: 32-63 Thread(s) per core: 1 Core(s) per socket: 16 Socket(s): 2 NUMA node(s): 2 Vendor ID: GenuineIntel CPU family: 6 Model: 207 Model name: INTEL(R) XEON(R) GOLD 6526Y Stepping: 2 CPU MHz: 3500.000 BogoMIPS: 5600.00 Virtualization: VT-x L1d cache: 1.5 MiB L1i cache: 1 MiB L2 cache: 64 MiB L3 cache: 75 MiB NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30 NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 Vulnerability Gather data sampling: Not affected Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Retbleed: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cat_l2 cdp_l3 invpcid_single cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local avx512_bf16 wbnoinvd dtherm ida arat pln pts avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq rdpid cldemote movdiri movdir64b md_clear pconfig flush_l1d arch_capabilities

Versions of relevant libraries: [pip3] executorch==0.5.0a0+df5b2ab [pip3] numpy==1.21.3 [pip3] torch==2.6.0.dev20241007+cpu [pip3] torchao==0.5.0 [pip3] torchaudio==2.5.0.dev20241007+cpu [pip3] torchsr==1.0.4 [pip3] torchvision==0.20.0.dev20241007+cpu [conda] executorch 0.5.0a0+df5b2ab pypi_0 pypi [conda] numpy 1.21.3 pypi_0 pypi [conda] torch 2.6.0.dev20241007+cpu pypi_0 pypi [conda] torchao 0.5.0 pypi_0 pypi [conda] torchaudio 2.5.0.dev20241007+cpu pypi_0 pypi [conda] torchsr 1.0.4 pypi_0 pypi [conda] torchvision 0.20.0.dev20241007+cpu pypi_0 pypi

kirklandsign commented 1 month ago

cc @cmodi-meta @Riandy Not sure if 16GB is good enough

Riandy commented 1 month ago

16gb should be good enough. We did try it on oneplus 12. @larryliu0820 , is the above export instruction/command still the latest one?

Astuary commented 1 month ago

Hello,

Not sure if this info is relevant, but this is the relevant log in Android Studio when I try to load Llava 1.5 in an emulator:

ETLogging               com.example.executorchllamademo      D  Loading model /data/local/tmp/llama/llava_with_sdpa.pte with tokenizer /data/local/tmp/llama/llava_tokenizer_with_sdpa.bin
2024-10-23 16:09:14.409  9810-9878  nativeloader            com.example.executorchllamademo      D  Load /data/app/~~LDxDEJuOR_QXZ4stDa2gXA==/com.example.executorchllamademo-q96Nq46rVWj1czVQbr99sg==/lib/x86_64/libexecutorch.so using ns clns-7 from class loader (caller=/data/app/~~LDxDEJuOR_QXZ4stDa2gXA==/com.example.executorchllamademo-q96Nq46rVWj1czVQbr99sg==/base.apk!classes4.dex): ok
2024-10-23 16:09:14.411  9810-9878  ExecuTorch              com.example.executorchllamademo      I  Reading file /sys/devices/soc0/image_version
2024-10-23 16:09:14.412  9810-9878  ExecuTorch              com.example.executorchllamademo      I  Failed to open midr file /sys/devices/soc0/image_version
2024-10-23 16:09:14.414  9810-9878  ExecuTorch              com.example.executorchllamademo      I  Reading file /sys/devices/system/cpu/cpu0/regs/identification/midr_el1
2024-10-23 16:09:14.416  9810-9878  ExecuTorch              com.example.executorchllamademo      I  Failed to open midr file /sys/devices/system/cpu/cpu0/regs/identification/midr_el1
2024-10-23 16:09:14.416  9810-9878  ExecuTorch              com.example.executorchllamademo      I  CPU info and manual query on # of cpus dont match.
2024-10-23 16:09:14.416  9810-9878  ExecuTorch              com.example.executorchllamademo      I  Resetting threadpool to -1 threads
2024-10-23 16:09:14.464  9810-9819  utorchllamademo         com.example.executorchllamademo      I  Waiting for a blocking GC NativeAlloc
2024-10-23 16:09:14.466  9810-9810  utorchllamademo         com.example.executorchllamademo      I  Waiting for a blocking GC NativeAlloc
2024-10-23 16:09:14.502  9810-9815  utorchllamademo         com.example.executorchllamademo      W  Cleared Reference was only reachable from finalizer (only reported once)
2024-10-23 16:09:14.543  9810-9819  utorchllamademo         com.example.executorchllamademo      I  WaitForGcToComplete blocked NativeAlloc on NativeAlloc for 79.826ms
2024-10-23 16:09:14.544  9810-9810  utorchllamademo         com.example.executorchllamademo      I  WaitForGcToComplete blocked NativeAlloc on NativeAlloc for 78.159ms
kirklandsign commented 1 month ago

Waiting for a blocking GC NativeAlloc

Seems like RAM is not enough, and it tries to GC. I'm not sure what's the exact requirement.

Astuary commented 1 month ago

Right, can you confirm if following the steps stated here, particularly this command python -m executorch.examples.models.llava.export_llava --pte-name llava.pte --with-artifacts, should result in a memory consumption of around 5GiB (as stated in that README)?

I saw a couple other Llava related issues here where people are running the LlamaDemo with Llava model iPhone 15 Pro Max (8GB RAM) and Samsung Galaxy S24 Ultra (12 GB RAM) successfully, so I am not sure if it's some emulator related issue. I am unable to load it on an actual Pixel 8a as well though.

WuhanMonkey commented 1 month ago

cc. @cmodi-meta Can you help here?