dfx is a tensor library with support for differentiable programming.
It is designed for use in machine learning, probabilistic programming, optimization and other domains.
dfx is the continuation of DiffSharp, carrying its work forward with deep respect for the ideas, care, and contributions that established its foundation.
We offer our sincere thanks to Dr. Atılım Güneş Baydin for creating and leading DiffSharp and for his foundational contributions to differentiable programming in F#.
dfx provides world-leading automatic differentiation capabilities for tensor code, including composable gradients, Hessians, Jacobians, directional derivatives, and matrix-free Hessian- and Jacobian-vector products over arbitrary user code. This goes beyond conventional tensor libraries such as PyTorch and TensorFlow, allowing the use of nested forward and reverse differentiation up to any level.
With dfx, you can compute higher-order derivatives efficiently and differentiate functions that are internally making use of differentiation and gradient-based optimization.
dfx comes with a LibTorch backend, using the same C++ and CUDA implementations for tensor computations that power PyTorch. On top of these raw tensors (LibTorch's ATen, excluding autograd), dfx implements its own computation graph and differentiation capabilities. It is tested on Linux, macOS, and Windows, and it supports CUDA and GPUs.
The dfx API is designed to be similar to the PyTorch Python API through very similar naming and idioms, and where elements have similar names the PyTorch documentation can generally be used as a guide.
dfx uses the incredible F# programming language for tensor programming. F# code is generally faster and more robust than equivalent Python code, while still being succinct and compact like Python, making it an ideal modern AI and machine learning implementation language. This allows fluent and productive code for tensor programming.
All documentation pages in this website are interactive notebooks which you can execute directly in your browser without installing anything in your local machine.
Using the buttons on the top of each page, you can execute the page as an interactive notebook running on cloud servers provided by Google Colab and Binder.
Using the buttons you can also download a page as a script or an interactive notebook, which you can execute locally in Jupyter or Visual Studio Code using dotnet interactive.
type dfx =
static member abs: input: Tensor -> Tensor
static member acos: input: Tensor -> Tensor
static member add: a: Tensor * b: Tensor -> Tensor
static member arange: endVal: float * ?startVal: float * ?step: float * ?device: Device * ?dtype: Dtype * ?backend: Backend -> Tensor + 1 overload
static member arangeLike: input: Tensor * endVal: float * ?startVal: float * ?step: float * ?device: Device * ?dtype: Dtype * ?backend: Backend -> Tensor + 1 overload
static member argmax: input: Tensor -> int array + 1 overload
static member argmin: input: Tensor -> int array + 1 overload
static member asin: input: Tensor -> Tensor
static member atan: input: Tensor -> Tensor
static member backends: unit -> Backend list
... <summary>
Tensor operations
</summary>
static member Dfx.dfx.config: unit -> Dfx.Device * Dfx.Dtype * Dfx.Backend * Dfx.Printer static member Dfx.dfx.config: configuration: (Dfx.Device * Dfx.Dtype * Dfx.Backend * Dfx.Printer) -> unit static member Dfx.dfx.config: ?device: Dfx.Device * ?dtype: Dfx.Dtype * ?backend: Dfx.Backend * ?printer: Dfx.Printer -> unit
Multiple items module Backend
from Dfx <summary>
Contains functions and settings related to backend specifications.
</summary>
-------------------- type Backend =
| Reference
| Torch
| Other of name: string * code: int
override ToString: unit -> string
member Name: string <summary>
Represents a backend for dfx tensors
</summary>
union case Dfx.Backend.Reference: Dfx.Backend <summary>
The reference backend
</summary>
type Tensor =
private | TensorC of primalRaw: RawTensor
| TensorF of primal: Tensor * derivative: Tensor * nestingTag: uint32
| TensorR of primal: Tensor * derivative: Tensor ref * parentOp: TensorOp * fanout: uint32 ref * nestingTag: uint32
interface IConvertible
interface IComparable
override Equals: other: obj -> bool
override GetHashCode: unit -> int
member GetSlice: bounds: int array2d -> Tensor
override ToString: unit -> string
member abs: unit -> Tensor
member acos: unit -> Tensor
member add: b: Tensor -> Tensor + 1 overload
member addSlice: location: int seq * b: Tensor -> Tensor
... <summary>
Represents a multi-dimensional data type containing elements of a single data type.
</summary> <example>
A tensor can be constructed from a list or sequence using <see cref="M:Dfx.dfx.tensor(System.Object)" /><code>
let t = dfx.tensor([[1.; -1.]; [1.; -1.]])
</code></example>
Multiple items type Conv2d =
inherit Model
new: inChannels: int * outChannels: int * ?kernelSize: int * ?stride: int * ?padding: int * ?dilation: int * ?kernelSizes: int seq * ?strides: int seq * ?paddings: int seq * ?dilations: int seq * ?bias: bool -> Conv2d
override ToString: unit -> string
override forward: value: Tensor -> Tensor
member bias: Tensor with get, set
member weight: Tensor with get, set <summary>A model that applies a 2D convolution over an input signal composed of several input planes</summary>
-------------------- new: inChannels: int * outChannels: int * ?kernelSize: int * ?stride: int * ?padding: int * ?dilation: int * ?kernelSizes: int seq * ?strides: int seq * ?paddings: int seq * ?dilations: int seq * ?bias: bool -> Conv2d
static member dfx.relu: input: Tensor -> Tensor
static member dfx.flatten: startDim: int * ?endDim: int -> (Tensor -> Tensor) static member dfx.flatten: input: Tensor * ?startDim: int * ?endDim: int -> Tensor
val decoder: Model<Tensor,Tensor>
static member dfx.unflatten: dim: int * unflattenedShape: int seq -> (Tensor -> Tensor) static member dfx.unflatten: input: Tensor * dim: int * unflattenedShape: int seq -> Tensor
Multiple items type ConvTranspose2d =
inherit Model
new: inChannels: int * outChannels: int * ?kernelSize: int * ?stride: int * ?padding: int * ?dilation: int * ?kernelSizes: int seq * ?strides: int seq * ?paddings: int seq * ?dilations: int seq * ?bias: bool -> ConvTranspose2d
override ToString: unit -> string
override forward: value: Tensor -> Tensor
member bias: Tensor with get, set
member weight: Tensor with get, set <summary>A model that applies a 2D transposed convolution operator over an input image composed of several input planes.</summary>
-------------------- new: inChannels: int * outChannels: int * ?kernelSize: int * ?stride: int * ?padding: int * ?dilation: int * ?kernelSizes: int seq * ?strides: int seq * ?paddings: int seq * ?dilations: int seq * ?bias: bool -> ConvTranspose2d
static member dfx.sigmoid: input: Tensor -> Tensor
val model: VAE
Multiple items type VAE =
inherit VAEBase
new: xShape: int seq * zDim: int * encoder: Model * decoder: Model -> VAE
override ToString: unit -> string
override decode: z: Tensor -> Tensor
override encode: x: Tensor -> Tensor * Tensor <summary>Variational auto-encoder</summary>
-------------------- new: xShape: int seq * zDim: int * encoder: Model * decoder: Model -> VAE