agentleFS
flooooooooooowflooooooooooow/flow-skills/skills/flow-autodiff/SKILL.md

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.

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
  1. Distinctive:

    Write the forward function in ordinary Flow.

    line 39
  2. Distinctive:

    Never report a training run without a gradient check.

    line 48

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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
ModuleHolds
stdlib/autodiff.flowForward mode, dual numbers
stdlib/autodiff_reverse.flowReverse mode
stdlib/nn.flow, stdlib/ml_nn.flowLayers and network helpers
stdlib/ml_opt.flowOptimisers
stdlib/tensor.flowTensors, used by the MLIR path
stdlib/blas.flowWrapped 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

  1. Write the forward function in ordinary Flow.
  2. Get its gradient through the autodiff module, or through generated gradient code where the example does that.
  3. Drive an optimiser loop.
  4. 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.flow

The 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 sources

MLIR 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.