PiVo-1.4M / runner /README.md
mlboydaisuke's picture
PiVo-1.4M on LiteRT: day-0 files
042f389 verified
|
Raw History Blame Contribute Delete
8.63 kB

runner/

pivo_runner is the C++ host loop of this repository on LiteRT's C API (LiteRT 2.3.0): the author's loop (pivo/runtime.py of empero-ai/PiVo-1.4M at revision 515d84fc) in C++ around the same graphs as the Python host. It takes phone ids, not text: make_inputs.py runs the author's frontend on the Mac (or any computer with the host's packages) and writes them. The phone numbers in this repository were measured with it. No binary is included; build.sh builds it.

File What it is
pivo_runner.cc The runner (one file, C++17, LiteRT C API)
fetch_kit.sh Downloads the LiteRT 2.3.0 C API headers and libraries into runner/kit/, each checked against its SHA-256
build.sh Builds runner/build/mac/pivo_runner (macOS, Apple silicon) and runner/build/android/pivo_runner (Android arm64, NDK r29)
make_inputs.py Text to the runner's inputs, with the author's frontend (host/pivo/text.py)
check_host_tables.py Compares the runner's host arithmetic with NumPy's, bit for bit

Build

bash runner/fetch_kit.sh
bash runner/build.sh mac          # or android (NDK at $NDK, default ~/Library/Android/sdk/ndk/29.0.13113456), or all

-ffp-contract=off keeps the compiler from fusing multiplies and adds that the source does not fuse, so the host's values (phase features, RoPE tables, the de-emphasis filter) round as NumPy and Python round them in the author's code. The runner computes sin and cos with NumPy's float32 algorithm (Cody-Waite reduction and polynomials) rather than the C library's, which differs from NumPy by one unit in the last place on about 15 % of arguments. On the Mac, runner/build/mac/pivo_runner --host-tables tables.f32 and python runner/check_host_tables.py --tables tables.f32 compare 272,978 values with NumPy.

Run

python runner/make_inputs.py --out inputs "NASA is ready for the next mission."
runner/build/mac/pivo_runner --model vocoder_frame_fp32.tflite --decoder decoder_fp32.tflite \
  --encoder 'encoder_n{N}_fp32.tflite' --fixtures inputs --count 1 --out out --dump none --wav-dir out/wav

out/wav/000.wav is the audio (16 kHz mono PCM16). The main pass synthesizes input 000 once before it, unrecorded, as a warm-up; each input gets one {"kind":"utt"} JSON line on standard output with its length, real-time factor, time to the first audio and the calls and milliseconds of each graph.

On an Android phone, push the runner, kit/android/libLiteRt.so, the accelerator libraries the run uses and the .tflite files to one directory (for example /data/local/tmp/pivo), then run it there with LD_LIBRARY_PATH=. and --libdir . (the directory LiteRT loads its accelerator and NPU libraries from).

