neura-program 0.4.0

Graph lowering, wave scheduling and device tape encoding
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
use neura_abi::{Element, Kind, Placement, TaskRecord, ValueRecord, strategy};
use neura_graph::{Graph, Init, Shape, Value, Window};
use neura_profile::{Budget, Profile};

fn narrow() -> Profile {
    Profile::derive(Budget::BASELINE)[0]
}

fn wide() -> Profile {
    *Profile::derive(Budget::BASELINE).last().expect("a profile")
}
use neura_program::Encoding;
use std::mem::size_of;

const ALIGNMENT: u64 = 256;
const PLACEMENT: Placement = Placement::new(1 << 16, 1 << 18);

fn encoding_with(graph: &Graph, profile: Profile) -> Encoding {
    Encoding::of(graph, ALIGNMENT, profile)
}

fn refuses(action: impl FnOnce()) -> bool {
    std::panic::catch_unwind(std::panic::AssertUnwindSafe(action)).is_err()
}

fn tape(encoding: &Encoding) -> Vec<TaskRecord> {
    encoding
        .tasks()
        .as_chunks::<{ std::mem::size_of::<TaskRecord>() }>()
        .0
        .iter()
        .map(|task| bytemuck::pod_read_unaligned(task))
        .collect()
}

fn tasks_of(encoding: &Encoding, value: Value) -> Vec<TaskRecord> {
    tape(encoding)
        .into_iter()
        .filter(|task| task.out == value.id())
        .collect()
}

fn values_of(encoding: &Encoding) -> Vec<ValueRecord> {
    encoding
        .values()
        .as_chunks::<{ size_of::<ValueRecord>() }>()
        .0
        .iter()
        .map(|value| bytemuck::pod_read_unaligned(value))
        .collect()
}

#[test]
fn a_row_folds_in_the_strategy_its_length_asks_for() {
    let graph = Graph::new();
    let short = graph.argmax(graph.input(Shape::matrix(4, 8), Element::Single));
    let middle = graph.argmax(graph.input(Shape::matrix(333, 200), Element::Single));
    let long = graph.argmax(graph.input(Shape::matrix(2, 4096), Element::Single));
    graph.retain(short);
    graph.retain(middle);
    graph.retain(long);
    for (profile, middle_geometry) in [
        (narrow(), strategy::WORKGROUP_ROW),
        (wide(), strategy::THREAD_ROW),
    ] {
        let encoding = encoding_with(&graph, profile);
        assert_eq!(tasks_of(&encoding, short).len(), 4);
        let folds = tasks_of(&encoding, middle);
        let rows_per_task = 333u32.div_ceil(profile.workgroups());
        assert_eq!(
            folds.len(),
            333usize.div_ceil(rows_per_task as usize),
            "a row fold hands the device the tasks its device width asks for",
        );
        assert_eq!(tasks_of(&encoding, long).len(), 2);
        for (index, task) in tasks_of(&encoding, short).into_iter().enumerate() {
            assert_eq!(task.geometry, strategy::THREAD_ROW);
            assert_eq!(task.first, index as u32);
            assert_eq!(task.count, 1);
            assert_eq!(Kind::of(task.kind), Kind::Argmax);
        }
        let mut covered = 0;
        for task in tasks_of(&encoding, middle) {
            assert_eq!(
                task.geometry, middle_geometry,
                "a row of 200 elements folds through {middle_geometry} on {profile:?}",
            );
            assert!(task.count > 0 && task.count <= 333);
            covered += task.count;
        }
        assert_eq!(covered, 333);
        for (index, task) in tasks_of(&encoding, long).into_iter().enumerate() {
            assert_eq!(task.geometry, strategy::WORKGROUP_ROW);
            assert_eq!(task.first, index as u32);
            assert_eq!(task.count, 1);
        }
    }
}

