.onnx models into optimized
.sentis assets for faster performance.| Benefit | Description |
|---|---|
Offline Operation | Works fully offline — essential for exhibitions, enterprise, and privacy-sensitive apps. |
Ultra-Low Latency | All computation runs locally, removing network delays. |
Full Privacy | Sensitive inputs like passthrough images never leave the device. |
Deterministic Performance | Performance remains stable regardless of network or server load. |
UnityInferenceEngineProvider is the bridge between Unity and the on-device
inference runtime. It wraps your AI model asset (for example, .onnx or
.sentis) and provides configuration options for execution backend, frame
scheduling, and GPU-based post-processing.UnityInferenceEngineProvider supports three tasks:| Field | Description |
|---|---|
Use Streaming Asset | Load models as serialized asset from StreamingAssets folder. |
Model Asset | The trained model file ( .onnx or .sentis). |
Backend Type | |
Split Over Frames | Run a portion of the model per frame to maintain framerate. |
Layers Per Frame | Number of layers to execute each frame (used when Split Over Frames is true). |
NMS Compute Shader | Optional GPU Non-Max Suppression for bounding box filtering. |
Class Labels File | Optional .txt file mapping class indices to readable labels. |
LLM Config | Fill OnDeviceLlmConfig for chat mode with tokenizer settings (see On-Device SLM Chat below). |
.sentis format,
and optionally serialize or quantize them for deployment..sentis assets with just a few clicks. The following sections explain how
to use this tool and how to serialize or quantize models for deployment.| Type | Bits | Description |
|---|---|---|
None | 32 | Full precision (default) |
Float16 | 16 | Half precision, preserves most accuracy |
Uint8 | 8 | Highly compact, may slightly reduce accuracy |
using Unity.InferenceEngine;
using UnityEngine;
public class ModelConverter : MonoBehaviour
{
public void QuantizeAndSave(Model model, string path)
{
ModelQuantizer.QuantizeWeights(QuantizationType.Float16, ref model);
ModelWriter.Save(path, model);
}
}
.onnx model..sentis asset optimized for the Unity runtime..sentis file inside your StreamingAssets folder.using Unity.InferenceEngine; Model model = ModelLoader.Load(Application.streamingAssetsPath + "/mymodel.sentis");
using Unity.InferenceEngine;
using UnityEngine;
using System.Collections;
public class ModelWarmup : MonoBehaviour
{
[SerializeField] private ModelAsset modelAsset;
[SerializeField] private BackendType backendType = BackendType.CPU;
private void Start()
{
StartCoroutine(WarmUpModel());
}
private IEnumerator WarmUpModel()
{
var model = ModelLoader.Load(modelAsset);
var worker = new Worker(model, backendType);
var input = new Tensor<float>(new TensorShape(1, 3, 224, 224));
worker.Schedule(input);
yield return null;
worker.Dispose();
input.Dispose();
Debug.Log("Model warmed up and ready");
}
}
LlmAgent, ObjectDetectionAgent, and ImageSegmentationAgent warm up assigned on-device providers during initialization to reduce first-inference latency. The UnityInferenceEngineProvider includes a WarmUp() method you can call manually for other agents.NonMaxSuppression op, like YoloX, which
can cause performance bottlenecks. If you have ever tried to run Yolo on the CPU
backend, or GPU for that matter, you have likely experienced significant frame
drops. Furthermore, on the GPUCompute backend, you will notice that the detection results are not
filtered at all, which leads to the model outputting a large number of bounding boxes for the same object.GpuNMS.csNMSCompute.computeGPUCompute
backend. Object detection can require CPU/GPU synchronization while results are
filtered and converted into 3D bounding boxes. This bottleneck will be resolved
in a future release.UnityInferenceEngineProvider supports on-device text generation with
decoder-only transformer models..sentis format.UnityInferenceEngineProvider asset and set Mode to Chat.OnDeviceLlmConfig with:
{0} for the user message and {1} for the system messagemaxLayers, numKeyValueHeads, headDim,
and eosTokenId to the selected model.| Mode | Speed | Framerate Impact | Use Case |
|---|---|---|---|
Blocking | 1-5s | May freeze frames | Quick responses when occasional stutter is acceptable |
NonBlocking | 5-15s | Smooth | Real-time experiences requiring consistent framerate |
using System.Threading;
using System.Threading.Tasks;
using Meta.XR.BuildingBlocks.AIBlocks;
using UnityEngine;
public class ChatExample : MonoBehaviour
{
[SerializeField] private UnityInferenceEngineProvider provider;
async Task TestChat(CancellationToken cancellationToken = default)
{
try
{
var req = new ChatRequest("Hello, how are you?");
var response = await provider.ChatAsync(req, ct: cancellationToken);
Debug.Log(response.text);
}
catch (System.Exception ex)
{
Debug.LogError($"Chat failed: {ex.Message}");
}
}
}