Skip to content

Tutorials

[[toc]]

These walkthroughs mirror the scripts in examples/. Each one demonstrates a single concept and can be executed without extra scaffolding.

  • :material-function-variant: Attention block
    Self-attention expressed in Fuse with projection helpers.
    python examples/01_attention_block.py
    
  • :material-transit-connection: Routing MLP
    Shows conditional execution across experts.
    python -m fuse run examples/04_mlp.fuse --backend numpy
    
  • :material-account-tree: Tree programs
    Compose hierarchical programs via tree_program.
    python examples/08_tree_program.py
    
  • :material-alpha-d-box: Custom operators
    Extend the DSL by injecting Python callables at runtime.
    python examples/11_custom_operator.py
    

Need optional backends?

Install fuse[torch] or fuse[jax] to enable the Torch FX and JAX runners. Examples automatically fall back to NumPy when a backend is unavailable.

Run a single tutorial

The CLI exposes the same ergonomics as the Python API. Use --backend to switch engines.

python -m fuse run examples/05_transformer_block.fuse --backend numpy

Add --explain to emit execution traces:

python -m fuse run examples/05_transformer_block.fuse --backend numpy --explain runs/transformer_trace.json

Batch execution helper

The gallery includes a batch runner that executes multiple programs and collects metrics.

python examples/run_new_architectures.py --backend numpy --out runs/gallery.jsonl

Tip

Pass --backend torch or --backend jax once you have the extras installed. Failed runs raise immediately so CI can catch regressions.

Explore the code

Each tutorial script highlights a distinct capability:

Script Highlights
01_attention_block.py Attention kernel expressed in the DSL with gradients and explainers.
03_runtime_policies.py Demonstrates manifest-backed weights and caching policies.
05_transformer_block.fuse Raw DSL program executed through the CLI.
08_tree_program.py Builds a tree of programs for recursive inference.
11_custom_operator.py Registers a custom Python callable and wires it into the graph.

Browse the examples directory for the full list.