#[test]
fn a_row_fold_hands_the_device_the_geometry_its_axis_asks_for() {
    let graph = Graph::new();
    let short = graph.sum_rows(graph.input(Shape::matrix(64, 8), Element::Single));
    let long = graph.sum_rows(graph.input(Shape::matrix(2, 200), Element::Single));
    let view = graph.sum_rows(graph.permute(
        graph.input(Shape::matrix(200, 2), Element::Single),
        [0, 1, 3, 2],
    ));
    graph.retain(short);
    graph.retain(long);
    graph.retain(view);
    for (profile, long_geometry) in [
        (narrow(), strategy::WORKGROUP_ROW),
        (wide(), strategy::THREAD_ROW),
    ] {
        let encoding = encoding_with(&graph, profile);
        let short = tasks_of(&encoding, short);
        assert_eq!(short.len(), 64);
        for (index, task) in short.into_iter().enumerate() {
            assert_eq!(Kind::of(task.kind), Kind::SumAxis);
            assert_eq!(task.slot, 3);
            assert_eq!(
                task.geometry,
                strategy::THREAD_ROW,
                "a row of eight elements folds through one thread",
            );
            assert_eq!(task.first, index as u32);
            assert_eq!(task.count, 1);
        }
        let long = tasks_of(&encoding, long);
        assert_eq!(long.len(), 2);
        for (index, task) in long.into_iter().enumerate() {
            assert_eq!(
                task.geometry, long_geometry,
                "a row of 200 elements folds through {long_geometry} on {profile:?}",
            );
            assert_eq!(task.slot, 3);
            assert_eq!(task.first, index as u32);
            assert_eq!(task.count, 1);
        }
        let view = tasks_of(&encoding, view);
        assert_eq!(view.len(), 1);
        assert_eq!(
            view[0].geometry,
            strategy::THREAD_ELEMENT,
            "a row a view holds apart folds element by element",
        );
        assert_eq!(view[0].slot, 3);
        assert_eq!(view[0].count, 2);
    }
}

#[test]
fn a_product_hands_the_device_a_tile_for_every_plane() {
    let graph = Graph::new();
    let left = graph.parameter(Shape::of([2, 3, 64, 16]), Init::Zero, Element::Single);
    let right = graph.parameter(Shape::of([2, 3, 16, 32]), Init::Zero, Element::Single);
    let batched = graph.matmul(left, right);
    let shared = graph.matmul(
        left,
        graph.parameter(Shape::matrix(16, 32), Init::Zero, Element::Single),
    );
    let spread = graph.matmul(
        graph.parameter(Shape::of([2, 1, 64, 16]), Init::Zero, Element::Single),
        right,
    );
    graph.retain(batched);
    graph.retain(shared);
    graph.retain(spread);
    assert_eq!(batched.shape(), Shape::of([2, 3, 64, 32]));
    assert_eq!(shared.shape(), Shape::of([2, 3, 64, 32]));
    assert_eq!(spread.shape(), Shape::of([2, 3, 64, 32]));
    let encoding = encoding_with(&graph, wide());
    let geometries = encoding.matmul_geometries();
    assert_eq!(
        geometries.len(),
        1,
        "three products of one shape take one tile of it",
    );
    let (tile, count) = geometries[0];
    let per_plane = 64u32.div_ceil(tile.rows()) * 32u32.div_ceil(tile.columns());
    assert_eq!(
        count,
        3 * 6 * per_plane,
        "every plane of every product carries its own tiles",
    );
    for product in [batched, shared, spread] {
        let tasks = tasks_of(&encoding, product);
        assert_eq!(tasks.len() as u32, 6 * per_plane);
        for (tile_index, task) in tasks.into_iter().enumerate() {
            assert_eq!(Kind::of(task.kind), Kind::Matmul);
            assert_eq!(task.first, tile_index as u32);
            assert_eq!(task.count, 1);
            assert_eq!(
                task.splits, 1,
                "a product of one depth block splits nothing"
            );
        }
    }
    assert_eq!(
        encoding.work(),
        u64::from(3 * 6 * per_plane) * tile.tile_work(),
        "a plan accounts the tiles of every plane",
    );
}

#[test]
fn a_product_refuses_batches_that_do_not_meet() {
    let graph = Graph::new();
    let left = graph.parameter(Shape::of([2, 1, 4, 3]), Init::Zero, Element::Single);
    assert!(refuses(|| {
        let _ = graph.matmul(
            left,
            graph.parameter(Shape::of([3, 1, 3, 5]), Init::Zero, Element::Single),
        );
    }));
    assert!(refuses(|| {
        let _ = graph.matmul(
            left,
            graph.parameter(Shape::of([2, 1, 4, 5]), Init::Zero, Element::Single),
        );
    }));
    assert!(refuses(|| {
        let _ = graph.sum_rows(graph.parameter(Shape::matrix(4, 1), Init::Zero, Element::Single));
    }));
}

#[test]
fn a_choice_covers_every_row_once() {
    let rows = 1000u32;
    let graph = Graph::new();
    let seed = graph.input(Shape::scalar(), Element::Single);
    let action = graph.categorical(graph.input(Shape::matrix(rows, 16), Element::Single), seed);
    graph.retain(action);
    let encoding = encoding_with(&graph, wide());
    let tasks = tasks_of(&encoding, action);
    assert_eq!(tasks.len(), 250);
    let mut cursor = 0;
    for task in tasks {
        assert_eq!(task.first, cursor);
        assert_eq!(task.count, 4);
        assert_eq!(Kind::of(task.kind), Kind::Categorical);
        assert_eq!(task.b, seed.id());
        cursor += task.count;
    }
    assert_eq!(cursor, rows);
    assert_eq!(encoding.span(action, PLACEMENT).elements, rows);
}

