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
169 downloads per month
93KB
2.5K
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