DiffKt is a general-purpose, functional, differentiable programming framework for Kotlin. It can automatically differentiate through functions of tensors, scalars, and user-defined types. It supports forward-mode and reverse-mode differentiation including Jacobian-vector and vector-Jacobian products, which can be composed for higher-order differentiation. It also supports differentiating against user-defined types using interfaces.
DiffKt also includes an early integration of ShapeTyping, an extensible compiler plugin for ahead-of-time tensor shape verification and inspection. With the ShapeTyping IntelliJ IDE plugin, users can even inspect tensor shapes and see tensor shape errors while in active development.
Currently there are two implementations that are supported for DiffKt. Follow the links below to install dependencies. It is recommended to use Homebrew as a package manager for macOS.
To use DiffKt, use the following dependency to your build.gradle.kts
file with the x.y.z
version number.
dependencies {
implementation("com.facebook.diffkt:x.y.z")
}
To use ShapeTyping, apply the plugin to your build.gradle.kts
file
plugins {
id("TODO")
...
}
And add the following dependencies
dependencies {
implementation("TODO")
implementation("TODO")
...
}
TODO: Instructions on downloading the IntelliJ
For more detailed instructions, please visit the ShapeTyping repository here. (TODO: link repository)
Currently DiffKt building is supported on macOS as well as Ubuntu. Help is needed to support building on Windows. Build instructions can be found below:
To build DiffKt from source files for UBUNTU, read INSTALL_UBUNTU.md
Navigate to the kotlin
folder from the repository root.
To run an example from the examples
folder, use the command ./gradlew :examples:run -Ppackage=<package-name>
. For instance, ./gradlew :examples:run -Ppackage=vector2
will run the vector2
example.
Navigate to the kotlin
folder from the repository root.
All tests should be run with the command ./gradlew test
To run specific tests, use the command ./gradlew :<subproject-name>:test --tests "<test-name>"
. For example, ./gradlew :api:test --tests "ReluTest"
.
Here are some tutorials to help you get started.
Intro to Differentiable Programming
Simple Parabola Gradient Descent
Linear Regression w/ Gradient Descent
Multivariable Linear Regression
Logistic Regression w/ Gradient Descent
Neural Network w/ Backpropagation
Linear Regression w/ User-Defined Types
Neural Network w/ User-Defined Types
We welcome and greatly value all kinds of contributions to DiffKt. If you would like to contribute, please see our Contributing Guidelines. Please refer to the contributing document or DiffKt.org for more details.
DiffKt is MIT licensed.