A pure Java implementation of OpenAI's gpt-oss inference in ~1000 lines of code optimized for CPU execution.
Inspired by llama.cpp, llama2.c, this repo ports the gpt-oss PyTorch model.py to efficient Java code, emphasizing minimalism, simplicity, and educational purpose.
Key features
- Pure Java - No native dependencies, runs anywhere with Java 23+
- Complete gpt-oss architecture - Full implementation of MoE transformer with GQA, sliding window attention, RoPE, and SwiGLU
- CPU inference - No GPU required, designed for consumer-grade commodity hardware on local machines or cloud compute instances
- Memory efficient - Run on 16GB+ RAM using memory-mapped weights via Java Foreign Memory API
- MXFP4 dequantization - Handles original MXFP4 quantized MoE weights
- Performance optimized - Support KVCache and exploit modern JDK GC/JIT, parallel processing, SIMD Vector API, and fused operations
- Educational - Clean, readable code for understanding LLM Transformer internals
- Handy CLI - Interactive chat and single-shot generation modes