Skip to content

Commit f4c7950

Browse files
committed
[Docs] Update website for V2
1 parent 328540f commit f4c7950

3 files changed

Lines changed: 74 additions & 65 deletions

File tree

docs/index.md

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ hide:
1010
<h1 style="margin: 0; font-size: 4.5rem; font-weight: 500; color: black;">Sheaf</h1>
1111
</div>
1212

13-
<h2>A Functional Language for Differentiable Computation</h2>
13+
<h2 style="max-width: 36rem; margin-left: auto; margin-right: auto; margin-top: 1rem;">A functional language for differentiable computation</h2>
1414

15-
<p>Inspired by Clojure. Designed from the ground up for machine learning. Compiles to native GPU code.</p>
15+
<p style="text-align: center; size: 1rem; max-width: 40rem; margin-left: auto; margin-right: auto; margin-top: 1rem;" markdown="1">
16+
17+
Sheaf brings Clojure’s code-as-data to machine learning, with models as inspectable, composable, and compiled data structures.
18+
19+
</p>
1620

1721
</div>
1822

@@ -22,9 +26,9 @@ hide:
2226

2327
## For ML Researchers
2428

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
2832

2933
</div>
3034

@@ -45,11 +49,9 @@ hide:
4549
<div class="flex-section" markdown="1">
4650
<div markdown="1">
4751

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

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

5456
</div>
5557
<div markdown="1">
@@ -98,26 +100,23 @@ Because the language is functionally pure, compilation and differentiation requi
98100
<div class="flex-section" markdown="1">
99101
<div markdown="1">
100102

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

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

107107
</div>
108108

109109
<div markdown="1">
110110

111111
```clojure
112-
;; Freeze a layer: zero out its gradients
113-
(defn freeze [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+
(defn append-layer [params new-layer]
114+
(assoc params :layers
115+
(append (get params :layers) new-layer)))
117116

118-
;; Apply weight decay to all parameters at once
119-
(defn weight-decay [params rate]
120-
(tree-map (fn [w] (* w (- 1.0 rate))) params))
117+
;; Swap the output head for a different task
118+
(defn hot-swap-head [model task-id heads]
119+
(assoc model :head (get heads task-id)))
121120

122121
```
123122

@@ -129,9 +128,9 @@ Compile-time macros generate architecture variants from a single template. The s
129128
<div class="flex-section" markdown="1">
130129
<div markdown="1">
131130

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

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

136135
</div>
137136

@@ -147,9 +146,7 @@ Three modes expose different aspects of execution: a tracer reconstructs the ful
147146
│ │ ├─ [sigmoid] f32[4x1] [min:-5.48e-2 max:1.18e0] (16B)
148147
│ │ └─ ← f32[4x1] [min:4.86e-1 max:7.66e-1] (16B) (1.8μs)
149148
│ └─ ← f32[4x1] [min:4.86e-1 max:7.66e-1] (16B) (0.0μs)
150-
│ ├─ [sgd-step] dict(keys:["l1", "l2"]), dict(keys:["l1", "l2"]), 0.700000
151-
│ └─ ← dict(keys:["l1", "l2"]) (8.9μs)
152-
└─ ← dict(keys:["loss", "p"]) (0.0μs)
149+
...
153150
```
154151

155152
=== "Guards"
@@ -176,11 +173,11 @@ Three modes expose different aspects of execution: a tracer reconstructs the ful
176173
=== "Profiler"
177174

178175
```css
179-
Profiler: 5.63s wall
176+
Profiler: 3.63s wall
180177

181178
Function Calls Total Self Avg/call
182179
------------------------------------------------------------------------
183-
gpt-forward 100 3.72s 3.72s 37.23ms
180+
gpt-forward 100 1.72s 3.72s 37.23ms
184181
reshape 301 900.57ms 900.57ms 2.99ms
185182
choice 100 622.85ms 622.85ms 6.23ms
186183
softmax 100 158.67ms 158.67ms 1.59ms
@@ -191,11 +188,11 @@ Three modes expose different aspects of execution: a tracer reconstructs the ful
191188

192189
Call tree:
193190

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)
199196
│ │ │ ├── reshape (900.16ms, 100 calls)
200197
│ │ │ ├── choice (622.85ms, 100 calls)
201198
│ │ │ ├── softmax (158.67ms, 100 calls)
@@ -213,7 +210,7 @@ Three modes expose different aspects of execution: a tracer reconstructs the ful
213210
<div class="flex-section">
214211
<div markdown="1">
215212

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.
217214
<br/><br/>
218215

219216
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
260257
Sheaf is written in Rust. The complete runtime with GPU backends ships
261258
as a single 4 MB executable.
262259

263-
Sheaf code is JIT-compiled to optimized GPU kernels for CUDA and Metal through StableHLO and IREE.
264-
265260
The compiler toolchain is downloaded on first use and is not required to run a compiled model.
266261

267262
</div>
268263

269264
<div markdown="1">
270265

271266
```
272-
$ du -h * # Standalone, self-contained deployment
267+
# Standalone, self-contained deployment
268+
$ du -h *
273269
128K __sheaf__ # compiled model
274270
3.2M data
275271
4.0K model.shf
276-
164M out-shakespeare-char
277-
3.6M sheaf # runtime
272+
164M out-weights
273+
3.8M sheaf # runtime
278274
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)...
285-
Step 100 | Loss: 2.4573
286275
```
287276

288277
</div>

docs/key-concepts.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ The reverse-mode pass then walks these bindings backward, accumulating adjoint c
7777
| Category | Operations |
7878
| ----------- | ----------------------------------------------------------- |
7979
| Arithmetic | `+`, `-`, `*`, `/`, `**`, `neg` |
80-
| Matrix | `@` (matmul), `transpose` |
80+
| Matrix | `@` (matmul), `einsum`, `transpose` |
8181
| Shape | `reshape`, `swapaxes`, `slice` |
8282
| Activations | `relu`, `gelu`, `sigmoid`, `tanh`, `softmax`, `log-softmax` |
8383
| Reductions | `sum`, `mean`, `var` |
@@ -129,13 +129,7 @@ Subsequent calls with the same argument shapes dispatch directly to the cached V
129129

130130
### Backend Selection
131131

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

140134
You can override this with the `--device` flag:
141135

@@ -246,5 +240,5 @@ Each argument position holds up to 8 cached buffers with most-recently-used orde
246240

247241
- **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`.
248242
- **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.** IREE backend performance varies by hardware. Benchmarks on your target device are recommended.
250244
- **Memory management.** No automatic model sharding or gradient checkpointing. Large models may exceed device memory.

docs/roadmap.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,52 @@ hide:
55

66
# Roadmap
77

8-
## Version 2.1 (planned features)
8+
These are the planned features for the next releases of Sheaf.
99

10-
### Performance
10+
### Language
1111

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

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

16-
### Distribution
16+
- **`reverse` / `flip`**: Reverse a tensor along an axis. Currently requires manual index construction.
1717

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

20-
### Developer experience
20+
- **`inc` / `dec`**: Small convenience to increment and decrement, as in Clojure. Currently `(+ var 1)` and `(- var 1)`.
2121

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

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

2628
### Operations
2729

2830
- **Convolution primitives**: `conv1d` and `conv2d` via `stablehlo.convolution`, exposed through the standard library.
2931

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

Comments
 (0)