Flag Default Meaning
--model FILE (required) The vocoder graph: vocoder_frame_*.tflite with --vocoder frame, vocoder_step_*.tflite with --vocoder step
--decoder FILE (required) decoder_*.tflite
--encoder PATTERN (required) The encoder files with {N} for the length: 'encoder_n{N}_fp32.tflite'
--buckets LIST 32,64,128,256,512 The encoder lengths that exist; an input uses the smallest that holds it
--vocoder frame|step frame One vocoder_frame call per 10 ms frame, or the author's conditioning call and four vocoder_step calls
--conditioning FILE conditioning_*.tflite (needed with --vocoder step)
--fixtures DIR, --count K (required) The inputs 000 to K-1 written by make_inputs.py
--out DIR (required) Output directory; with --dump full the audio of input k goes to DIR/model0/<k>.f32 as float32, zero-padded to --out-elems
--out-elems N 480000 The length of each dump (480,000 samples = 30 s, the model's longest utterance)
--dump full|none full Write the float32 dumps or not
--wav-dir DIR Also write each input's audio as DIR/<k>.wav
--json FILE Also write the JSON lines to a file
--speed S 1.0 Speaking rate, 0.5 to 2.0, as the author's speed
--accel cpu|gpu|npu|npu+cpu cpu The accelerator of every graph
--enc-accel, --dec-accel, --voc-accel, --cond-accel --accel The accelerator of one graph
--gpu-precision default|fp16|fp32|fp16acc32 fp32 GPU precision of every graph (default = the accelerator's own choice, FP16 on the phones tested)
--enc-precision, --dec-precision, --voc-precision, --cond-precision --gpu-precision GPU precision of one graph
--cpu-threads N 1 XNNPACK threads per CPU graph. The run stops with exit code 6 (THREADS_NOT_APPLIED) when N >= 2 and the process runs fewer threads
--libdir DIR Where LiteRT loads the GPU accelerator and NPU libraries from
--cache-dir DIR Where the NPU's compiled graphs are kept, so later loads skip the compile
--npu-vendor qualcomm|google_tensor qualcomm Which NPU options the runner sets
--burst 0|1 1 Qualcomm HTP performance mode Burst
--rounds R, --ab-fixture ID 0, 000 After the main pass, a latency phase: input ID synthesized R times, then each graph's middle call of that input alone R times (summary lines)
--warmup W 1 Warm-up runs before each part of the latency phase
--trace 1 0 Add a {"kind":"trace"} line per input: the durations and pitch periods the loop chose
--host-tables FILE Write the host arithmetic tables for check_host_tables.py and exit

The output lines also follow the contract of the benchmark harness that ran the phone tests: pid= first, compile_end model[0] after every graph's compile (model 0, the vocoder, compiles last), done wall_ms= last.

Libraries

fetch_kit.sh downloads and checks:

File From SHA-256
kit/litert_cc_sdk/ LiteRT v2.3.0 release, litert_cc_sdk.zip zip 44ebb188ae1a510f233639fa499928fdaaba46436a153a2dbfbb9d87d59728d2
kit/android/libLiteRt.so Maven com.google.ai.edge.litert:litert:2.3.0 e5b7e3413a8b428b1a1b669f368cf613058868bc7b63e10d0b9c2e6ba55c97d8
kit/android/libLiteRtClGlAccelerator.so Maven litert-gpu:2.3.0 c200369269a3994b646a8d0ac56ff29127c6ce742abcfd345a7d478eab3b6c6d
kit/android/libLiteRtDispatch_Qualcomm.so Maven litert-npu-runtime-qualcomm:2.3.0 22e2d581555617c4a4dabc46ed74833829816e9cd13a0eea27dd4d2178049751
kit/android/libLiteRtCompilerPlugin_Qualcomm.so Maven litert-npu-runtime-qualcomm:2.3.0 51cff612134bc5d0e3b56db9c285f734218ae984f7201569d067b9e86b2b5ae2
kit/android_gt/libLiteRtDispatch_GoogleTensor.so Maven litert-npu-runtime-google-tensor:2.3.0 e38144002de11a15f653bb34f1c7efa4cb5af7acdddca424eb32297c5b5f9391
kit/android_gt/libLiteRtCompilerPlugin_google_tensor.so Maven litert-npu-runtime-google-tensor:2.3.0 6b1432e771c54b970412cd0a2450611a465011df7e3314321d813615f47c244e
kit/mac/libLiteRt.dylib PyPI ai-edge-litert 2.3.0 (macOS arm64 wheel) f3d8b2c3dea5125111de6b005820088629efd13db04b5f157ffd4f2c5dbb318b
kit/mac/libLiteRtMetalAccelerator.dylib the same wheel 5531feca4ff0e2c67628e09d635a6f79da74534e88b7a3d262efa5dcda59e95d

The Qualcomm NPU also needs Qualcomm's QAIRT 2.50.0.260828 libraries next to them on the phone (the version LiteRT 2.3.0 is built against). QAIRT is Qualcomm's SDK under Qualcomm's license and is not downloaded here. The phone tests used these files from it:

File SHA-256
libQnnHtp.so 09e930b6af975bae23bcf6965ac2ce60f6b999aff37cb7eabe9b4d7c1bc3f264
libQnnHtpPrepare.so fb2580518a1072b2d32324727c187b8c8fc77a385ded839666eb5bc66cd0ad94
libQnnHtpV81CalculatorStub.so 2fa093c81f4cca3aedc33ab763f7d37ae35d077e9122fb09d67a701c83c0d265
libQnnHtpV81Skel.so 9b7266e38aea818a1caeba5cbfebd9a8cbdba8f25dd82126d9b44ebf4fec4fa0
libQnnHtpV81Stub.so 5b0ea1ef9929bdfcdda0d8dfc6ddffdc913fa2be02cf01a1574d644b2e0e0d38
libQnnIr.so 2e40d5c9e843a2c583f59abbd6a09ab2f95c14f599aaee9226eaf8b10df3bc4f
libQnnSaver.so 632ee1cd0f7f0855086e9da989a4725e437108dd5bf504bc9bc6ac535a9bc1a8
libQnnSystem.so b30bd9880dc48f6c5349185a7d45b326f8a064b10072e60094354fa23d9a2027

LiteRT 2.3.0 reads the CPU thread count from its CPU options under the name xnnpack (in both libLiteRt.so and libLiteRt.dylib); the runner sets it there and, after the warm-up utterance, checks that its own process runs at least that many threads.