Browse the Repository | Everything since v0.3.12
The first stable release, and the source code tree switched from TensorFlow to LiteRT.
LiteRT
- TfLite is built from LiteRT 2.2.0 (
tflite/in the LiteRT tree) instead oftensorflow/lite/. TensorFlow is still fetched, but only as a build dependency. tflite_beam:tflite_version/0answers<<"2.2.0">>. A delegate plugin loaded throughtflite_beam_delegate:external/1has to be built against the same LiteRT release.tflite_beam:source_tree/0answerslitert, so a stale or wrong binary can be told apart.tensorflow_version/0reports the TensorFlow release the build pulled in.- The seven precompiled targets and their glibc requirements are unchanged.
New
- LiteRT compiled model API.
tflite_beam_litert_compiled_model: accelerators by name (cpu,gpu,npu),fully_accelerated/1to check whether the accelerator took the whole graph, and a per-operator profiler (profile/2,summarise_profile/1).tflite_beam_litert_compiled_model_servershares one model between callers behind a bounded queue.tflite_beam_litert_compiled_model_isolatedruns it on its own node, so a crash in native code comes back as{error, _}instead of taking the VM down. This is a build option:TFLITE_BEAM_ENABLE_LITERT_API=truefetches the precompiled variant that has it, or turns it on in a source build. The GPU accelerator is built whenever the LiteRT API is. armv6 and armv7l have no LiteRT variant, because they build without XNNPACK and LiteRT's CPU accelerator is XNNPACK. - Delegates.
tflite_beam_delegate:xnnpack/0,1,tflite_beam_delegate:external/1,2for any library implementing TfLite's delegate plugin interface,tflite_beam_coral:edge_tpu_delegate/0,1, andtflite_beam_interpreter_builder:add_delegate/2,3with#{on_decline => error | fallback}.tflite_beam_delegate:available/0reports what the build compiled in. XNNPACK is now attached explicitly inbuild/2instead of by TfLite insideallocate_tensors/1: same output, but it shows up in the execution plan right away and can be configured. tflite_beam_interpreter_server. One interpreter in a process, so setting inputs, invoking and reading outputs is one step. Two processes sharing a raw interpreter got each other's answers 147 times in 400 calls on a real model. For the direct API there istflite_beam_interpreter:controlling_process/1,2, likegen_tcp.- Signature runners.
tflite_beam_interpreter:get_signature_runner/2andtflite_beam_signature_runner: inputs and outputs by name instead of by index. Alsoresize_input_tensor/3andresize_input_tensor_strict/3,enable_cancellation/1andcancel/1,release_non_persistent_memory/1,reset_variable_tensors/1,signature_inputs/2,signature_outputs/2,subgraphs_size/1andverify_and_build_from_buffer/1,2. - Tokenizer. CJK ideographs are split the way BERT does it, so CJK characters no longer come back as
[UNK]. The punctuation lookup no longer makes a process call per character: 5.56us to 0.21us per character, and 24,000 characters of Chinese from 923ms to 13ms. - Verified downloads. Precompiled tarballs are checked against a sha256 manifest shipped in the package (
checksum.term) before unpacking. An https download that cannot be verified is refused;TFLITE_BEAM_CACERTnames a CA store andTFLITE_BEAM_UNSAFE_HTTPSskips the check. - Model metadata reports
custom_metadata.tflite_beam:xnnpack_max_tensor_dims/0. Tensor types{f, 8}and{f8_e4m3fn, 8}. Edge TPU context options are applied instead of ignored.
Memory safety
Each of these has a test that fails without the fix.
- Tensor handles keep their interpreter alive, and are retired when
allocate_tensors/1, a resize or a secondbuild/2moves the tensor. They used to read freed memory. - Resizing an input past XNNPACK's maximum rank wrote past a stack buffer (SIGBUS or SIGSEGV depending on the rank). Refused now.
- A failed
build/2returnedokand left an empty interpreter that the next call dereferenced. - Truncated or corrupt models are verified instead of walked, and a tensor with a null name no longer crashes the node.
- Every NIF is behind an exception guard, every interpreter call takes the in-use guard, and three data races in the ownership state found by ThreadSanitizer are fixed.
- Resource destructors run on a reaper thread instead of the scheduler: a 49MB model took 15.8ms in the destructor, now under 5us. Tensor copies,
build/2andallocate_tensors/1run on dirty schedulers. - Leaks: the model buffer on parse failure, the signature runner registry, the error reporter, and references stranded when an allocation failed partway.
Upgrading from 0.3
Nothing was renamed. One module was removed and a few return values changed.
tflite_beam_interpreter_builder:build/2returns{error, Reason}on failure instead ofok.- A tensor handle stops working once
allocate_tensors/1, a resize or a secondbuild/2has moved it. Fetch it again. tflite_beam_tensor:set_data/2requires a binary of exactly the tensor's size. A short one used to be written partially and reported as success.tflite_beam_interpreter:predict/2returnslist(binary()) | {error, binary()}. A failed invoke or an unreadable output fails the whole call.get_signature_defs/1returns signature keys and input/output names as binaries, not atoms.tflite_beam_tensor:type/1can also return{u, 16},{bf, 16},{f, 8},{f8_e4m3fn, 8}andunknown.- Two processes calling one interpreter at the same time are refused instead of raced.
- XNNPACK is attached in
build/2.tflite_beam_ops_builtin_builtin_resolver:new(#{apply_default_delegates => true})gives TfLite's lazy delegation back. - Negative tensor indices are refused by
set_inputs/2,set_outputs/2andset_variables/2. TfLite reads before its tensor table with them. set_num_threads/2accepts-1.list_associated_files/1andget_associated_file/2return{error, _}for a model with no archive, instead ofbad_eocdfromzip.- A machine with no CA certificate store no longer downloads precompiled binaries unverified.
tflite_beam_contrib_huggingfaceis removed.