flow-autodiff
Skill1 starsChanged 3 months agoMITView on GitHub
Compute gradients and train models in Flow using the stdlib autodiff, optimisers, and neural network helpers. Use for derivatives, optimisation, curve fitting, gradient descent, backpropagation, or small neural networks.
In this repository13 other files it gives its agents.
- AGENTS.mdAGENTS.md
- flow-audioSkill
- flow-basicsSkill
- flow-compiler-devSkill
- flow-debugSkill
- flow-dynamicsSkill
- flow-effectsSkill
- flow-graphicsSkill
- flow-perfSkill
- flow-setupSkill
- flow-stdlibSkill
- flow-verifySkill
- flow-wasmSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 39
Write the forward function in ordinary Flow.
- Distinctive: line 48
Never report a training run without a gradient check.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Gradients and learning
Autodiff lives in the standard library rather than in a framework. Forward mode uses dual numbers; reverse mode has its own module.
Requires FLOW_HOST=python.
Find the current surface first
The module names are stable but the function names move. Check before writing:
ls lib/stdlib/ | grep -E "autodiff|nn|ml_|tensor"
grep -n "^function" lib/stdlib/autodiff.flow | head -40
grep -n "^function" lib/stdlib/autodiff_reverse.flow | head -40
grep -n "^function" lib/stdlib/ml_opt.flow | head -30| Module | Holds |
stdlib/autodiff.flow | Forward mode, dual numbers |
stdlib/autodiff_reverse.flow | Reverse mode |
stdlib/nn.flow, stdlib/ml_nn.flow | Layers and network helpers |
stdlib/ml_opt.flow | Optimisers |
stdlib/tensor.flow | Tensors, used by the MLIR path |
stdlib/blas.flow | Wrapped linear algebra |
lib/stdlib/nn_xor_loss_*.flow are checked-in generated gradient sources. They
show what code generation produces and are worth reading before hand-writing a
backward pass.
Shape of the work
- Write the forward function in ordinary Flow.
- Get its gradient through the autodiff module, or through generated gradient code where the example does that.
- Drive an optimiser loop.
- Assert that the loss actually fell, and that the gradient matches a finite difference.
The check that matters
Never report a training run without a gradient check. A wrong gradient still produces a loss curve that goes down sometimes.
# finite difference against the analytic gradient
let h: f64 = 1e-6
let numeric: f64 = (f(x + h) - f(x - h)) / (2.0 * h)
let analytic: f64 = grad_f(x)
if fabs(numeric - analytic) > 1e-4 {
println("FAIL: gradient mismatch")
return 1
}Then assert the training outcome, for example that XOR loss ends below a threshold, and return a distinct code otherwise.
Worked examples
ls examples/ml/
ls examples/ml/models/
FLOW_HOST=python flow run examples/ml/models/mlp_xor.flowThe ML demos are built to train on CPU in seconds. If something is running for minutes, the model or the step size is wrong, not the machine.
MLIR and GPU paths
flow ml run program.flow # MLIR-first ML workloads
flow ml bench program.flow
flow gpu program.flow # emit @gpu kernels as Metal sourcesMLIR needs LLVM installed via flow setup. Do not claim an MLIR or GPU result
you have not run. Report the backend in the command.
Reporting
State the loss before and after, the number of steps, the learning rate, the gradient check result, and the exact command. A number without a method behind it is not a result.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

