#cli #module #f64 #floretta #floretta-cli

app floretta-cli

Automatic differentiation for WebAssembly

5 releases (breaking)

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

#25 in #f64

Download history 101/week @ 2025-01-21 1/week @ 2025-01-28 10/week @ 2025-02-04 142/week @ 2025-02-18 14/week @ 2025-02-25 4/week @ 2025-03-04 1/week @ 2025-03-11

341 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
~225K SLoC