LiteRT Next הוא קבוצה חדשה של ממשקי API שמשפרים את LiteRT, במיוחד מבחינת האצת חומרה וביצועים של אפליקציות למידת מכונה ול-AI במכשיר. ממשקי ה-API הם גרסה אלפא וזמינים ב-Kotlin וב-C++.
ממשק ה-API של מודל הידור הבא של LiteRT מבוסס על ממשק ה-API של TensorFlow Lite Interpreter, ומפשט את תהליך הטעינה וההפעלה של המודל לצורך למידת מכונה במכשיר. ממשקי ה-API החדשים מספקים דרך יעילה חדשה להשתמש בהאצה של חומרה, ומבטלים את הצורך לטפל במודלים של FlatBuffers, בתאימות הדדית של מאגרי קלט/פלט ובמפיצים. ממשקי ה-API של LiteRT Next לא תואמים לממשקי ה-API של LiteRT. כדי להשתמש בתכונות של LiteRT Next, כדאי לעיין במדריך תחילת העבודה.
כדי לראות דוגמאות להטמעות של LiteRT Next, אפשר לעיין באפליקציות הדגמה הבאות:
כדי להריץ את ההסקה באמצעות ממשקי ה-API של LiteRT Next, צריך לבצע את השלבים הבאים:
טוענים מודל תואם.
הקצאת מאגרי הטנסורים של הקלט והפלט.
קוראים את המודל המהדר.
קריאת ההסקות למאגר פלט.
בקטעי הקוד הבאים מוצגת הטמעה בסיסית של התהליך כולו ב-Kotlin וב-C++.
C++
// Load model and initialize runtimeLITERT_ASSIGN_OR_RETURN(automodel,Model::CreateFromFile("mymodel.tflite"));LITERT_ASSIGN_OR_RETURN(autoenv,Environment::Create({}));LITERT_ASSIGN_OR_RETURN(autocompiled_model,CompiledModel::Create(env,model,kLiteRtHwAcceleratorCpu));// Preallocate input/output buffersLITERT_ASSIGN_OR_RETURN(autoinput_buffers,compiled_model.CreateInputBuffers());LITERT_ASSIGN_OR_RETURN(autooutput_buffers,compiled_model.CreateOutputBuffers());// Fill the first inputfloatinput_values[]={/* your data */};input_buffers[0].Write<float>(absl::MakeConstSpan(input_values,/*size*/));// Invokecompiled_model.Run(input_buffers,output_buffers);// Read the outputstd::vector<float>data(output_data_size);output_buffers[0].Read<float>(absl::MakeSpan(data));
Kotlin
// Load model and initialize runtimevalmodel=CompiledModel.create(context.assets,"mymodel.tflite",CompiledModel.Options(Accelerator.CPU))// Preallocate input/output buffersvalinputBuffers=model.createInputBuffers()valoutputBuffers=model.createOutputBuffers()// Fill the first inputinputBuffers[0].writeFloat(FloatArray(data_size){data_value/* your data */})// Invokemodel.run(inputBuffers,outputBuffers)// Read the outputvaloutputFloatArray=outputBuffers[0].readFloat()
LiteRT API החדש: פיתוח יעיל יותר באמצעות בחירת מעבדים אוטומטית, ביצוע אסינכרוני אמיתי וטיפול יעיל במאגרי נתונים של קלט/פלט.
ביצועים ברמה הגבוהה ביותר של GPU: שימוש בהאצה מתקדמת של GPU לצורך למידת מכונה במכשיר. יכולת הפעולה ההדדית החדשה של מאגר הנתונים הזמני מאפשרת העברה ללא העתקה ומצמצמת את זמן האחזור בסוגים שונים של מאגרי נתונים זמניים של GPU.
הסקת מסקנות ברמה גבוהה יותר של AI גנרטיבי: הפעלת השילוב הפשוט ביותר עם הביצועים הטובים ביותר למודלים של AI גנרטיבי.
Unified NPU Acceleration: גישה חלקה ל-NPUs מספקי צ'יפים מרכזיים, עם חוויית פיתוח עקבית. האצת LiteRT NPU זמינה דרך תוכנית גישה מוקדמת.
שיפורים מרכזיים
ב-LiteRT Next (Compiled Model API) יש את השיפורים העיקריים הבאים ב-LiteRT (TFLite Interpreter API). מדריך מקיף להגדרת האפליקציה באמצעות LiteRT Next זמין במאמר תחילת העבודה.
שימוש במאיץ: כדי להריץ מודלים ב-GPU באמצעות LiteRT, צריך ליצור באופן מפורש משימות למענה, להפעיל פונקציות ולבצע שינויים בתרשים. ב-LiteRT
לאחר מכן, פשוט מציינים את המאיץ.
יכולת פעולה הדדית של מאגרי נתונים (buffers) בחומרה: ב-LiteRT אין אפשרות להשתמש במאגרי נתונים, וכל הנתונים עוברים דרך זיכרון המעבד. ב-LiteRT Next אפשר להעביר מאגרי נתונים לחומרה של Android (AHWB), מאגרי נתונים של OpenCL, מאגרי נתונים של OpenGL או מאגרי נתונים מיוחדים אחרים.
ביצוע אסינכרוני: LiteRT Next כולל API אסינכרוני שעוצב מחדש, ומספק מנגנון אסינכרוני אמיתי שמבוסס על גדרות סנכרון. כך אפשר לקצר את זמני הביצוע הכוללים באמצעות שימוש בחומרה מגוונת – כמו מעבדים, מעבדים גרפיים, מעבדים לעיבוד נתונים (NPUs) – למשימות שונות.
טעינה של מודל: ב-LiteRT Next אין צורך בשלב build נפרד בטעינה של מודל.
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-09-03 (שעון UTC)."],[],[],null,["# LiteRT Next Overview\n\n| **Experimental:** LiteRT Next is an alpha release and under active development.\n\nLiteRT Next is a new set of APIs that improves upon LiteRT, particularly in\nterms of hardware acceleration and performance for on-device ML and AI\napplications. The APIs are an alpha release and available in Kotlin and C++.\n\nThe LiteRT Next Compiled Model API builds on the TensorFlow Lite Interpreter\nAPI, and simplifies the model loading and execution process for on-device\nmachine learning. The new APIs provide a new streamlined way to use hardware\nacceleration, removing the need to deal with model FlatBuffers, I/O buffer\ninteroperability, and delegates. The LiteRT Next APIs are not compatible with\nthe LiteRT APIs. In order to use features from LiteRT Next, see the [Get\nStarted](./get_started) guide.\n\nFor example implementations of LiteRT Next, refer to the following demo\napplications:\n\n- [Image segmentation with Kotlin](https://github.com/google-ai-edge/LiteRT/tree/main/litert/samples/image_segmentation/kotlin_cpu_gpu/android)\n- [Asynchronous segmentation with C++](https://github.com/google-ai-edge/LiteRT/tree/main/litert/samples/async_segmentation)\n\nQuickstart\n----------\n\nRunning inference with the LiteRT Next APIs involves the following key steps:\n\n1. Load a compatible model.\n2. Allocate the input and output tensor buffers.\n3. Invoke the compiled model.\n4. Read the inferences into an output buffer.\n\nThe following code snippets show a basic implementation of the entire process in\nKotlin and C++. \n\n### C++\n\n // Load model and initialize runtime\n LITERT_ASSIGN_OR_RETURN(auto model, Model::CreateFromFile(\"mymodel.tflite\"));\n LITERT_ASSIGN_OR_RETURN(auto env, Environment::Create({}));\n LITERT_ASSIGN_OR_RETURN(auto compiled_model,\n CompiledModel::Create(env, model, kLiteRtHwAcceleratorCpu));\n\n // Preallocate input/output buffers\n LITERT_ASSIGN_OR_RETURN(auto input_buffers, compiled_model.CreateInputBuffers());\n LITERT_ASSIGN_OR_RETURN(auto output_buffers, compiled_model.CreateOutputBuffers());\n\n // Fill the first input\n float input_values[] = { /* your data */ };\n input_buffers[0].Write\u003cfloat\u003e(absl::MakeConstSpan(input_values, /*size*/));\n\n // Invoke\n compiled_model.Run(input_buffers, output_buffers);\n\n // Read the output\n std::vector\u003cfloat\u003e data(output_data_size);\n output_buffers[0].Read\u003cfloat\u003e(absl::MakeSpan(data));\n\n### Kotlin\n\n // Load model and initialize runtime\n val model =\n CompiledModel.create(\n context.assets,\n \"mymodel.tflite\",\n CompiledModel.Options(Accelerator.CPU)\n )\n\n // Preallocate input/output buffers\n val inputBuffers = model.createInputBuffers()\n val outputBuffers = model.createOutputBuffers()\n\n // Fill the first input\n inputBuffers[0].writeFloat(FloatArray(data_size) { data_value /* your data */ })\n\n // Invoke\n model.run(inputBuffers, outputBuffers)\n\n // Read the output\n val outputFloatArray = outputBuffers[0].readFloat()\n\nFor more information, see the [Get Started with Kotlin](./android_kotlin) and\n[Get Started with C++](./android_cpp) guides.\n\nKey features\n------------\n\nLiteRT Next contains the following key benefits and features:\n\n- **New LiteRT API**: Streamline development with automated accelerator selection, true async execution, and efficient I/O buffer handling.\n- **Best-in-class GPU Performance**: Use state-of-the-art GPU acceleration for on-device ML. The new buffer interoperability enables zero-copy and minimizes latency across various GPU buffer types.\n- **Superior Generative AI inference**: Enable the simplest integration with the best performance for GenAI models.\n- **Unified NPU Acceleration** : Offer seamless access to NPUs from major chipset providers with a consistent developer experience. LiteRT NPU acceleration is available through an [Early Access\n Program](https://forms.gle/CoH4jpLwxiEYvDvF6).\n\nKey improvements\n----------------\n\nLiteRT Next (Compiled Model API) contains the following key improvements on\nLiteRT (TFLite Interpreter API). For a comprehensive guide to setting up your\napplication with LiteRT Next, see the [Get Started](./get_started) guide.\n\n- **Accelerator usage**: Running models on GPU with LiteRT requires explicit delegate creation, function calls, and graph modifications. With LiteRT Next, just specify the accelerator.\n- **Native hardware buffer interoperability**: LiteRT does not provide the option of buffers, and forces all data through CPU memory. With LiteRT Next, you can pass in Android Hardware Buffers (AHWB), OpenCL buffers, OpenGL buffers, or other specialized buffers.\n- **Async execution**: LiteRT Next comes with a redesigned async API, providing a true async mechanism based on sync fences. This enables faster overall execution times through the use of diverse hardware -- like CPUs, GPUs, CPUs, and NPUs -- for different tasks.\n- **Model loading**: LiteRT Next does not require a separate builder step when loading a model."]]