#[test]
fn an_index_list_carries_one_index_per_row() {
    let graph = Graph::new();
    let indices = graph.input(Shape::matrix(6, 1), Element::Single);
    let mask = graph.one_hot(indices, 4);
    graph.retain(mask);
    let encoding = encoding_with(&graph, wide());
    let tasks = tasks_of(&encoding, mask);
    assert_eq!(tasks.len(), 1);
    assert_eq!(Kind::of(tasks[0].kind), Kind::OneHot);
    assert_eq!(tasks[0].a, indices.id());
    assert_eq!(encoding.span(mask, PLACEMENT).elements, 24);
    assert_eq!(graph.shape(mask), Shape::matrix(6, 4));
}

#[test]
fn a_gather_copies_the_rows_of_the_table_it_names() {
    let graph = Graph::new();
    let table = graph.input(Shape::matrix(5, 3), Element::Single);
    let indices = graph.input(Shape::matrix(7, 1), Element::Single);
    let picked = graph.gather(table, indices);
    graph.retain(picked);
    let encoding = encoding_with(&graph, wide());
    let tasks = tasks_of(&encoding, picked);
    assert_eq!(tasks.len(), 1);
    assert_eq!(Kind::of(tasks[0].kind), Kind::Gather);
    assert_eq!(tasks[0].a, table.id());
    assert_eq!(tasks[0].b, indices.id());
    assert_eq!(encoding.span(picked, PLACEMENT).elements, 21);
    assert_eq!(graph.shape(picked), Shape::matrix(7, 3));
}

#[test]
fn a_convolution_hands_the_device_the_window_it_walks() {
    let graph = Graph::new();
    let input = graph.input(Shape::of([2, 3, 64, 64]), Element::Single);
    let filter = graph.parameter(Shape::of([4, 3, 3, 3]), Init::Zero, Element::Single);
    let window = Window::new([3, 3], [2, 2], [1, 1]);
    let convolved = graph.conv2d(input, filter, window);
    assert_eq!(convolved.shape(), Shape::of([2, 4, 32, 32]));
    graph.retain(convolved);
    let encoding = encoding_with(&graph, wide());
    let tasks = tasks_of(&encoding, convolved);
    assert_eq!(tasks.len(), 4);
    let mut cursor = 0;
    for task in tasks {
        assert_eq!(Kind::of(task.kind), Kind::Conv2d);
        assert_eq!(task.a, input.id());
        assert_eq!(task.b, filter.id());
        assert_eq!(task.first, cursor);
        assert_eq!(task.count, 2048);
        assert_eq!(task.stride_rows, 2);
        assert_eq!(task.stride_columns, 2);
        assert_eq!(task.pad_rows, 1);
        assert_eq!(task.pad_columns, 1);
        cursor += task.count;
    }
    assert_eq!(cursor, 8192);
    assert_eq!(encoding.span(convolved, PLACEMENT).elements, 8192);
    assert_eq!(
        encoding.work(),
        8192 * 27,
        "a convolution accounts every channel of every tap it reads",
    );
}

#[test]
fn a_convolution_weight_gradient_chunks_its_positions_and_folds_them() {
    let graph = Graph::new();
    let input = graph.parameter(Shape::of([1, 16, 8, 8]), Init::Zero, Element::Single);
    let filter = graph.parameter(Shape::of([16, 16, 3, 3]), Init::Zero, Element::Single);
    let window = Window::new([3, 3], [1, 1], [1, 1]);
    let convolved = graph.conv2d(input, filter, window);
    let gradients = graph.backward(graph.sum(convolved));
    let output_grad = gradients.of(convolved);
    let weight_grad = gradients.of(filter);
    graph.retain(weight_grad);
    let encoding = encoding_with(&graph, wide());
    let gradient_tasks = tape(&encoding)
        .into_iter()
        .filter(|task| Kind::of(task.kind) == Kind::Conv2dWeightGrad)
        .collect::<Vec<_>>();
    let partials = gradient_tasks
        .iter()
        .find(|task| task.out != weight_grad.id())
        .map(|task| task.out)
        .expect("a weight gradient splits its positions before it folds them");
    assert_eq!(
        values_of(&encoding)[partials as usize].dims,
        [1, 1, 64, 2304],
        "the chunks of a weight gradient are summed down one row each",
    );
    let mut chunks = 0u32;
    let mut folded = 0u32;
    for task in gradient_tasks {
        if task.out == weight_grad.id() {
            assert_eq!(task.geometry, strategy::WEIGHT_FOLD);
            assert_eq!(task.a, partials);
            folded += task.count;
        } else {
            assert_eq!(task.out, partials);
            assert_eq!(task.geometry, strategy::WEIGHT_CHUNK);
            assert_eq!(task.a, input.id());
            assert_eq!(task.b, output_grad.id());
            assert_eq!(task.c, filter.id());
            chunks += 1;
        }
    }
    assert_eq!(chunks, 128);
    assert_eq!(folded, 2304);
    assert_eq!(encoding.span(weight_grad, PLACEMENT).elements, 2304);
}

