• Stars
    star
    151
  • Rank 245,989 (Top 5 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Running ONNX models in vanilla Kotlin

KInference Icon KInference

JB Research

KInference is a library that makes it possible to execute complex ML models (written via ONNX) in Kotlin.

ONNX is a popular ecosystem for building, training, evaluating, and exchanging ML and DL models. It makes the process much simpler and divides the model into building blocks that can be switched or tuned to one's liking.

However, popular ML libraries, including those intended for the inference of ONNX models, carry with themselves a lot of dependencies and requirements that complicate their use in some cases. KInference is designed to facilitate the inference of ONNX models on a variety of platforms via configurable backends. Our library addresses not only the problem of server side inference, but also of local inference as well, and provides several solutions that are suitable for running both on user side and server side.

Right now, KInference is in active development.

Table of contents:

Why should I use KInference?

  • KInference is specifically optimized for inference. Most of the existing ML libraries are, in fact, versatile tools for model training and inference, but carry with themselves a lot of dependencies and requirements. KInference, on the other hand, addresses inference-only functionality to help facilitate model inference with a relatively small yet convenient API and inference-specific optimizations.

  • KInference has pure-JS and pure-JVM backends that make it possible to run models anywhere where JS or JVM virtual machine is available. In addition, you can switch between the chosen backends using backend configuration.

  • KInference supports configurable backends. KInference employs platform-specific optimizations and allows backend configuration essential for multiplatform projects. You can choose a backend for every module in the build.gradle.kts project file just by adding corresponding dependencies, while keeping most of your KInference-related code in a single common module.

  • KInference enables data preprocessing. We understand that data needs preprocessing before feeding it to the model and that is why we implemented numpy-like n-dimensional arrays. KInference can also work with custom array formats, with some of them being available out-of-the-box (see multik, kmath).

KInference backends

KInference Core

Pure Kotlin implementation that requires nothing but vanilla Kotlin. KInference Core is lightweight but fast, and supports numerous ONNX operators. It makes the library easy to use and especially convenient for various applications that require the models to run locally on users' machines. Note that this backend is well-optimized for JVM projects only, and, despite the fact that KInference Core is available for JavaScript projects, it is highly recommended to use KInference TensorFlow.js backend instead for more performance.

KInference Core dependency coordinates:

dependencies {
    api("io.kinference", "inference-core", "0.2.13")
}

TensorFlow.js

High-performance JavaScript backend that relies on the Tensorflow.js library. Essentially, it employs GPU operations provided by TensorFlow.js to boost the computations. In addition, this implementation enables model execution directly in the user's browser. This backend is recommended for JavaScript projects.

TensorFlow.js backend dependency coordinates:

dependencies {
    api("io.kinference", "inference-tfjs", "0.2.13")
}

ONNXRuntime CPU and ONNXRuntime GPU

Java backends that use ONNXRuntime as an inference engine and provide common KInference API to interact with the ONNXRuntime library.

Note that the GPU backend is CUDA-only. To check on the system requirements, visit the following link

ONNXRuntime CPU backend dependency coordinates:

dependencies {
    api("io.kinference", "inference-ort", "0.2.13")
}

ONNXRuntime GPU backend dependency coordinates:

dependencies {
    api("io.kinference", "inference-ort-gpu", "0.2.13")
}

Third-party math libraries adapters

KInference works with custom array formats, and some of them are available out-of-the-box. Basically, adapters enable working with familiar array formats and libraries. You can use several third-party Kotlin math libraries with KInference via our data adapters. In addition to the library adapters listed below, you can implement your own adapters using KInference adapters API.

KMath adapter

Array adapter for the kmath library that works with JVM KInference backends.

Dependency coordinates:

dependencies {
    api("io.kinference", "adapter-kmath-{backend_name}", "0.2.13")
}

Multik adapter

Array adapter for the multik library that works with JVM KInference backends.

Dependency coordinates:

dependencies {
    api("io.kinference", "adapter-multik-{backend_name}", "0.2.13")
}

Getting started

Let us now walk through how to get started with KInference. The latest version of KInference is 0.2.13

Setup dependencies repository

Firstly, you should add KInference repository in build.gradle.kts via:

repositories {
    maven {
        url = uri("https://packages.jetbrains.team/maven/p/ki/maven")
    }
}

Project setup

To enable the backend, you can add the chosen KInference runtime as a dependency:

dependencies {
    api("io.kinference", "inference-core", "0.2.13")
}

Multi-backend project setup

To configure individual KInference backend for each target, you should add corresponding backends to the dependencies.

kotlin {
    jvm {}

    js(IR) {
        browser()
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                api("io.kinference:inference-api:0.2.13")
                api("io.kinference:ndarray-api:0.2.13")
            }
        }

        val jvmMain by getting {
            dependencies {
                api("io.kinference:inference-core:0.2.13")
            }
        }

        val jsMain by getting {
            dependencies {
                api("io.kinference:inference-tfjs:0.2.13")
            }
        }
    }
}

