
Nano-vLLM Java
A Java library that loads a model you already have and runs it on the CPU. The call stays in the JVM: no Python process, no CUDA, and no PyTorch. It does not train models.
It chats, calls your Java methods, embeds a sentence, transcribes and speaks, labels a language, reads a picture, and returns a choice with a probability. Families: Qwen3, Qwen3.5 text, Gemma 3, Gemma 4 text, Llama, LFM2, BERT, EmbeddingGemma, Whisper, Piper, fastText, and YOLO26. Each file type is under Supported models.
| Chat in the terminal |
Depth, surfaces, parked cars, people |
 |
 |
| It finds this computer's city and speaks the forecast |
Russian draughts. You play White. Jeff plays the other colour. |
 |
 |
One download, no Hugging Face gate, then the menu:
./models/download-qwen3-0.6b.sh
mvn -pl nano-vllm-java-samples -q exec:java
Attach com.igormaznitsa:nano-vllm-java:1.5.0 on JDK 21+. The calls start at Calls. Every other sample is under Samples. The design tour is description.md. Ideas here were inspired by the Python nano-vllm educational engine.
Contents
Calls
| You have |
You get |
Call |
| A question or a log snippet |
A text reply |
llm.chatOnce(…) or llm.chat().send(…).answer() |
| A sentence |
A vector |
generate(text, EMBEDDING) |
| A WAV clip |
A transcript |
generate(sound, TEXT) |
| A sentence |
A WAV file |
generate(text, AUDIO) |
| A sentence |
Ranked labels |
generate(text, LABELS) |
| A picture |
Boxes, a mask, pose, a map, depth, or image labels |
model.generate(image, IMAGE) |
| A state and a fixed list of options |
The chosen option and a probability for each |
jev.decide(…) |
| Notes on disk |
A reply that can quote those notes |
llm.rag(…).ask(…) |
| A question your Java function can answer |
A reply after that function runs |
builder.tool(…).build(), then chatOnce(…) |
One LLM runs one call at a time. Share the loaded LlmModel when calls should overlap. The rules are in Threads.
Supported models
LlmModelFactory.make(path) accepts a Hugging Face folder, a .gguf file, a YOLO26 *.onnx, or a fastText *.bin / *.ftz.
| Family |
Typical file |
Job |
| Qwen3, Gemma 3, Llama |
Safetensors folder, or ONNX weights in that folder |
Chat |
| Qwen3 |
Also a .gguf file |
Chat |
| Qwen3.5 text |
Safetensors folder, or a .gguf file (qwen35). The vision tower is skipped |
Chat, tools, and Jev |
| Gemma 4 text (QAT mobile) |
Safetensors only |
Chat and tools |
| LFM2 |
.gguf only |
Chat and tools |
| BERT (gte, E5, XLM-RoBERTa, …) |
.gguf or ONNX |
Embeddings |
| EmbeddingGemma |
Safetensors folder (2_Dense and 3_Dense included) |
Embeddings |
| Whisper |
Safetensors folder |
Speech to text |
| Piper |
*.onnx + *.onnx.json |
Text to speech |
| fastText |
*.bin or *.ftz |
Labels |
| YOLO26 (nano through extra-large) |
fused *.onnx, nms=False, 640 |
Detect, segment, pose, oriented boxes, semantic map, depth, or image labels |
If a folder has both safetensors and ONNX, safetensors is used. An unsupported file fails with UnsupportedModelException and the list of families this build knows.
Download scripts are in models/README.md. A first chat model with no Hugging Face gate is Qwen3-0.6B (./models/download-qwen3-0.6b.sh). Gemma3-270M is smaller and needs the model license accepted on Hugging Face first (./models/download-gemma3-270m.sh).
Add it
JDK 21+. Gemma3-270M and Qwen3-0.6B want a few gigabytes of heap. The in-repo demos expect about 16 GB.
Maven
<dependency>
<groupId>com.igormaznitsa</groupId>
<artifactId>nano-vllm-java</artifactId>
<version>1.5.0</version>
</dependency>
Gradle
implementation 'com.igormaznitsa:nano-vllm-java:1.5.0'
On the module path: requires com.igormaznitsa.nanollvm;.
Weights are not in the jar. Point LlmModelFactory at a downloaded folder (config.json, tokenizer, *.safetensors) or at a single .gguf file.
Chat
import com.igormaznitsa.nanollvm.llm.LLM;
import com.igormaznitsa.nanollvm.models.LlmModel;
import com.igormaznitsa.nanollvm.models.LlmModelFactory;
import java.nio.file.Path;
Path modelDir = Path.of("/opt/models/Gemma3-270M");
try (LlmModel model = LlmModelFactory.make(modelDir);
LLM llm = LLM.builder(model)
.noSystemPrompt() // Gemma chat path; Qwen can take .systemPrompt("…")
.build()) {
String reply = llm.chatOnce("""
Read the log and reply in three short bullets: what failed, likely cause, one next check.
Do not invent hosts or error codes that are not in the log.
2026-08-07 22:14:08 ERROR payment-api - give up order=99102 after 3 timeouts upstream=billing-svc:8443
""");
System.out.println(reply);
}
The same program is LogTriageHelloWorld (default folder models/Gemma3-270M):
mvn -pl nano-vllm-java-samples -q exec:java \
-Dexec.mainClass=com.igormaznitsa.nanollvm.samples.LogTriageHelloWorld
llm.chat() starts a transcript. llm.chat(session) continues one opened on that same engine. A session from another engine is rejected. session.filter(…) returns a ChatAdmission for each message: keep it in the transcript, send it to the model, both, or neither. Every filter must allow a destination. Stored messages are checked again on the next send.
Thinking is split with the checkpoint's own special tokens. A quoted <think>…</think> inside the scratchpad stays in thinking. The answer starts after the close that balances the opening tag.
Tools
A chat turn can call a Java function registered on the engine. The model writes the call in that checkpoint's own tool format. The engine runs the function, sends the returned text back, and continues the reply. chat and chatOnce do this. Raw generate does not.
Qwen3, Qwen3.5, LFM2, and Gemma 4 are accepted. Gemma 3 and Llama fail at build() when a tool is registered.
import com.igormaznitsa.nanollvm.llm.LLM;
import com.igormaznitsa.nanollvm.llm.ModelTool;
import com.igormaznitsa.nanollvm.models.LlmModel;
import com.igormaznitsa.nanollvm.models.LlmModelFactory;
import java.nio.file.Path;
ModelTool osName = ModelTool.of(
"os_name",
"Operating system name of this machine.",
"{\"type\":\"object\",\"properties\":{}}",
arguments -> System.getProperty("os.name"));
try (LlmModel model = LlmModelFactory.make(Path.of("/opt/models/Qwen3-0.6B"));
LLM llm = LLM.builder(model).tool(osName).build()) {
System.out.println(llm.chatOnce("What operating system is this? Call os_name."));
}
The function receives a JSON object ({} when the call has no arguments) and returns text. The third argument is a JSON Schema object. A name matches [A-Za-z_][A-Za-z0-9_]*. A space the model wrote inside the name is ignored, so os_ name still matches os_name. One user message runs at most maxToolExecutions calls (four when omitted). The function runs on the chat thread. A thrown exception goes back as error: … and the turn continues.
ToolsHelloWorld asks Qwen3-0.6B for the OS name, then for a directory listing, each in its own turn.
mvn -pl nano-vllm-java-samples -q exec:java \
-Dexec.mainClass=com.igormaznitsa.nanollvm.samples.ToolsHelloWorld
Jev
A decision is a typed question: a choice, a yes/no, or a score. The engine reads the next-token probability of a few labels (A / B, Yes / No, or 1 / 2) and returns the option with the highest probability, plus a probability for each option.
LLM.builder(model).toJev() is the call for every causal chat checkpoint, including Jeff-Qwen3.5-0.8B. There is no second API for Jeff's readout head. Embeddings, Whisper, Piper, fastText, and YOLO are refused. Jev.close() closes the engine and leaves the model open.
The default readout is L0: a choice is read once per option, a yes/no is read as both phrasings, and those probabilities are averaged. After eight states of the same question, a label prior from those states is applied. jevLevel(JevLevel.RAW) is one prefill in the order you passed.
import com.igormaznitsa.nanollvm.jev.Jev;
import com.igormaznitsa.nanollvm.jev.JevDecision;
import com.igormaznitsa.nanollvm.jev.JevQuestion;
import com.igormaznitsa.nanollvm.llm.LLM;
import com.igormaznitsa.nanollvm.models.LlmModel;
import com.igormaznitsa.nanollvm.models.LlmModelFactory;
import java.nio.file.Path;
import java.util.List;
try (LlmModel model = LlmModelFactory.make(Path.of("models/Gemma3-270M"));
Jev jev = LLM.builder(model).toJev()) {
JevDecision route = jev.decide(
"My card was charged twice for one order.",
JevQuestion.choice("Which team should handle this?",
List.of("billing", "technical", "sales", "other")));
System.out.println(route.answer() + " " + route.probability("billing"));
JevDecision refund = jev.decide(
"I want my money back for order 441.",
JevQuestion.yesNo("Does this message ask for a refund?"));
System.out.println(refund.answer());
JevDecision urgency = jev.decide(
"The payment page returns 500 and the customer cannot check out.",
JevQuestion.score("How urgent is the customer's request?",
List.of("low", "medium", "high")));
System.out.println(urgency.score().getAsDouble());
}
Jeff uses the same call. Russian checkers passes jevLevel(JevLevel.RAW) because a turn can have many legal moves:
import com.igormaznitsa.nanollvm.jev.JevLevel;
try (LlmModel model = LlmModelFactory.make(Path.of("models/Jeff-Qwen3.5-0.8B"));
Jev jev = LLM.builder(model).jevLevel(JevLevel.RAW).toJev()) {
JevDecision route = jev.decide(state, question);
}
Download Jeff with ./models/download-jeff-qwen3.5-0.8b.sh. JevHelloWorld prints a choice at L0 and at RAW, a yes/no, a score, then eight states until the prior turns on.
mvn -pl nano-vllm-java-samples -q exec:java \
-Dexec.mainClass=com.igormaznitsa.nanollvm.samples.JevHelloWorld
Images
A picture goes in as packed pixels. The file decides the job: objects, a mask, pose points, oriented boxes, a semantic map, depth, or image labels. Pictures are ArgbImage (row-major 0xAARRGGBB). The library has no java.desktop dependency. YoloStreetHelloWorld.fromBufferedImage copies a BufferedImage into that layout.

Depth tints the street from red (near) to green (far). Semantic paints each surface. Oriented boxes mark the parking lot. Detect writes the person scores on the crossing.
The same call loads yolo26n.onnx through yolo26x.onnx. The first convolution selects the scale: 16 channels is nano, 32 is small, 64 is medium or large, and 96 is extra-large. A second copy of the first block selects large when the stem is 64. The file is a fused export (nms=False, image size 640). P2, P6, YOLOE, and a .pt file are refused.
open(path) detects the kind. A renamed file such as lalala.onnx has nothing to detect, so pass open(path, LlmModelType.YOLO_DETECT).