You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sheaf brings Clojure’s code-as-data to machine learning, with models as inspectable, composable, and compiled data structures.
18
+
19
+
</p>
16
20
17
21
</div>
18
22
@@ -22,9 +26,9 @@ hide:
22
26
23
27
## For ML Researchers
24
28
25
-
-**Single binary framework** — Models train and run on GPU with no environment to configure
26
-
-**Functional parameters** — Models are data structures that can be inspected, transformed, and composed
27
-
-**Runtime Observability** — Guards and traces expose tensor stability and failure modes
29
+
-**No classes, no boilerplate** — Write math, not plumbing
30
+
-**Runtime Observability** — Catch NaN, trace shapes and profile performance without code changes
31
+
-**Single binary framework** — One executable, no dependencies. Train and run on GPU out of the box
28
32
29
33
</div>
30
34
@@ -45,11 +49,9 @@ hide:
45
49
<divclass="flex-section"markdown="1">
46
50
<divmarkdown="1">
47
51
48
-
Neural networks in Sheaf are written as mathematical transformations.
52
+
In Sheaf, a neural network is a composition of mathematical functions over a parameter tree.
49
53
50
-
Layers, activations, and parameter bindings form explicit data flow, without imperative state management.
51
-
52
-
Because the language is functionally pure, compilation and differentiation require no decorators or annotations. `value-and-grad` differentiates any pure function; the JIT resolves shapes and compiles to GPU code automatically.
54
+
Sheaf is purely functional, so differentiation and compilation require no annotations. Any pure function can be differentiated with value-and-grad and is automatically compiled to GPU code.
53
55
54
56
</div>
55
57
<divmarkdown="1">
@@ -98,26 +100,23 @@ Because the language is functionally pure, compilation and differentiation requi
98
100
<divclass="flex-section"markdown="1">
99
101
<divmarkdown="1">
100
102
101
-
In Sheaf, model parameters are nested dictionaries.
102
-
103
-
There are no module classes, or registration, or parameter groups. Structural operations like pruning, freezing, or weight sharing are expressed as regular data transformations.
103
+
Because models are data, Sheaf requires no module classes, registration, or parameter groups. Even structural operations like pruning, freezing, or weight sharing are expressed as regular data transformations.
104
104
105
-
Compile-time macros generate architecture variants from a single template. The same primitives extend to neuro-symbolic pipelines where logic and learning are jointly differentiable.
105
+
Sheaf brings compile-time macros to the computation graph itself, generating architecture variants from a single template.
106
106
107
107
</div>
108
108
109
109
<divmarkdown="1">
110
110
111
111
```clojure
112
-
;; Freeze a layer: zero out its gradients
113
-
(defnfreeze [grad layer-key]
114
-
(assoc grad layer-key
115
-
(tree-map (fn [g] (zeros (shape g)))
116
-
(get grad layer-key))))
112
+
;; Grow a model: add a layer at runtime
113
+
(defnappend-layer [params new-layer]
114
+
(assoc params :layers
115
+
(append (get params :layers) new-layer)))
117
116
118
-
;; Apply weight decay to all parameters at once
119
-
(defnweight-decay [params rate]
120
-
(tree-map (fn [w] (* w (-1.0 rate))) params))
117
+
;; Swap the output head for a different task
118
+
(defnhot-swap-head [model task-id heads]
119
+
(assoc model :head (get heads task-id)))
121
120
122
121
```
123
122
@@ -129,9 +128,9 @@ Compile-time macros generate architecture variants from a single template. The s
129
128
<divclass="flex-section"markdown="1">
130
129
<divmarkdown="1">
131
130
132
-
Every function call, tensor shape, and numerical statistic is observable at runtime.
131
+
In Sheaf, every function call, tensor shape, and numerical statistic is observable at runtime.
133
132
134
-
Three modes expose different aspects of execution: a tracer reconstructs the full call hierarchy with tensor statistics, guards halt on numerical invariants like NaN or range violations, and a profiler attributes wall time to each function in the call tree.
133
+
A tracer logs the full call hierarchy with tensor statistics. Guards halt execution on numerical invariants like NaN or range violations. A profiler attributes wall time to each function in the call tree.
135
134
136
135
</div>
137
136
@@ -147,9 +146,7 @@ Three modes expose different aspects of execution: a tracer reconstructs the ful
@@ -191,11 +188,11 @@ Three modes expose different aspects of execution: a tracer reconstructs the ful
191
188
192
189
Call tree:
193
190
194
-
├── generate (5.58s, 1 call)
195
-
│ ├── reduce (5.58s, 1 call)
196
-
│ │ └── <lambda> (5.58s, 101 calls)
197
-
│ │ ├── generate-token (5.56s, 100 calls)
198
-
│ │ │ ├── gpt-forward (3.72s, 100 calls)
191
+
├── generate (3.58s, 1 call)
192
+
│ ├── reduce (3.58s, 1 call)
193
+
│ │ └── <lambda> (3.58s, 101 calls)
194
+
│ │ ├── generate-token (3.56s, 100 calls)
195
+
│ │ │ ├── gpt-forward (1.72s, 100 calls)
199
196
│ │ │ ├── reshape (900.16ms, 100 calls)
200
197
│ │ │ ├── choice (622.85ms, 100 calls)
201
198
│ │ │ ├── softmax (158.67ms, 100 calls)
@@ -213,7 +210,7 @@ Three modes expose different aspects of execution: a tracer reconstructs the ful
213
210
<divclass="flex-section">
214
211
<divmarkdown="1">
215
212
216
-
A complete GPT-2 124M implementation in Sheaf is 1,908 tokens, while the equivalent PyTorch is 7,486. Sheaf's uniform syntax keeps the code concise and close to the math.
213
+
A complete GPT-2 124M implementation in Sheaf is 1,908 tokens, while the equivalent PyTorch is 7,486. Sheaf's uniform syntax keeps the code concise and unambiguous.
217
214
<br/><br/>
218
215
219
216
Context usage counts GPT-4 tokens (tiktoken) across model, training, and sampling code. Deploy size is the minimal runtime required to train and run a model on a CUDA GPU.
@@ -260,29 +257,21 @@ Context usage counts GPT-4 tokens (tiktoken) across model, training, and samplin
260
257
Sheaf is written in Rust. The complete runtime with GPU backends ships
261
258
as a single 4 MB executable.
262
259
263
-
Sheaf code is JIT-compiled to optimized GPU kernels for CUDA and Metal through StableHLO and IREE.
264
-
265
260
The compiler toolchain is downloaded on first use and is not required to run a compiled model.
266
261
267
262
</div>
268
263
269
264
<divmarkdown="1">
270
265
271
266
```
272
-
$ du -h * # Standalone, self-contained deployment
267
+
# Standalone, self-contained deployment
268
+
$ du -h *
273
269
128K __sheaf__ # compiled model
274
270
3.2M data
275
271
4.0K model.shf
276
-
164M out-shakespeare-char
277
-
3.6M sheaf # runtime
272
+
164M out-weights
273
+
3.8M sheaf # runtime
278
274
4.0K train.shf
279
-
280
-
$ ./sheaf train.shf
281
-
Loading model...
282
-
Loaded: 6 layers, 384 dim, 65 vocab
283
-
Training data: 1115394 tokens
284
-
Training for 100 steps (batch_size=4 block_size=256)...
@@ -129,13 +129,7 @@ Subsequent calls with the same argument shapes dispatch directly to the cached V
129
129
130
130
### Backend Selection
131
131
132
-
Sheaf selects the compilation backend based on available hardware:
133
-
134
-
| Platform | Primary Backend | Fallback |
135
-
| -------- | --------------- | ----------- |
136
-
| Linux | CUDA | Vulkan, CPU |
137
-
| macOS | Metal | CPU |
138
-
| Other | CPU | - |
132
+
Sheaf probes available hardware in preference order: CUDA, Metal, Vulkan, CPU. The first available backend is used.
139
133
140
134
You can override this with the `--device` flag:
141
135
@@ -246,5 +240,5 @@ Each argument position holds up to 8 cached buffers with most-recently-used orde
246
240
247
241
-**Shape specialization.** Functions are compiled for the tensor shapes seen at the first call. A different shape (e.g., a different batch size) triggers automatic recompilation and caching. This is the same tracing model as `jax.jit`.
248
242
-**Control flow.**`if` expressions inside compiled functions cause fallback to the interpreter. Conditional logic must live outside the hot path, or use `where`, which compiles to `stablehlo.select`.
249
-
-**Metal backend.** IREE's Metal/SPIR-V backend is less optimized than CUDA. Some operations are slower on Apple GPUs than on equivalent NVIDIA hardware.
243
+
-**Backend maturity.** IREEbackend performance varies by hardware. Benchmarks on your target device are recommended.
250
244
-**Memory management.** No automatic model sharding or gradient checkpointing. Large models may exceed device memory.
Copy file name to clipboardExpand all lines: docs/roadmap.md
+36-10Lines changed: 36 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,26 +5,52 @@ hide:
5
5
6
6
# Roadmap
7
7
8
-
## Version 2.1 (planned features)
8
+
These are the planned features for the next releases of Sheaf.
9
9
10
-
### Performance
10
+
### Language
11
11
12
-
-**KV cache**: Sheaf 2.0 currently doesn't have a KV cache, which is essential for competitive inference at scale. Without it, each generated token recomputes full O(n^2) attention over the entire context. With it, each step costs O(n) after the first pass.
12
+
-**`def` for global constants**: Immutable top-level bindings, as in Clojure. While not required per-se, it eliminates the need to pass configuration dictionaries everywhere.
13
13
14
-
-**Batch generation mode**: Currently, autoregressive generation calls the compiled model once per token. Batch mode would compile the full generation loop into a single dispatch, returning all tokens at once.
14
+
-**`loop` / `recur`**: Explicit tail-recursive loops. Sheaf uses `repeat`, but `loop` and `recur` are more natural for someone coming from Clojure.
15
15
16
-
### Distribution
16
+
-**`reverse` / `flip`**: Reverse a tensor along an axis. Currently requires manual index construction.
17
17
18
-
-**NCCL all-reduce**: Multi-GPU training via NCCL collective operations, for data-parallel training across multiple devices.
18
+
-**`stack`**: Combine multiple tensors into a new dimension.
19
19
20
-
### Developer experience
20
+
-**`inc` / `dec`**: Small convenience to increment and decrement, as in Clojure. Currently `(+ var 1)` and `(- var 1)`.
21
21
22
-
-**Jupyter integration**: A Sheaf kernel for Jupyter, allowing interactive notebook workflows with inline tensor visualization and training loops.
22
+
-**`argmax` returns integers**: `argmax` and `argmin` currently return floats. They will return integer tensors for direct use as indices.
23
23
24
-
-**`:trace` and `:blame` in the REPL**: These observability modes were tied to V1 semantics and temporarily removed. They will be re-introduced with behavior adapted to the V2 execution model.
24
+
### Macros
25
+
26
+
-**Enriched `defmacro`**: `range` and `reduce` available at compile time, enabling macros that generate architecture variants from a single template.
25
27
26
28
### Operations
27
29
28
30
-**Convolution primitives**: `conv1d` and `conv2d` via `stablehlo.convolution`, exposed through the standard library.
29
31
30
-
-**`vmap` on dictionaries**: `vmap` currently only accepts tensor arguments. PyTree support (automatic flattening/unflattening of dicts) will be added to match the behavior of `value-and-grad`.
32
+
-**`vmap` on dictionaries**: `vmap` currently only accepts tensor arguments. PyTree support (automatic flattening/unflattening of dicts) should be added to match the behavior of `value-and-grad`.
33
+
34
+
### Autodiff
35
+
36
+
-**Gradient checkpointing**: Recompute forward activations during the backward pass instead of storing them all. This will reduce memory usage for deep models (the GPT-2 124M training currently uses 13 GB).
37
+
38
+
-**Scalar parameters in `value-and-grad`**: Float scalars in parameter dictionaries (e.g., `{:w 5.0}`) will produce correct gradients. Currently requires wrapping in a 1-element tensor.
39
+
40
+
### Performance
41
+
42
+
-**KV cache helpers**: A `cached-attention` stdlib function to simplify implementing KV cache in transformer models.
43
+
44
+
-**Batch generation mode**: Compile the full autoregressive generation loop into a single dispatch, returning all tokens at once.
45
+
46
+
### Developer experience
47
+
48
+
-**Error call stack propagation**: When an error occurs inside a stdlib function, the error message will show the user's call site, not the stdlib internals.
49
+
50
+
-**Jupyter integration**: A Sheaf kernel for Jupyter, allowing interactive notebook workflows with inline tensor visualization and training loops.
51
+
52
+
-**`:trace` and `:blame` in the REPL**: These observability modes were tied to V1 semantics and temporarily removed. They will be re-introduced with behavior adapted to the V2 execution model.
53
+
54
+
### Distribution
55
+
56
+
-**NCCL all-reduce**: Multi-GPU training via NCCL collective operations, for data-parallel training across multiple devices.
0 commit comments