The Kiln logo: a flame in a kiln's arched door

kiln4j

Open generative models for the JVM

Call models as plain Java methods, on your GPU, inside your JVM.

NewKiln Studio: try the models without writing code

Early · Apache 2.0 · a Liberation Data project

Zero overhead

Native inference. No middleman.

Straight from the JVM to the GPU.

Kiln runs open-weight models for text, images and songs in-process, through Java’s Foreign Function & Memory API. A model is an object, a generation is a method call, and the weights stay on your GPU between calls. There is no Python, no model server, no HTTP, no JSON round trip and no second process.

Same engines

The native runners themselves

Kiln calls llama.cpp, stable-diffusion.cpp, acestep.cpp and yue2.cpp directly: the same C/C++ engines the CLIs and servers use, so you get their speed and their model support.

Vulkan today

On the GPU

Vulkan on AMD, Intel and NVIDIA. The same build script knows ROCm, CUDA and Metal, and your Java code doesn’t change when you switch.

One process

Nothing in between

A Kiln call is a native function call. Weights stay resident between calls, and tokens stream back to a Java callback as they are produced.

Plain Java

Models are objects. Generating is a method call.

Open a model in a try-with-resources block, call it as often as you like, and close it to give the memory back.

  • Every model class is AutoCloseable: weights are freed on close().
  • Text streams token by token to any callback, such as System.out::print.
  • Tool calling with chatJson: OpenAI-style messages and tools in, tool_calls out.
  • Audio comes back as PCM; images as a BufferedImage.
  • Java 22+, built and tested on 25. Instances aren’t thread-safe.
// The weights load onto the GPU once, and stay there until close()
try (var llm = new LlamaModel("Qwen3-4B-Instruct-2507-Q4_K_M.gguf")) {
    // Tokens stream to your callback as they are produced
    llm.chat(List.of(Message.user("Name a country song about a robot.")),
             Options.DEFAULT, System.out::print);
}

Kiln doesn’t download anything: HfCache finds weights in your Hugging Face cache, or pass file paths.

Engines and models

Four engines, one module each.

Each module binds one engine. Use one, or put several in the same JVM.

Text

kiln-llama

on llama.cpp

Any GGUF language model.

  • Qwen
  • Llama
  • Gemma
  • Mistral
  • …

Images

kiln-sd

on stable-diffusion.cpp

Diffusion models, including image editing.

  • FLUX.1
  • FLUX.2
  • Qwen-Image
  • Qwen-Image-Edit
  • SD 1.x/2.x/XL/3
  • Wan
  • LTX

Songs

kiln-acestep

on acestep.cpp

Songs with vocals and lyrics, up to several minutes long.

  • ACE-Step 1.5

Songs

kiln-yue2

on yue2.cpp

Songs, from the engine’s own JSON request.

  • YuE2

Check each model’s license before you use what it makes. Some are non-commercial: YuE2’s weights are CC BY-NC 4.0, for example.

Measured

What it does on one machine today.

Everything here ran from Java on Linux, on an AMD Radeon 8060S (Ryzen AI Max+ 395 “Strix Halo”, 128 GB unified memory) with the Vulkan backend.

Backends:

Vulkan testedROCm (HIP) untestedCUDA untestedMetal untested

The build script knows the ROCm, CUDA and Metal backends of the underlying engines, but those Kiln builds haven’t been tested yet. Reports and fixes welcome.

ModelResult
Qwen3 4B Instruct (Q4_K_M)~60 tokens/s
ACE-Step 1.5 XL turbo3 min 20 s song in 57 s
ACE-Step 1.5 turbo60 s song in ~15 s
YuE2 3B (Q8_0)60 s song in ~60 s
FLUX.2 [klein] base 4B (fp8)768×768, 12 steps in ~130 s
Qwen-Image 2512 (fp8)1024×1024, 20 steps in ~13 min
Qwen3’s tokens are streamed through a Java callback. One Strix Halo laptop, Vulkan.

Against ComfyUI

The same song job, side by side.

ACE-Step 1.5 turbo with its 4B LM, writing a 60 s song, on the same machine. Cold is the first run with nothing loaded, weights included. Warm is the second run with the weights resident (seed + 1, so ComfyUI doesn’t return its cached result).

Not quite like for like: ComfyUI ran the bf16 safetensors DiT, Kiln the GGUF Q8_0 weights. One run each, from kiln-bench.

Kiln Studio

Try the models without writing code.

Kiln Studio is a desktop app around Kiln: chat with a GGUF model and watch the tokens per second, watch it call tools, make an image or a song, and see what is loaded and how much memory it holds. It runs Kiln in a JVM of its own, with its own Java, and finds the models in your Hugging Face cache.

