phanerozoic commited on
Commit
ceb4d99
Β·
verified Β·
1 Parent(s): e9ddd26

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +38 -0
  2. config.json +9 -0
  3. create_safetensors.py +49 -0
  4. model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - pytorch
5
+ - safetensors
6
+ - threshold-logic
7
+ - neuromorphic
8
+ - sequential
9
+ - shift-register
10
+ ---
11
+
12
+ # threshold-sipo
13
+
14
+ 4-bit Serial-In Parallel-Out shift register. Serial to parallel converter.
15
+
16
+ ## Circuit
17
+
18
+ ```
19
+ β”Œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”
20
+ SI ──► [Q3]─[Q2]─[Q1]─[Q0]
21
+ β”‚ β”‚ β”‚ β”‚
22
+ β–Ό β–Ό β–Ό β–Ό
23
+ P3 P2 P1 P0
24
+ ```
25
+
26
+ ## Parameters
27
+
28
+ | | |
29
+ |---|---|
30
+ | Inputs | 5 |
31
+ | Outputs | 4 |
32
+ | Neurons | 4 |
33
+ | Parameters | 24 |
34
+ | Magnitude | 8 |
35
+
36
+ ## License
37
+
38
+ MIT
config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "threshold-sipo",
3
+ "description": "4-bit SIPO shift register",
4
+ "inputs": 5,
5
+ "outputs": 4,
6
+ "neurons": 4,
7
+ "layers": 1,
8
+ "parameters": 24
9
+ }
create_safetensors.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from safetensors.torch import save_file
3
+
4
+ weights = {}
5
+
6
+ # 4-bit SIPO (Serial In, Parallel Out) Shift Register
7
+ # Input: Q[3:0] (current state), SI (serial input)
8
+ # Output: N[3:0] (next state = parallel output)
9
+
10
+ def add_neuron(name, w_list, bias):
11
+ weights[f'{name}.weight'] = torch.tensor([w_list], dtype=torch.float32)
12
+ weights[f'{name}.bias'] = torch.tensor([bias], dtype=torch.float32)
13
+
14
+ # N3 = SI
15
+ add_neuron('n3', [0.0, 0.0, 0.0, 0.0, 1.0], -1.0)
16
+
17
+ # N2 = Q3
18
+ add_neuron('n2', [1.0, 0.0, 0.0, 0.0, 0.0], -1.0)
19
+
20
+ # N1 = Q2
21
+ add_neuron('n1', [0.0, 1.0, 0.0, 0.0, 0.0], -1.0)
22
+
23
+ # N0 = Q1
24
+ add_neuron('n0', [0.0, 0.0, 1.0, 0.0, 0.0], -1.0)
25
+
26
+ save_file(weights, 'model.safetensors')
27
+
28
+ def sipo(q3, q2, q1, q0, si):
29
+ return si, q3, q2, q1
30
+
31
+ print("Verifying 4-bit SIPO shift register...")
32
+ errors = 0
33
+ for q in range(16):
34
+ for si in [0, 1]:
35
+ q3, q2, q1, q0 = (q>>3)&1, (q>>2)&1, (q>>1)&1, q&1
36
+ n3, n2, n1, n0 = sipo(q3, q2, q1, q0, si)
37
+ expected = (si << 3) | (q >> 1)
38
+ result = n3*8 + n2*4 + n1*2 + n0
39
+ if result != expected:
40
+ errors += 1
41
+
42
+ if errors == 0:
43
+ print("All 32 test cases passed!")
44
+ else:
45
+ print(f"FAILED: {errors} errors")
46
+
47
+ mag = sum(t.abs().sum().item() for t in weights.values())
48
+ print(f"Magnitude: {mag:.0f}")
49
+ 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:2fef5572fca8d366bd587ef75d2d31456f224a84eeff8bbadb5bdbad3ea3ed6b
3
+ size 608