#[test]
fn a_convolution_stops_the_graph_it_cannot_walk() {
    let graph = Graph::new();
    let input = graph.input(Shape::of([2, 3, 6, 6]), Element::Single);
    let filter = graph.parameter(Shape::of([4, 3, 3, 3]), Init::Zero, Element::Single);
    assert!(refuses(|| {
        let _ = graph.conv2d(input, filter, Window::sliding([5, 5]));
    }));
    assert!(refuses(|| {
        let _ = graph.conv2d(
            input,
            graph.parameter(Shape::of([4, 2, 3, 3]), Init::Zero, Element::Single),
            Window::sliding([3, 3]),
        );
    }));
    assert!(refuses(|| {
        let _ = graph.conv2d(
            graph.input(Shape::of([2, 3, 2, 2]), Element::Single),
            graph.parameter(Shape::of([4, 3, 5, 5]), Init::Zero, Element::Single),
            Window::new([5, 5], [1, 1], [1, 1]),
        );
    }));
}

#[test]
fn a_choice_stops_the_graph_it_cannot_fold() {
    let graph = Graph::new();
    let table = graph.parameter(Shape::matrix(4, 4), Init::Zero, Element::Single);
    let indices = graph.input(Shape::matrix(2, 1), Element::Single);
    assert!(refuses(|| {
        let _ = graph.argmax(graph.permute(table, [0, 1, 3, 2]));
    }));
    assert!(refuses(|| {
        let _ = graph.gather(
            graph.input(Shape::matrix(4, 4), Element::Single),
            graph.input(Shape::matrix(2, 2), Element::Single),
        );
    }));
    assert!(refuses(|| {
        let _ = graph.one_hot(indices, 0);
    }));
    assert!(refuses(|| {
        let _ = graph.one_hot(graph.permute(table, [0, 1, 3, 2]), 2);
    }));
    assert!(refuses(|| {
        let _ = graph.categorical(
            graph.input(Shape::vector(4), Element::Single),
            graph.input(Shape::vector(2), Element::Single),
        );
    }));
}

#[test]
fn an_index_carries_no_gradient_of_its_own() {
    let index_graph = Graph::new();
    let indices = index_graph.input(Shape::matrix(2, 1), Element::Single);
    let drawn = index_graph.argmax(indices);
    assert!(refuses(|| {
        let _ = index_graph.backward(drawn);
    }));

    let table_graph = Graph::new();
    let table = table_graph.parameter(Shape::matrix(4, 3), Init::Zero, Element::Single);
    let indices = table_graph.input(Shape::matrix(2, 1), Element::Single);
    let picked = table_graph.matmul(table_graph.one_hot(indices, 4), table);
    let gradients = table_graph.backward(table_graph.sum(picked));
    assert_eq!(gradients.of(table).shape(), Shape::matrix(4, 3));
}

#[test]
fn a_gather_walks_its_gradient_back_into_the_table_it_reads() {
    let graph = Graph::new();
    let table = graph.parameter(Shape::matrix(4, 3), Init::Zero, Element::Single);
    let indices = graph.input(Shape::matrix(2, 1), Element::Single);
    let picked = graph.gather(table, indices);
    let gradients = graph.backward(graph.sum(picked));
    assert_eq!(gradients.of(table).shape(), Shape::matrix(4, 3));
}

#[test]
fn a_scatter_adds_updates_into_the_leaf_it_names() {
    let graph = Graph::new();
    let table = graph.resident(Shape::matrix(4, 3), Element::Single);
    let indices = graph.input(Shape::matrix(2, 1), Element::Single);
    let updates = graph.input(Shape::matrix(2, 3), Element::Single);
    graph.scatter_into(table, indices, updates);
    let encoding = encoding_with(&graph, narrow());
    assert_eq!(encoding.task_count(), 1);
    assert!(!encoding.updates_weights());
}

