Skip to content

sheaf-lang/sheaf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

506 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sheaf

Sheaf is a functional language for differentiable computation. Inspired by Clojure, it compiles to StableHLO and runs on CPU, Metal GPU, and CUDA via IREE.

Sheaf ships as a single native binary with zero runtime dependencies.

Note: This is Sheaf V2, a ground-up rewrite in Rust replacing the original Python/JAX implementation while keeping the language and syntax. The website will be updated as V2 stabilizes.

Goals

  • Clojure paradigm: homoiconicity, immutability, minimalist syntax
  • Native hardware performance: compiles to StableHLO, executes via IREE on CPU/GPU/TPU
  • JIT compilation: pure functions are automatically compiled and dispatched to the best available device
  • Symbolic autodiff: reverse-mode automatic differentiation on the AST, before compilation

Sample code

(defn transformer-block [x layer-p config]
  (as-> x h
    (-> h   ;; 1. Self-Attention
        (layer-norm (get layer-p :ln1) 2)
        (multi-head-attention layer-p config)
        (first)  ;; Attention output
        (+ h))   ;; Residual 1

    (-> h   ;; 2. MLP
        (layer-norm (get layer-p :ln2) 2)
        (mlp (get layer-p :mlp))
        (+ h)))) ;; Residual 2

Architecture

Sheaf source (.shf)
  --> Parser --> AST
  --> Type inference
  --> StableHLO codegen (MLIR)
  --> IREE compiler (VMFB)
  --> IREE runtime (CPU / Metal / CUDA)

The interpreter handles effectful operations (I/O, randomness) while pure numerical functions are JIT-compiled to IREE for hardware-accelerated execution.

Links

About

A functional language for differentiable programs

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages