Commit 360479b
committed
M17: native window ops (conv-pool training)
Lift window_sum, window_max, window_min, window_product,
window_scatter_max, window_scatter_min off via_binary onto native MLX.
MLX has no direct primitives — each op is composed as mx::pad →
mx::as_strided (sliding-window view) → reduce, mirroring
nn/layers/pooling.py generalised to N-D so Nx's per-axis
window/stride/padding/dilation all lower cleanly. Scatter variants
add argmax-with-last-occurrence-tie-break (mask * arange(K) trick,
since mx::argmax is first-occurrence) → per-axis absolute-index
computation → mx::scatter_add into a mx::full(init_value) buffer →
slice back. Closes the training primitive set: grad(window_max) in Nx
rewrites to window_scatter_max, so every MaxPool backward pass now
stays on MLX instead of round-tripping through BinaryBackend.
Tests: backend_window_test (19 unit — shape × stride × padding ×
dilation × f32/bf16/s32/u8), backend_window_scatter_test (11 —
overlapping windows, tie-break, non-zero init, 1-D/3-D),
grad-equivalence extensions (3 new zoo fns: window_sum,
window_max_pool, window_avg_pool; bf16 equivalence auto-picks-up;
EXLA oracle skips un-regenerated entries via
ExlaGoldenData.has_golden?/1), cnn_curve_test (handwritten 2-conv +
max-pool CNN, 30 steps), mnist_cnn_full_test (:training_full, LeNet
≥97%, observed 1.60 → 0.12 loss over 5 epochs).1 parent 5b23df1 commit 360479b
15 files changed
Lines changed: 1315 additions & 29 deletions
File tree
- c_src/ops
- lib/emily
- test
- emily
- grad
- training
- support
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
855 | 855 | | |
856 | 856 | | |
857 | 857 | | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
858 | 895 | | |
859 | 896 | | |
860 | 897 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 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 | + | |
11 | 42 | | |
12 | 43 | | |
13 | 44 | | |
| |||
0 commit comments