Skip to content

Feature/207 kllama gguf - #307

Merged
michalharakal merged 22 commits into
developfrom
feature/207-kllama-gguf
Jan 18, 2026
Merged

michalharakal merged 22 commits into
developfrom
feature/207-kllama-gguf

Conversation

@michalharakal

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-307 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

michalharakal and others added 18 commits January 18, 2026 15:20
Implements: #207

# Conflicts:
#	settings.gradle.kts
- Create GGUFTokenizer that extracts vocabulary from GGUF metadata
- Implement BPE encoding with greedy merge algorithm
- Handle byte fallback tokens (<0xXX> format) and SentencePiece markers
- Make tokenizer path optional for GGUF models in CLI
- Update JVM and Native CLI to use embedded tokenizer when available

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Configure shadowJar task to create kllama-all.jar with all dependencies
bundled. Run with: ./gradlew :skainet-apps:skainet-kllama:shadowJar

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove Format enum and format parameter from LlamaWeightLoader
- Remove loadFromKarpathyBin() and all Karpathy-specific helper methods
- Update loadLlamaRuntimeWeights functions to remove format parameter
- Simplify CLI to only support .gguf files with embedded tokenizer
- Fix Q8_1 dequantization bug (bytesPerBlock was 40, should be 36)
- Update tests to use GGUF format tensor shapes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Outlines the path to making KLlama the #1 choice for multiplatform
LLM inference, competing with jlama while offering unique KMP capabilities.

Key phases:
- Performance: mmap loading, quantized kernels, SIMD, KV-cache
- Developer Experience: Chat API, streaming Flow, templates, tools
- Model Support: Mistral, Phi, Gemma, Qwen, MoE architectures
- Platform Acceleration: Metal, WebGPU, NNAPI
- Distribution: Maven Central, CocoaPods, npm, documentation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Documents the core architecture for enabling:
- Zero-copy mmap loading across all platforms
- Pluggable compute backends (CPU, MLX, Metal, WebGPU, CUDA)
- Unified memory support on Apple Silicon
- Block-wise quantized inference without full dequantization

Key abstractions:
- TensorData: Heap, Mapped, Quantized implementations
- TensorStorage: Host vs Device memory management
- ComputeBackend: Platform-specific operation execution
- ImportHint: Zero-copy vs lazy vs device-copy strategies

This architecture enables running 70B models in 16GB RAM with GPU
acceleration and zero memory copies on Apple Silicon.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implement memory-mapped file support for loading GGUF models without
copying tensor data into heap memory. This enables efficient loading
of large models by leveraging OS-level lazy loading and page sharing.

New components:
- FloatBufferTensorData interface for buffer-backed tensor access
- MmapFloatTensorData implementation wrapping MappedByteBuffer
- MmapTensorSource factory for creating tensor views from mmap regions
- MmapLlamaLoader for zero-copy GGUF loading (F32 tensors)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Update competitive comparison table: Memory-mapped I/O now ✅ (JVM)
- Mark Phase 1.1 Memory-Mapped GGUF Loading as COMPLETED
- Update Key Gaps section to reflect mmap progress

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
BitNet uses ternary weights {-1, 0, +1} enabling matmul with
additions only (no FP multiply). This provides 5-10x speedup
potential and is a unique differentiator.

Phase 1 updated priorities:
- 1.1 Memory-mapped GGUF ✅ COMPLETED
- 1.2 BitNet/Ternary support 🆕 HIGH PRIORITY
- 1.3 Standard quantized kernels (Q4_K, Q8_0)
- 1.4 JVM Vector API integration
- 1.5 KV-Cache optimization

Existing BitNet foundation:
- Ternary DType already defined
- DenseTernaryTensorArray for 2-bit packed storage
- GGUF TQ1_0/TQ2_0 enum values present

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add dequantTQ1_0 and dequantTQ2_0 functions in LlamaWeightLoader
- Create TernaryTensorData interface and Ternary2BitTensorData implementation
- Implement addition-only TernaryMatmul kernel (no FP multiplies)
- Add comprehensive unit tests for dequantization and ternary ops
- Update quant_format.md with TQ documentation
- Mark BitNet support as implemented in roadmap

The ternary matmul enables efficient inference for BitNet-style models
where weights are constrained to {-1, 0, +1}, replacing multiplications
with conditional additions/subtractions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@michalharakal
michalharakal force-pushed the feature/207-kllama-gguf branch from c9891da to d74517e Compare January 18, 2026 14:21
@github-actions

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-307 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

- Add Q8_0TensorData and Q4_KTensorData for direct quantized matmul
- Add QuantizedMatmul with scalar kernels for Q8_0 and Q4_K formats
- Add JVM Vector API SIMD kernels (JvmQuantizedVectorKernels)
- Add OffheapKvCache using direct ByteBuffers for reduced GC pressure
- Add KvCache abstraction with platform-specific implementations
- Add QuantizedTensorFactory for raw bytes to quantized tensor conversion
- Integrate quantized dispatch into DefaultCpuOpsJvm
- Update LlamaRuntime to use KvCache interface

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-307 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

- Add LlamaRuntimeQuantizedTest with 13 tests covering:
  - Q8_0 and Q4_K matmul shape and accuracy
  - OffheapKvCache store/retrieve, key scores, weighted sums
  - LlamaRuntime integration with OffheapKvCache
  - HeapKvCache vs OffheapKvCache parity
- Fix OffheapKvCache to implement KvCache interface
- Add getKey/getValue methods with headOffset+elementIdx signature

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-307 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

- Update competitive comparison table (quantized inference, SIMD: ✅)
- Mark key gaps #1 and #2 as resolved
- Update sections 1.3, 1.4, 1.5 with implementation details
- Add Phase 1 Summary table
- Update Q1 timeline with completed items

Phase 1 "Performance Foundation" is now complete:
- Memory-mapped GGUF loading (JVM)
- BitNet/Ternary TQ1_0/TQ2_0 support
- Q8_0/Q4_K quantized inference kernels
- JVM Vector API SIMD kernels
- Off-heap KV cache with platform abstractions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-307 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

- Add memory profiling task (HeapKvCache vs OffheapKvCache)
- Add GC analysis task for long inference sessions
- Add end-to-end test task with real Q4_K model
- Add benchmark suite task for tok/s comparison
- Include profiling code template and expected results table

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@michalharakal
michalharakal merged commit 8e6fca7 into develop Jan 18, 2026
5 checks passed
@github-actions

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-307 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant