Package smile.onnx.genai
package smile.onnx.genai
Idiomatic Java API for ONNX Runtime GenAI.
This package wraps the GenAI C API through Panama FFM bindings in
smile.onnx.genai.foreign. Handles implement AutoCloseable
and throw unchecked GenAIException on native errors.
Layers
- Core handles —
Config,Model,Tokenizer,Generator, … - Convenience —
SimpleGenAIfor prompt → stream → text. - Serve seam —
GenAiChatModelimplementsLanguageModel; smile-serve uses it as OGA fallback (allowlist + optional Olive) when Torch CUDA/builtin does not apply. - Allowlist / Olive target —
GenAISupportedModels,GenAI.resolveOliveTarget().
Quick start
try (var genai = SimpleGenAI.of("models/phi-3-mini-cpu")) {
try (var params = genai.createGeneratorParams()) {
params.setSearchOption("max_length", 256)
.setSearchOption("temperature", 0.8);
String reply = genai.generate(params, "Hello!", System.out::print);
}
}
Providers
Model.open(String) cascades CUDA → RyzenAI →
OpenVINO NPU → QNN → DirectML (Windows) → CPU when
SMILE_ONNX_GENAI_PROVIDER is auto (default). Each accelerator
requires matching EP natives.
Classical Vitis AI for general ONNX is
SessionOptions.appendVitisAiExecutionProvider().
Native libraries
Both onnxruntime and onnxruntime-genai must be on the OS
library search path. Use --enable-native-access=ALL-UNNAMED.
OgaEngine continuous batching is not wrapped yet; map it to
smile.llm.engine.ModelExecutor in a later phase.
-
ClassDescriptionContainer for LoRA adapters that can be activated on a
Generator.Loaded audios for multimodal GenAI models.GenAI model configuration: execution providers and overlay JSON.Process-wide ONNX Runtime GenAI controls: library availability, telemetry, logging helpers, and shutdown.LanguageModeladapter over ONNX Runtime GenAI.Unchecked exception thrown when an ONNX Runtime GenAI operation fails.Oliveoptimizetarget derived from the GenAI EP cascade.Allowlist of architectures supported by ONNX Runtime GenAI for chat.Chat-capable (and Whisper) families tracked for Olive / OGA conversion.Autoregressive token generator.Search and sampling options for aGenerator.Loaded images for multimodal GenAI models.An ONNX Runtime GenAI model.Converts text / images / audios intoNamedTensorsfor multimodal models.Named collection of tensors matching model input names.A collection of token-id sequences (batch of prompts / responses).Convenience façade for single-prompt text generation with an optional streaming callback.Thin GenAI tensor wrapper forGenerator.setModelInput(String, Tensor)/ multimodal inputs.Element types matchingOgaElementType.Converts between text and GenAI token ids, including chat templates.Incremental token → text decoder used while streaming generation.