Kiln Studio in its dark theme with two windows on its desktop. Behind, the Chat window: Qwen3 4B Instruct answering a request for a haiku about a kiln and one sentence on what a kiln is for, at 68.7 tokens a second, with its time to the first token and token counts. In front, overlapping it, the Image window: FLUX.2 [klein] with its prompt, size and steps, and the image it made, a kiln's orange fire beside shelves of stoneware jars, generated in 2 minutes 17 seconds over 12 steps
Chat with Qwen3 4B Instruct at 68.7 tokens a second, and an image from FLUX.2 [klein].

Builds for macOS (Apple silicon and Intel, signed and notarized) and Linux are on their way with the first release.

How it works

One self-contained library per engine.

Each engine is built into a single shared library with its own ggml linked in statically and kept private. The engines pin different ggml versions, and this is what lets several of them share one process.

stable-diffusion.cpp

Has a key/value C API, so kiln-sd binds it directly.

llama.cpp

Its C API passes structs by value and is mid-migration to a new batch API, so kiln-llama binds a small, stable C layer instead.

acestep.cpp and yue2.cpp

C++ only, so each gets a C layer of about a hundred lines: a JSON request in, PCM audio out.

Tool calling

LlamaModel.chatJson takes messages and tools in OpenAI’s format and returns a message with content, reasoning_content and tool_calls. It uses the model’s own chat template and tool-call format, with the same templates and parsers as llama-server.

ModelPool

Keeps models resident between uses, the way ComfyUI does. It unloads idle models least recently used first to stay within a memory budget, can unload after an idle timeout, and gives each model one user at a time.

Pick a backend at build time

The Java is the same for every backend. native/build.sh builds the libraries for the one you name.

Long jobs on small power budgets

A long GPU dispatch can trip a laptop driver’s compute timeout, so ACE-Step audio is decoded in 512-frame tiles. Tune it with KILN_ACESTEP_VAE_CHUNK.

The engines’ own logs

Set KILN_VERBOSE=1 to see what llama.cpp, stable-diffusion.cpp and friends print.

Getting started

Build the engines, fetch some weights, run.

You need JDK 25, CMake, Ninja, a C++17 compiler and the SDK for your GPU backend. For Vulkan on Fedora:dnf install vulkan-headers vulkan-loader-devel glslc spirv-headers-devel.

1. Build

native/build.sh clones the engines at their pinned commits and writes the libraries to build/native/<os>-<arch>-<backend>/. Pick another backend for Gradle with -Pkiln.backend=hip.

native/build.sh vulkan     # or hip | cuda | metal | cpu; optionally list engines: llama sd acestep yue2
./gradlew build

2. Fetch weights

With the Hugging Face CLI. HfCache finds them in HF_HUB_CACHE, HF_HOME/hub or ~/.cache/huggingface/hub.

hf download unsloth/Qwen3-4B-Instruct-2507-GGUF Qwen3-4B-Instruct-2507-Q4_K_M.gguf
hf download Serveurperso/ACE-Step-1.5-GGUF acestep-5Hz-lm-4B-Q8_0.gguf Qwen3-Embedding-0.6B-Q8_0.gguf \
    acestep-v15-turbo-Q8_0.gguf vae-BF16.gguf
hf download black-forest-labs/FLUX.2-klein-base-4b-fp8 flux-2-klein-base-4b-fp8.safetensors
hf download Comfy-Org/flux2-dev split_files/vae/flux2-vae.safetensors
hf download Comfy-Org/z_image_turbo split_files/text_encoders/qwen_3_4b.safetensors

3. Try the examples

The song examples take the engines’ own JSON requests; pass your own as a second argument.

./gradlew single    # an LLM writes a song, ACE-Step sings it, FLUX.2 klein paints the cover
./gradlew chat --args='"Write a haiku about a kiln"'
./gradlew song --args='song.wav'                         # -Pdit=xl-turbo for the larger model
./gradlew yue2 --args='yue2-song.wav'
./gradlew image --args='klein out.png "a neon sign that says KILN"' -Psteps=12 -Pwidth=768 -Pheight=768

4. In your own app

Put the libraries on -Dkiln.library.path (or KILN_LIBRARY_PATH, or the platform loader path) and allow native access.

java -Dkiln.library.path=build/native/linux-x86_64-vulkan \
     --enable-native-access=ALL-UNNAMED -jar your-app.jar

Roadmap

Next in the kiln.

  • Test and document the HIP, CUDA and Metal builds; prebuilt native libraries per platform.
  • Video through stable-diffusion.cpp: Wan and LTX.
  • kiln-embabel: an Embabel Agent LlmService and LocalModelSource.
  • An optional OpenAI-compatible server.
  • Vision-language models through llama.cpp’s mtmd.
  • An MLX module for Apple silicon, through mlx-c.
  • Speech through whisper.cpp, and a Kotlin layer with coroutine Flow streaming.

Founded by Jasper Blues, creator of Typhoon. Sponsored by Rod Johnson, creator of the Spring Framework and of Embabel, the AI agent framework for the JVM.

Fire up your JVM.

Open models as Java objects, on your own GPU. Kiln is early: try it, and tell us what breaks.