You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LiteRT GPU program cache grows ~0.5 GB per engine create and never speeds up init #552
blocked-runtimeRequires upstream or native runtime support before Dart package work can complete.bugSomething isn't workingpriority:P2Planned next: useful unblocked work or validation after P1 items
Found while re-running #521 on macOS arm64 (M4 Max, macOS 26.6.2), llamadart 6cea70af2, LiteRT-LM 0.17.0-6, Qwen3.5-0.8B INT8, GPU backend.
Observed
*_mldrift_program_cache.bin in the LiteRT cache directory grows ~0.5 GB per GPU engine create: 2.5 GB after the cold run, 5.0 GB, then 6.9 GB across the following runs. Total cache directory reached 7.6 GB for one 0.8B model.
The cache gives no benefit: shader init stays ~32 s per create, cold or warm.
From the 3rd create onward, and on every warm create, the runtime logs DATA_LOSS: Deserialization failed (webgpu/inference_context.cc:187), 10 lines per create. Non-fatal.
Reading (unverified): the serialized program cache fails to deserialize, so every create recompiles and appends a new serialization instead of replacing it.
Impact: unbounded disk growth in the app cache directory for any app that reloads a LiteRT GPU model; severe on mobile.
Not checked: other platforms/GPUs, portable bundle (this was JIT dart run), whether the growth is in the runtime or in how llamadart passes the cache path. If it reproduces with the native C API alone it belongs in leehack/litert-lm-native or upstream.
Acceptance: cache size is bounded across repeated GPU engine creates, and either a warm create is measurably faster or the program cache is not written.
Reproduced on macOS arm64, LiteRT-LM 0.17.0-6, Qwen3.5-0.8B INT8, GPU, llamadart 82cbb101: one process, fresh cache dir, one engine at a time, 8-token generation and full dispose between creates.
Create
*_mldrift_program_cache.bin
Init
DATA_LOSS
1 (cold)
539,470,408
51.8 s
no
2
1,078,897,224
50.6 s
no
3
1,608,917,872
50.8 s
10 lines
4 (file deleted first)
539,470,408
47.9 s
no
Growth happens inside engine_create only; the weight cache stays at 751,917,896 bytes. (Init times are inflated: another GPU run shared the machine.)
Create 2 silently misses the cache for the 10 prefill graphs; create 3 logs Deserialization failed: DATA_LOSS (delegate_kernel.cc:808) for them. Deleting the file costs no init time, so the cache gives no benefit for this model.
llamadart only passes a fixed directory ($TMPDIR/llamadart_litert_lm on macOS/Android, litert_lm_service.dart_defaultCacheDir; null elsewhere, so the runtime caches next to the model) through litert_lm_engine_settings_set_cache_dir. It never names, opens or deletes cache files, and only one engine is alive at a time. Runtime-side.
The C API has no program-cache switch (SetDisableProgramCache / cache_compiled_shaders_only exist in C++ only); the :nocache sentinel also disables the GPU weight cache.
Looks model-specific: in a long-lived cache dir the Qwen3.5 program cache is 15 GB while gemma-4-E2B is 44 MB and Qwen3-0.6B 7.8 MB (only Qwen3.5 was run here).
Not checked: other platforms/GPUs, two processes on one directory, a portable bundle.
Options for llamadart, none implemented: (1) document the cache directory and make it configurable; (2) opt-in prune of *_mldrift_program_cache.bin above a size cap before engine create, logged so the bug stays visible; (3) a C setter for the program-cache switch in leehack/litert-lm-native; (4) an upstream report referencing LiteRT-LM#2503.
Mitigation from #565 verified on real hardware (Apple M4 Max, Metal, main8cdfb2ad2, public LlamaEngine API, Qwen3.5-0.8B INT8, throwaway liteRtLmCacheDir, six creates in one process):
Create
liteRtLmMaxProgramCacheBytes
Program cache before → after
Deleted
1
null
(dir missing) → 539,470,408
no
2
null
539,470,408 → 1,078,897,224
no
3
600,000,000
1,078,897,224 → 539,470,408
yes, one warning
4
600,000,000
539,470,408 → 1,069,491,056
no (under cap)
5
0
1,069,491,056 → 539,470,408
yes, one warning
6
0, native log level none
539,470,408 → 539,470,408 (new mtime)
yes, silently
The weight cache (751,917,896 bytes) kept its size and mtime throughout; the missing nested directory was created at the lazy engine create; output was identical and coherent in every step. DATA_LOSS appeared only on create 4 (appending to a previously capped file), not on create 2.
Not exercised on hardware: *.xnnpack_cache preservation (no such file on the GPU path), the prune-failure path, links, other platforms.
Re-checked on LiteRT-LM v0.18.0 published bytes for the 0.12.0 validation (#966): not fixed for Qwen3.5-0.8B_int8.litertlm.
macOS arm64 (M4 Max, Metal through WebGPU), main29c52578, portable validation bundle, fresh cache directory, six engine creates across two processes (qwen35-litert-gpu run twice):
Create
Program cache (bytes)
Create time
DATA_LOSS lines
1 (cold)
539,205,104
48.9 s
0
2
1,069,010,176
51.9 s
10
3
1,598,803,200
54.1 s
10
4 (new process)
2,128,596,224
52.3 s
10
5
2,658,389,248
48.4 s
10
6
3,188,182,272
50.1 s
10
Every create appends 529.8 MB; the weight cache stays at 751,917,896 bytes.
Warm creates are no faster. Two of twelve graphs initialise from the cache; ten log Deserialization failed: DATA_LOSS (ml_drift/webgpu/inference_context.cc:187), now from the second create on.
Acceptance is not met. The liteRtLmMaxProgramCacheBytes cap remains the mitigation; it was not re-exercised here, but the file suffix it matches is unchanged.
Not checked: other platforms, the VL bundle, two processes sharing a directory at once. Not independently reviewed.
Re-checked on v0.18.0 (2026-10-14): unchanged for Qwen3.5 (+530 MB per engine create). The opt-in liteRtLmMaxProgramCacheBytes cap remains the mitigation; whether to set a default cap is an open decision.
Decision (2026-10-14): set a default liteRtLmMaxProgramCacheBytes cap of about 1 GiB per cache directory, overridable to a higher value or unlimited. This changes default behaviour, so it targets the next minor release, not 0.12.x.
Closed with the bounded-cache mitigation shipped in 0.13.0 by #1089 (via #1095): a 1 GiB default program-cache cap per directory, with -1 for unlimited. Warm-create speed and cache growth depend on the LiteRT-LM runtime (google-ai-edge/LiteRT-LM#2503).
blocked-runtimeRequires upstream or native runtime support before Dart package work can complete.bugSomething isn't workingpriority:P2Planned next: useful unblocked work or validation after P1 items
Activity
leehack commentedon Sep 21, 2026
Reproduced on macOS arm64, LiteRT-LM 0.17.0-6, Qwen3.5-0.8B INT8, GPU, llamadart
82cbb101: one process, fresh cache dir, one engine at a time, 8-token generation and full dispose between creates.*_mldrift_program_cache.binDATA_LOSSengine_createonly; the weight cache stays at 751,917,896 bytes. (Init times are inflated: another GPU run shared the machine.)Deserialization failed: DATA_LOSS(delegate_kernel.cc:808) for them. Deleting the file costs no init time, so the cache gives no benefit for this model.$TMPDIR/llamadart_litert_lmon macOS/Android,litert_lm_service.dart_defaultCacheDir;nullelsewhere, so the runtime caches next to the model) throughlitert_lm_engine_settings_set_cache_dir. It never names, opens or deletes cache files, and only one engine is alive at a time. Runtime-side.SetDisableProgramCache/cache_compiled_shaders_onlyexist in C++ only); the:nocachesentinel also disables the GPU weight cache.Not checked: other platforms/GPUs, two processes on one directory, a portable bundle.
Options for llamadart, none implemented: (1) document the cache directory and make it configurable; (2) opt-in prune of
*_mldrift_program_cache.binabove a size cap before engine create, logged so the bug stays visible; (3) a C setter for the program-cache switch in leehack/litert-lm-native; (4) an upstream report referencing LiteRT-LM#2503.feat: configurable LiteRT-LM cache directory and opt-in program cache…
leehack commentedon Sep 21, 2026
Mitigation from #565 verified on real hardware (Apple M4 Max, Metal,
main8cdfb2ad2, publicLlamaEngineAPI, Qwen3.5-0.8B INT8, throwawayliteRtLmCacheDir, six creates in one process):liteRtLmMaxProgramCacheBytesnoneThe weight cache (751,917,896 bytes) kept its size and mtime throughout; the missing nested directory was created at the lazy engine create; output was identical and coherent in every step.
DATA_LOSSappeared only on create 4 (appending to a previously capped file), not on create 2.Not exercised on hardware:
*.xnnpack_cachepreservation (no such file on the GPU path), the prune-failure path, links, other platforms.feat: adopt LiteRT-LM v0.18.0 (#968)
leehack commentedon Oct 14, 2026
Re-checked on LiteRT-LM
v0.18.0published bytes for the 0.12.0 validation (#966): not fixed forQwen3.5-0.8B_int8.litertlm.macOS arm64 (M4 Max, Metal through WebGPU),
main29c52578, portable validation bundle, fresh cache directory, six engine creates across two processes (qwen35-litert-gpurun twice):DATA_LOSSlinesDeserialization failed: DATA_LOSS(ml_drift/webgpu/inference_context.cc:187), now from the second create on.liteRtLmMaxProgramCacheBytescap remains the mitigation; it was not re-exercised here, but the file suffix it matches is unchanged.Not checked: other platforms, the VL bundle, two processes sharing a directory at once. Not independently reviewed.
leehack commentedon Oct 14, 2026
Re-checked on v0.18.0 (2026-10-14): unchanged for Qwen3.5 (+530 MB per engine create). The opt-in
liteRtLmMaxProgramCacheBytescap remains the mitigation; whether to set a default cap is an open decision.leehack commentedon Oct 14, 2026
Decision (2026-10-14): set a default
liteRtLmMaxProgramCacheBytescap of about 1 GiB per cache directory, overridable to a higher value or unlimited. This changes default behaviour, so it targets the next minor release, not 0.12.x.leehack commentedon Oct 15, 2026
Closed with the bounded-cache mitigation shipped in 0.13.0 by #1089 (via #1095): a 1 GiB default program-cache cap per directory, with -1 for unlimited. Warm-create speed and cache growth depend on the LiteRT-LM runtime (google-ai-edge/LiteRT-LM#2503).