Examples

You can find several KInference usage examples in this repository. The repository has examples of multi-backend project configuration and sharing KInference-related code between the modules.

Want to know more?

KInference API itself is widely documented, so you can explore its code and interfaces to get to know KInference better.

You may also submit feedback and ask questions in repository issues and issue discussions.

More Repositories

1

reflekt

A plugin for Kotlin compiler for compile-time reflection
Kotlin
362
star
2

astminer

A library for mining of path-based representations of code (and more)
Kotlin
280
star
3

viktor

Efficient f64-only ndarray in Kotlin
Kotlin
119
star
4

RefactorInsight

An IntelliJ IDEA plugin that detects refactorings in Git commits
Java
103
star
5

anti-copy-paster

A plugin for IntelliJ IDEA for extracting code duplicates into a new method as soon as they are introduced.
Java
101
star
6

code2seq

PyTorch's implementation of the code2seq model.
Python
61
star
7

snakecharm

Plugin for PyCharm / IntelliJ IDEA Platform IDEs which adds support for Snakemake language.
Python
58
star
8

commit_message_generation

🌟 replication package for 📜 From Commit Message Generation to History-Aware Commit Message Completion, ASE 2023
Python
56
star
9

psiminer

A Tool for Mining Rich Abstract Syntax Trees from Code
Kotlin
56
star
10

IntelliJDeodorant

The project is not actively supported.
Java
56
star
11

npy

NPY and NPZ support for the JVM
Kotlin
51
star
12

PyNose

A test smell detector for Python.
Kotlin
49
star
13

TestSpark

TestSpark - a plugin for generating unit tests. TestSpark natively integrates different AI-based test generation tools and techniques in the IDE. Started by SERG TU Delft. Currently under implementation by JetBrains Research (Software Testing Research) for research purposes.
Kotlin
47
star
14

sosed

Finding similar repositories on GitHub
Python
45
star
15

coqpilot

VSCode extension that is designed to help automate writing of Coq proofs.
TypeScript
44
star
16

pubtrends

Scientific literature explorer. Runs a Pubmed or Semantic Scholar search and allows user to explore high-level structure of result papers
Jupyter Notebook
35
star
17

bioinf-commons

Bioinformatics library in Kotlin
Kotlin
29
star
18

pubtrends-review

Automatic generation of reviews of scientific papers
Jupyter Notebook
28
star
19

buckwheat

A multi-language tokenizer for extracting identifiers from source code.
Jupyter Notebook
24
star
20

Lupa

A framework for the large scale analysis of programming language usage.
Jupyter Notebook
24
star
21

sorrel

Plugin for checking license compatibility in IntelliJ IDEA
Kotlin
22
star
22

embeddings-for-trees

Set of PyTorch modules for developing and evaluating different algorithms for embedding trees.
Python
22
star
23

lca-baselines

Baselines for all tasks from Long Code Arena benchmarks 🏟️
Python
22
star
24

authorship-detection

Evaluation of source authorship attribution tool
Python
21
star
25

paddle

Young and dynamic build system for Python
Kotlin
20
star
26

python-change-miner

A tool for mining graph-based change patterns in Python code
Python
19
star
27

IRen

Java
19
star
28

bumblebee

An IntelliJ-based IDE plugin for Python AST transformations
Kotlin
18
star
29

Matroskin

A library for the large scale analysis of Jupyter notebooks
Python
18
star
30

kotlinRMiner

Detects performed refactorings in the changes in Kotlin code
Java
16
star
31

tnm

Kotlin
14
star
32

cuBool

Sparse linear Boolean algebra for Nvidia Cuda
C++
14
star
33

adhd-study

Jupyter Notebook
13
star
34

big

BigWIG, BigBED and TDF for the JVM
Kotlin
12
star
35

spbla

Sparse Boolean linear algebra for Nvidia Cuda, OpenCL and CPU computations
C++
12
star
36

CFPQ_PyAlgo

The collection of Context-Free Path Querying algorithms
Python
10
star
37

jbr

JBR Genome Browser
Dockerfile
10
star
38

gorshochek

[WIP] A tool for C++ code modification to augment data for clone detection tools
C++
10
star
39

hldiff

Language-independent high-level differencing tool
Kotlin
10
star
40

CFPQ-on-GPGPU

Cuda
10
star
41

data-driven-type-migration

An IntelliJ IDEA plugin improving type migration refactoring using inferred type conversion rules
Java
9
star
42