#[test]
fn a_scatter_stops_at_every_tensor_it_cannot_update() {
    let graph = Graph::new();
    let table = graph.resident(Shape::matrix(4, 3), Element::Single);
    let derived = graph.mul(table, table);
    let indices = graph.input(Shape::matrix(2, 1), Element::Single);
    let updates = graph.input(Shape::matrix(2, 3), Element::Single);
    let wide = graph.input(Shape::matrix(2, 4), Element::Single);
    assert!(refuses(|| {
        graph.scatter_into(derived, indices, updates);
    }));
    assert!(refuses(|| {
        graph.scatter_into(table, indices, wide);
    }));
    assert!(refuses(|| {
        graph.scatter_into(table, graph.permute(indices, [0, 1, 3, 2]), updates);
    }));
}

#[test]
fn an_attention_hands_the_device_a_row_block_for_every_plane() {
    let heads = 2u32;
    let batch = 2u32;
    let tokens = 9u32;
    let width = 4u32;
    let graph = Graph::new();
    let tensor = |tokens: u32| {
        graph.parameter(
            Shape::of([heads, batch, tokens, width]),
            Init::Zero,
            Element::Single,
        )
    };
    let out = graph.attention(
        tensor(tokens),
        tensor(tokens),
        tensor(tokens),
        neura_graph::AttentionOptions {
            scale: 0.5,
            causal: true,
            origin: None,
        },
    );
    graph.retain(out);
    for profile in [narrow(), wide()] {
        let encoding = encoding_with(&graph, profile);
        let tiles = encoding.attention();
        assert_eq!(
            tiles.len(),
            1,
            "one width of one graph takes one attention tile",
        );
        assert_eq!(tiles[0].width(), width);
        assert!(
            tiles[0].shared_bytes() <= profile.shared_bytes(),
            "an attention stages more than the pool its profile offers",
        );
        let tasks = tasks_of(&encoding, out);
        let blocks = tokens.div_ceil(profile.workgroup());
        assert_eq!(
            tasks.len() as u32,
            heads * batch * blocks,
            "an attention hands the device one task per row block of every plane",
        );
        let mut plane = 0u32;
        let mut block = 0u32;
        for task in tasks {
            assert_eq!(Kind::of(task.kind), Kind::Attention);
            assert_eq!(task.geometry, 0);
            assert_ne!(task.extra, neura_abi::NO_VALUE);
            assert!(task.count > 0 && task.count <= profile.workgroup());
            assert_eq!(task.first, plane * tokens + block * profile.workgroup());
            assert!(task.param > 0.0 && task.slot == 1);
            block += 1;
            if block == blocks {
                block = 0;
                plane += 1;
            }
        }
    }
}

#[test]
fn an_attention_keeps_the_shared_pool_its_products_stage_from() {
    let tokens = 64u32;
    let width = 8u32;
    let graph = Graph::new();
    let data = graph.parameter(
        Shape::of([1, 1, tokens, width]),
        Init::Zero,
        Element::Single,
    );
    let left = graph.parameter(Shape::matrix(64, 64), Init::Zero, Element::Single);
    let right = graph.parameter(Shape::matrix(64, 64), Init::Zero, Element::Single);
    graph.retain(graph.matmul(left, right));
    let out = graph.attention(
        data,
        data,
        data,
        neura_graph::AttentionOptions {
            scale: 0.5,
            causal: false,
            origin: None,
        },
    );
    graph.retain(out);
    let profile = wide();
    let encoding = encoding_with(&graph, profile);
    let spare = profile.shared_bytes() - profile.staging_bytes();
    assert!(
        encoding.attention()[0].shared_bytes() <= spare,
        "an attention beside a product stages within what the product leaves",
    );
    assert!(
        u64::from(encoding.attention()[0].keys()) * 2 * u64::from(width) * 4 <= spare,
        "an attention keys within the pool the products leave",
    );
}

#[test]
fn an_attention_stops_the_plan_that_asks_for_more_registers_than_a_thread_carries() {
    let graph = Graph::new();
    let width = 96u32;
    let tensor = graph.parameter(Shape::of([1, 1, 4, width]), Init::Zero, Element::Single);
    let out = graph.attention(
        tensor,
        tensor,
        tensor,
        neura_graph::AttentionOptions {
            scale: 0.5,
            causal: false,
            origin: None,
        },
    );
    graph.retain(out);
    assert!(refuses(|| {
        let _ = encoding_with(&graph, narrow());
    }));
}