#automatic-differentiation #name #wat #pass #export #floretta

app floretta-cli

Automatic differentiation for WebAssembly

4 releases (breaking)

0.4.0 Feb 20, 2025
0.3.0 Jan 21, 2025
0.2.0 Nov 22, 2024
0.1.0 Nov 19, 2024

#184 in WebAssembly

Download history 62/week @ 2024-11-13 227/week @ 2024-11-20 13/week @ 2024-11-27 3/week @ 2024-12-04 4/week @ 2024-12-11 50/week @ 2025-01-15 52/week @ 2025-01-22 10/week @ 2025-02-05 147/week @ 2025-02-19 12/week @ 2025-02-26

169 downloads per month

MIT license

93KB
2.5K SLoC

Rust 2K SLoC // 0.0% comments WebAssembly 318 SLoC

Floretta CLI

Floretta is an automatic differentiation tool for WebAssembly. This crate is the command line interface; for the Rust library, see the floretta crate.

To install:

cargo install --locked floretta-cli

Use the --help flag to see all available CLI arguments:

floretta --help

For example, if you create a file called square.wat with these contents:

(module
  (func (export "square") (param f64) (result f64)
    (f64.mul (local.get 0) (local.get 0))))

Then you can use Floretta to take the backward pass of the "square" function and name it "backprop":

floretta square.wat --export square backprop --output gradient.wasm

Finally, if you have a Wasm engine, you can use it to compute a gradient with the emitted Wasm binary by running the forward pass followed by the backward pass. For instance, if you have Node.js installed, you can create a file called gradient.mjs with these contents:

import fs from "node:fs/promises";
const wasm = await fs.readFile("gradient.wasm");
const module = await WebAssembly.instantiate(wasm);
const { square, backprop } = module.instance.exports;
console.log(square(3));
console.log(backprop(1));

And run it like this:

node gradient.mjs

Expected output:

9
6

Dependencies

~9–17MB
~226K SLoC