task-tracker-plugin

Kotlin
8
star
43

revizor

A data-driven PyCharm plugin for code enhancement using graph patterns.
Kotlin
8
star
44

spla

An open-source generalized sparse linear algebra framework with vendor-agnostic GPUs accelerated computations
C++
8
star
45

kotlin-code-anomaly

Code anomaly detection in Kotlin compiler
Jupyter Notebook
7
star
46

span

SPAN Semi-supervised Peak Analyzer
Kotlin
7
star
47

batcore

Baselines and testing framework for code reviewer recommendation
Python
7
star
48

DeepBugsPlugin

Deep learning-based bug detector for IntelliJ
Kotlin
6
star
49

CoFRA

A CFL-r-based static analyser
C#
6
star
50

code-summarization-dataset

Kotlin
6
star
51

task-tracker-post-processing

Python
6
star
52

CFPQ_Data

Graphs and grammars for Context-Free Path Querying algorithms evaluation.
Python
6
star
53

code-completion-benchmark-toolkit

IntelliJ Code Completion Benchmarking Toolkit
Kotlin
6
star
54

JetNN

Python
6
star
55

bitcode-tools

Gradle tools to analyze bitcode of a Kotlin/Native project
Kotlin
5
star
56

litmuskt

Litmus testing tool for Kotlin/Native (WIP)
Kotlin
5
star
57

scasat-smk-pipeline

Single cell ATAC-Seq Snakemake pipeline
Python
5
star
58

ReSplit

An algorithm that re-splits Jupyter notebooks by merging and splitting their cells.
Jupyter Notebook
5
star
59

python-ml-type-hints

5
star
60

bus-factor-explorer

A web app for exploring Bus Factor of GitHub projects by analyzing the commit history.
Jupyter Notebook
5
star
61

code-quality-ij-server

Kotlin
5
star
62

planning-library

🌟 library with planning algorithms for AI Agents
Python
5
star
63

fine-tuning-ml-models

Python
5
star
64

kinference-primitives

Kotlin
5
star
65

sc-atacseq-explorer

Single cell ATAC-Seq preprocessing for single cell explorer
Jupyter Notebook
5
star
66

depminer

Kotlin
5
star
67

refactoring-workshop-demo

Kotlin
4
star
68

kinference-examples

Kotlin
4
star
69

louvain

Louvain method for community detection, implemented in Kotlin
Kotlin
4
star
70

topias

IntelliJ plugin for visualization of VCS changes statistics.
Java
4
star
71

docs-fine-tuning

Python
4
star
72

contrastive-learning-framework

Python
4
star
73

cncourse

Materials for Computational Neuroscience Course 2020
4
star
74

file-importance

ICTL + BILSEN project on using file importance in risk assessment
Python
4
star
75

overcoming

Jupyter Notebook
4
star
76

HumanEval-Dafny

Translating humaneval into dafny
Dafny
4
star
77

code-changes-clustering

Jupyter Notebook
4
star
78

similar-python-dependencies

Analyzing dependencies in Python projects and their dynamics
Python
4
star
79

tasktracker-3

Kotlin
3
star
80

bugs-classification

Java
3
star
81

KotlinMemoryModelResearch

3
star
82

nn-design-smells

Python
3
star
83

plugin-utilities

Repository for utilities to create and test IntelliJ plugins
Kotlin
3
star
84

MR-loader

Kotlin
3
star
85

chipseq-smk-pipeline

ChIP-Seq processing pipeline on snakemake
Python
3
star
86

lumberjack

Exploring automated BPE-like approaches to reduce the size of parse-trees
Kotlin
3
star
87

extract-method-experiments

Jupyter Notebook
3
star
88

FormalLanguageConstrainedReachability-LectureNotes

Материалы по достижимости с ограничениями в терминах формальных языков
TeX
3
star
89

ai-agents-code-editing

Exploring context retrieval strategies for code editing
Python
3
star
90

tag-prediction

2
star
91

effective-inference

2
star
92

mads

Multi-Agent Dynamic Simulation framework
Kotlin
2
star
93

metrics-evaluation

Evaluating metrics for code generation
Python
2
star
94

feature-recommendations

Python
2
star
95

spla-bench

Benchmark suite for performance analysis of sparse graphs frameworks
Python
2
star
96

formal-lang-course

Курс по формальным языкам: шаблон для домашних работ + материалы
Python
2
star
97

linktracker

Kotlin
2
star
98

kinference-compiler

Build ONNX models in compile-time
Kotlin
2
star
99

agents-eval

Jupyter Notebook
2
star
100

fishbone

Fishbone Ishikawa diagrams construction and visualising
JavaScript
2
star