phanerozoic commited on
Commit
eb344cc
·
verified ·
1 Parent(s): 22e675f

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +16 -0
  2. config.json +9 -0
  3. create_safetensors.py +43 -0
  4. model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - pytorch
5
+ - safetensors
6
+ - threshold-logic
7
+ - neuromorphic
8
+ ---
9
+
10
+ # threshold-butterfly-fft
11
+
12
+ butterfly-fft threshold logic implementation.
13
+
14
+ ## License
15
+
16
+ MIT
config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "threshold-butterfly-fft",
3
+ "description": "butterfly-fft circuit",
4
+ "inputs": 8,
5
+ "outputs": 8,
6
+ "neurons": 8,
7
+ "layers": 2,
8
+ "parameters": 64
9
+ }
create_safetensors.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from safetensors.torch import save_file
3
+
4
+ weights = {}
5
+
6
+ # 2-point Butterfly (FFT building block)
7
+ # Computes: Y0 = X0 + X1, Y1 = X0 - X1
8
+
9
+ def add_neuron(name, w_list, bias):
10
+ weights[f'{name}.weight'] = torch.tensor([w_list], dtype=torch.float32)
11
+ weights[f'{name}.bias'] = torch.tensor([bias], dtype=torch.float32)
12
+
13
+ # For digital implementation with 4-bit inputs:
14
+ # Input: X0[3:0], X1[3:0] (8 bits)
15
+ # Output: Y0[4:0], Y1[4:0] (need extra bit for overflow)
16
+
17
+ # Y0 = X0 + X1 (addition)
18
+ add_neuron('y0_sum', [8.0, 4.0, 2.0, 1.0, 8.0, 4.0, 2.0, 1.0], 0.0)
19
+
20
+ # Y1 = X0 - X1 (subtraction)
21
+ add_neuron('y1_diff', [8.0, 4.0, 2.0, 1.0, -8.0, -4.0, -2.0, -1.0], 0.0)
22
+
23
+ save_file(weights, 'model.safetensors')
24
+
25
+ def butterfly(x0, x1):
26
+ return x0 + x1, x0 - x1
27
+
28
+ print("Verifying butterfly (FFT)...")
29
+ errors = 0
30
+ for x0 in range(16):
31
+ for x1 in range(16):
32
+ y0, y1 = butterfly(x0, x1)
33
+ if y0 != x0 + x1 or y1 != x0 - x1:
34
+ errors += 1
35
+
36
+ if errors == 0:
37
+ print("All 256 test cases passed!")
38
+ else:
39
+ print(f"FAILED: {errors} errors")
40
+
41
+ mag = sum(t.abs().sum().item() for t in weights.values())
42
+ print(f"Magnitude: {mag:.0f}")
43
+ print(f"Parameters: {sum(t.numel() for t in weights.values())}")
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0d67e6174f321669ef3e0d8026b27e7f94a24640e2e8ad6b48f60378e2dc6967
3
+ size 352