KanakMalpani commited on
Commit
bf81425
·
verified ·
1 Parent(s): aa0261d

feat(W5): tiny .bnnpack canary (lab demo, not SOTA)

Browse files
Files changed (1) hide show
  1. README.md +70 -0
README.md ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: bnn-lab
4
+ tags:
5
+ - binary-neural-network
6
+ - xnor
7
+ - cpu
8
+ - mnist
9
+ - canary
10
+ - lab-demo
11
+ - not-sota
12
+ pipeline_tag: other
13
+ ---
14
+
15
+ # bnn-lab MNIST MLP `.bnnpack` (canary)
16
+
17
+ **Canary / lab demo — not ImageNet SOTA, not a MNIST leaderboard submission.**
18
+
19
+ Packed **hidden** `BinaryLinear` layers from `bnn.models.BinaryMLP` (`hidden=512`).
20
+ FP stem (`784→512`) and FP head (`512→10`) are **not** in this pack (standard
21
+ BNN practice; encode skips them).
22
+
23
+ ## This file vs published MNIST numbers
24
+
25
+ This Hub artifact is a **codec canary** (seed-0 `build_model("binary_mlp")`
26
+ BinaryLinear blobs). It is **not** the 3-epoch trained checkpoint
27
+ (`checkpoints/binary_mlp.pt` is gitignored). Do not report this file's
28
+ inference accuracy as the lab MNIST result.
29
+
30
+ Published STE train floors (CPU, seed **42**, 3 epochs) from
31
+ [`results/train_results.json`](https://github.com/KanakMalpani/Binary-Neural-Networks/blob/main/results/train_results.json)
32
+ and [`tests/golden_floors.json`](https://github.com/KanakMalpani/Binary-Neural-Networks/blob/main/tests/golden_floors.json)
33
+ `mnist`:
34
+
35
+ | Model | Recorded test acc | Floor |
36
+ |-------|-------------------|-------|
37
+ | `fp32_mlp` | **97.67** | `fp32_mlp_min_acc`: 96.0 |
38
+ | `binary_mlp` | **96.36** | `binary_mlp_min_acc`: **95.0** |
39
+ | `ternary_mlp` | **97.16** | `ternary_mlp_min_acc`: 95.0 |
40
+
41
+ Gap gate: `gap_max_pp_fp_vs_binary`: **3.0** pp when FP ≥ `fp_for_gap_gate` 97.0.
42
+ Retrain + re-encode: `bnn train --model binary_mlp --epochs 3 --seed 42` then
43
+ `python scripts/encode_hf_canaries.py --only mnist-mlp --from-checkpoint checkpoints/binary_mlp.pt`.
44
+
45
+ ## What 32× means
46
+
47
+ **32× is uint64 pack compression** of aligned BinaryLinear weights
48
+ (`in_features % 64 == 0`), not a GPU speedup from `sign()`. Training with STE
49
+ is simulation.
50
+
51
+ ## Load
52
+
53
+ ```python
54
+ from huggingface_hub import hf_hub_download
55
+ from bnn.codec import decode_file, packed_module_fp_err
56
+
57
+ path = hf_hub_download(
58
+ "KanakMalpani/bnn-lab-mnist-mlp-canary", filename="model.bnnpack"
59
+ )
60
+ modules, meta = decode_file(path)
61
+ for name, mod in modules.items():
62
+ print(name, mod.in_features, mod.out_features, packed_module_fp_err(mod))
63
+ ```
64
+
65
+ Tutorial: [`docs/tutorials/08_HF_OPTIMISER.md`](https://github.com/KanakMalpani/Binary-Neural-Networks/blob/main/docs/tutorials/08_HF_OPTIMISER.md).
66
+
67
+ ## License
68
+
69
+ MIT (same as [bnn-lab](https://pypi.org/project/bnn-lab/)). MNIST itself is not
70
+ bundled (lab `data/` is gitignored).