floretta 0.1.0

Automatic differentiation for WebAssembly.
Documentation

Reverse-mode automatic differentiation for WebAssembly.

The typical workflow is to create an empty config via [Autodiff::new], use [Autodiff::gradient] to specify one or more scalar-valued functions of which to take the gradient, and then use [Autodiff::transform] to process a Wasm module.

For example, if you have wat and Wasmtime installed:

use wasmtime::{Engine, Instance, Module, Store};

let input = wat::parse_str(r#"
(module
(func (export "square") (param f64) (result f64)
(f64.mul (local.get 0) (local.get 0))))
"#).unwrap();

let mut ad = floretta::Autodiff::new();
ad.gradient("square", "double");
let output = ad.transform(&input).unwrap();

let engine = Engine::default();
let mut store = Store::new(&engine, ());
let module = Module::new(&engine, &output).unwrap();
let instance = Instance::new(&mut store, &module, &[]).unwrap();
let double = instance.get_typed_func::<f64, f64>(&mut store, "double").unwrap();
let result = double.call(&mut store, 3.).unwrap();
assert_eq!(result, 6.);