Repository navigation
omnivoice: harden the rknn_zeroop packed-weight disk cache - #1302
Merged
Merged
Conversation
The zero-op generator's cache (rknn_zeroop) trusted a warm pack file on its size alone, never created the cache directory, and wrote pack files in place with unchecked fwrite. Three consequences: a fresh install never populates the cache (silent cold pack every run); a crash, ENOSPC or power loss can leave a full-size file with a torn tail that the size check accepts and the NPU then runs on; and any cache I/O failure was a hard pack error that killed the session. - create_directories() the cache dir when caching is on - each cache file is [packed body][FNV-1a-64 trailer], published atomically (per-pid .tmp, fflush+fsync, rename, tmp unlinked on failure); pre-trailer caches self-invalidate via the size check, so the format change needs no fingerprint bump - the warm path verifies every trailer before syncing to the NPU; any miss (missing/truncated/corrupt/bad checksum) falls back to a cold repack instead of failing - mkdir/write/flush failures are non-fatal: recorded in a new Engine::last_warning() and logged by the generator; the run repacks Board gates (RK3588, twin geometry, seed 42, g=2.0, all audio md5 31eaa272118dd19fad97ac326a72f91d): fresh install creates the dir and writes 112 files (pack_ms 8135.8); warm load verifies (2844.9); chattr +i dir -> rc=0, empty dir, no .tmp, warning logged; flipping two bytes mid-file in one full-size pack -> checksum miss, cold repack (9317.2). x86: ovz_engine.cpp stub tier passes g++ -fsyntax-only with ENGINE_HAVE_RKNN=1; check_loader_catalog_sync.py passes. Co-Authored-By: Claude <[email protected]> Performed-by: Claude-Fable-5
Owner
|
@wOvAN Thanks! PR mergd. One minor issue: Servers may register the same OmniVoice checkpoint under two different IDs, such as |
Contributor
Author
|
Merged before the review-round amend landed - the fixes (temp sweep after a killed packer, mkstemp publish, named warm-miss warnings, pre-pack zeroing, docs' warm-load number) continued as #1303 with the same board gates (p18-p23, twin md5 parity). |
0xShug0
pushed a commit
that referenced
this pull request
Nov 16, 2026
Follow-up to #1302 (merged as the pre-review commit; these fixes were validated on the board in the same session, p18-p23): - sweep *.tmp.* temps at the start of pack_weights: a process killed mid-cold-pack leaked up to 112 ~7 MB temps into the cache dir forever (only exact final names are ever read back) - publish temps via mkstemp instead of a per-pid name: pid namespaces sharing a bind-mounted model dir collide on ...bin.<pid>.tmp - the warm->cold fallback (the main new path) now names the file in last_warning(): cache: warm miss at <file> (read/checksum) | (device sync), repacking - a silent repack was visible only as a pack_ms jump, and a failed device sync masqueraded as a cache miss - zero each device buffer before pack_b so file + trailer never carry uninitialized device-pool bytes if a future librknnrt rounds B.size above the packed grid - docs: warm load is ~2.8 s (the FNV verification pass), not ~1.1 s; document the sweep, mkstemp, the warm-miss warning, and cache growth (~812 MB per fingerprint, never pruned) Board gates (RK3588 twin, seed 42, g=2.0, all audio md5 31eaa272118dd19fad97ac326a72f91d): fresh install cold pack 8797.9 ms, 112 files; warm 2868.9 ms, zero warnings; chattr +i dir -> rc=0, dir empty, write-failed warning; mid-file corruption -> warm-miss warning names the file, repack 9831.6; kill -9 at 9 final + 1 tmp -> rerun leaves 112 final / 0 tmp, 8880.3. x86 stub tier g++ -fsyntax-only with ENGINE_HAVE_RKNN=1 and check_loader_catalog_sync.py pass. Performed-by: Claude-Fable-5 Co-authored-by: wOvAN <[email protected]> Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to the merged zero-op generator (#1297): harden the packed-weight disk cache, which
was the one thing the review round flagged as easy to get wrong and left for a second PR.
What was fragile
pack_weights()cached the per-(layer, shape) packed B operands under<cache_dir>/ovz_<fingerprint>.<layer>.<shape>.binand a warm run trusted that cache on filesize alone. Three holes:
cache_dir, so on a clean checkout the firstfopen(..., "wb")failed on every file, the cache was silently never written, and every run paid the fullcold pack.
fwrite's return was ignored and files were written in place, soa full disk, an ENOSPC mid-write, or a crash mid-pack left a short file the size-check caught
(good) - but the real exposure is the inverse, a crash that left a full-size file with a torn
tail, which the size-check accepted as warm.
swapped checkpoint repacks; but a cache file that got bit-rotted or half-committed on disk to
the right size was loaded and synced to the NPU as if valid.
What it does now
pack_weights()createscache_dir(withstd::filesystem::create_directories) when cachingis on, so a fresh install populates the cache on its first run.
[packed body][FNV-1a-64 trailer], published atomically:mkstempaunique temp in the cache dir (unique across pid namespaces, so containerized deploys sharing a
bind-mounted model dir cannot collide on one temp name),
fflush+fsync, thenrenameover the final name. A half-written pack can never masquerade as a complete file, and the
temp is unlinked on any failure. Temps left by a process killed mid-pack are swept at the
start of the next
pack_weights()(they are never read back, so they are a pure disk leak).syncing it to the NPU. Any miss (missing/truncated/corrupt file, bad checksum, failed device
sync) drops to the cold pack-and-write path, so the engine self-heals instead of running on
garbage, and names the file in the warning (a silent warm->cold flip is otherwise visible
only as a
pack_msjump).pack_b, so file + trailer never carryuninitialized device-pool bytes if a future
librknnrtroundsB.sizeabove the packed grid.warning on the engine,
rknn_zeroop_generatorsurfaces it throughdebug::log_message(Warning, "omnivoice.rknn_zeroop", ...), and the run proceeds byrepacking. A read-only cache directory costs a warm start, not a session.
The file-format change (adding the 8-byte trailer) self-invalidates the pre-trailer caches: the
old files fail the size check (
size != wsz + 8) and repack, so no fingerprint-tag bump isneeded and the transition needs no migration step.
Validation (RK3588 board, twin geometry, seed 42, g=2.0)
The twin gate renders a byte-identical WAV when the cache is correct, so all five gates check
that
md5 == 31eaa272118dd19fad97ac326a72f91d(the established twin hash) is preserved.cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DENGINE_ENABLE_RKNN=ON -DENGINE_RKNN_INCLUDE_DIR=/usr/local/include -DENGINE_RKNN_LIBRARY=/usr/lib/librknnrt.so -DAUDIOCPP_MODEL_SET=custom -DAUDIOCPP_MODELS=omnivoicethencmake --build build --target audiocpp_cli; RC=0.<model_directory>/rknn-zeroop-cache):./build/bin/audiocpp_cli --task clon --family omnivoice --model models/OmniVoice-GGUF/omnivoice-f16.gguf --backend cpu --threads 4 --text "<2 Russian sentences>" --voice-ref assets/resources/b.wav --reference-text "Some call me nature..." --seed 42 --guidance-scale 2.0 --session-option 'omnivoice.exec_plan={"generator":{"impl":"rknn_zeroop"}}'files written (28 layers x 4 shapes),
pack_ms 8797.9(cold pack), audio md5 matches.pack_ms 2868.9(checksum-verified warm load),audio md5 matches, zero cache warnings in the log.
chattr +i;chmod 500is not a gatefor root, it has
CAP_DAC_OVERRIDE), twin run - rc=0, audio md5 matches, the directory isleft empty (mkstemp temp + rename: nothing survives), and the log carries
cache: write failed for .../ovz_omnivoice-zeroop-v1-<fp>.0.0.bin.pack_ms 9831.6), audio md5 matches, andthe log carries
cache: warm miss at .../ovz_...0.0.bin (read/checksum), repacking(therepack rewrites all 112 packs: the miss check is per-file, the fallback is deliberately
global - 8 s of repack beats per-file bookkeeping).
pkill -9 -x audiocpp_climid cold pack (112-file dirhad 9 final + 1
.tmp.XXXXXXat the kill), then relaunch - the sweep removes the orphanedtemp (rerun leaves
112 final, 0 tmp), full cold repackpack_ms 8880.3, audio md5 matches.x86:
ovz_engine.cpp(stub tier) andrknn_zeroop_generator.cpppassg++ -fsyntax-only -std=c++17 -DENGINE_HAVE_RKNN=1;tools/check_loader_catalog_sync.pypasses. The warm-path FNV is ~19 MB/layer over 112 files, well under the NPU pack/sync time, so
warm
pack_msis unchanged for practical purposes.Known limitations
swapped checkpoint lingers until removed by hand (~812 MB per fingerprint). Out of scope here.
~8 s on the board, accepted for the simplicity.