Instructions to use litert-community/ZONOS3-Mini with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/ZONOS3-Mini with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Download host/graphs.cpp from litert-community/ZONOS3-Mini: direct link, hf CLI and curl.
- Browser
- Download file 3.45 kB
-
https://huggingface.co/litert-community/ZONOS3-Mini/resolve/main/host/graphs.cpp
- Command line
-
hf download hf://litert-community/ZONOS3-Mini/host/graphs.cpp
-
curl -L -o graphs.cpp https://huggingface.co/litert-community/ZONOS3-Mini/resolve/main/host/graphs.cpp
3.45 kB
| // Opaque ABI subset of the LiteRT 2.3 TensorFlow Lite C signature-runner API. | |
| extern "C" { | |
| struct TfLiteModel; struct TfLiteInterpreterOptions; struct TfLiteInterpreter; | |
| struct TfLiteSignatureRunner; struct TfLiteTensor; | |
| TfLiteModel* TfLiteModelCreateFromFile(const char*); | |
| void TfLiteModelDelete(TfLiteModel*); | |
| TfLiteInterpreterOptions* TfLiteInterpreterOptionsCreate(); | |
| void TfLiteInterpreterOptionsSetNumThreads(TfLiteInterpreterOptions*, int32_t); | |
| void TfLiteInterpreterOptionsDelete(TfLiteInterpreterOptions*); | |
| TfLiteInterpreter* TfLiteInterpreterCreate(const TfLiteModel*, const TfLiteInterpreterOptions*); | |
| void TfLiteInterpreterDelete(TfLiteInterpreter*); | |
| TfLiteSignatureRunner* TfLiteInterpreterGetSignatureRunner(const TfLiteInterpreter*, const char*); | |
| void TfLiteSignatureRunnerDelete(TfLiteSignatureRunner*); | |
| int TfLiteSignatureRunnerAllocateTensors(TfLiteSignatureRunner*); | |
| TfLiteTensor* TfLiteSignatureRunnerGetInputTensor(TfLiteSignatureRunner*, const char*); | |
| const TfLiteTensor* TfLiteSignatureRunnerGetOutputTensor(const TfLiteSignatureRunner*, const char*); | |
| int TfLiteSignatureRunnerInvoke(TfLiteSignatureRunner*); | |
| int TfLiteTensorCopyFromBuffer(TfLiteTensor*, const void*, size_t); | |
| int TfLiteTensorCopyToBuffer(const TfLiteTensor*, void*, size_t); | |
| } | |
| template<class T, void(*Delete)(T*)> using Handle = std::unique_ptr<T, decltype(Delete)>; | |
| class CpuGraph final : public Graph { | |
| Handle<TfLiteModel, TfLiteModelDelete> model{nullptr, TfLiteModelDelete}; | |
| Handle<TfLiteInterpreter, TfLiteInterpreterDelete> interpreter{nullptr, TfLiteInterpreterDelete}; | |
| Handle<TfLiteSignatureRunner, TfLiteSignatureRunnerDelete> signature{nullptr, TfLiteSignatureRunnerDelete}; | |
| public: | |
| explicit CpuGraph(const fs::path& path) { | |
| model.reset(TfLiteModelCreateFromFile(path.c_str())); | |
| require(bool(model), "load " + path.string()); | |
| Handle<TfLiteInterpreterOptions, TfLiteInterpreterOptionsDelete> opts( | |
| TfLiteInterpreterOptionsCreate(), TfLiteInterpreterOptionsDelete); | |
| require(bool(opts), "create CPU options"); | |
| TfLiteInterpreterOptionsSetNumThreads(opts.get(), 4); | |
| interpreter.reset(TfLiteInterpreterCreate(model.get(), opts.get())); | |
| require(bool(interpreter), "create CPU interpreter"); | |
| signature.reset(TfLiteInterpreterGetSignatureRunner(interpreter.get(), "serving_default")); | |
| require(signature && TfLiteSignatureRunnerAllocateTensors(signature.get()) == 0, "allocate signature"); | |
| } | |
| void run(const std::vector<View>& inputs, const Outputs& outputs) override { | |
| for (size_t i=0; i<inputs.size(); ++i) { | |
| auto name = "args_" + std::to_string(i); | |
| auto t = TfLiteSignatureRunnerGetInputTensor(signature.get(), name.c_str()); | |
| require(t && TfLiteTensorCopyFromBuffer(t, inputs[i].data, inputs[i].size*sizeof(float)) == 0, name); | |
| } | |
| require(TfLiteSignatureRunnerInvoke(signature.get()) == 0, "invoke signature"); | |
| for (size_t i=0; i<outputs.size(); ++i) { | |
| auto name = "output_" + std::to_string(i); | |
| auto t = TfLiteSignatureRunnerGetOutputTensor(signature.get(), name.c_str()); | |
| auto& v = *outputs[i]; | |
| require(t && TfLiteTensorCopyToBuffer(t, v.data(), v.size()*sizeof(float)) == 0, name); | |
| } | |
| } | |
| }; | |
| std::unique_ptr<Graph> open_graph(const fs::path& path, bool) { | |
| return std::make_unique<CpuGraph>(path); | |
| } | |