Upload folder using huggingface_hub
Browse files- README.md +40 -0
- config.json +9 -0
- create_safetensors.py +60 -0
- model.safetensors +3 -0
README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- pytorch
|
| 5 |
+
- safetensors
|
| 6 |
+
- threshold-logic
|
| 7 |
+
- neuromorphic
|
| 8 |
+
- sequential
|
| 9 |
+
- register
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# threshold-pipo
|
| 13 |
+
|
| 14 |
+
4-bit Parallel-In Parallel-Out register with enable.
|
| 15 |
+
|
| 16 |
+
## Circuit
|
| 17 |
+
|
| 18 |
+
```
|
| 19 |
+
D3 D2 D1 D0
|
| 20 |
+
│ │ │ │
|
| 21 |
+
▼ ▼ ▼ ▼
|
| 22 |
+
[Q3] [Q2] [Q1] [Q0] ← EN
|
| 23 |
+
|
| 24 |
+
EN=1: Q = D (load)
|
| 25 |
+
EN=0: Q holds
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
## Parameters
|
| 29 |
+
|
| 30 |
+
| | |
|
| 31 |
+
|---|---|
|
| 32 |
+
| Inputs | 9 |
|
| 33 |
+
| Outputs | 4 |
|
| 34 |
+
| Neurons | 8 |
|
| 35 |
+
| Parameters | 80 |
|
| 36 |
+
| Magnitude | 24 |
|
| 37 |
+
|
| 38 |
+
## License
|
| 39 |
+
|
| 40 |
+
MIT
|
config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "threshold-pipo",
|
| 3 |
+
"description": "4-bit PIPO register",
|
| 4 |
+
"inputs": 9,
|
| 5 |
+
"outputs": 4,
|
| 6 |
+
"neurons": 8,
|
| 7 |
+
"layers": 2,
|
| 8 |
+
"parameters": 80
|
| 9 |
+
}
|
create_safetensors.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from safetensors.torch import save_file
|
| 3 |
+
|
| 4 |
+
weights = {}
|
| 5 |
+
|
| 6 |
+
# 4-bit PIPO (Parallel In, Parallel Out) Register
|
| 7 |
+
# Input: D[3:0] (data input), EN (enable)
|
| 8 |
+
# Output: Q[3:0] (when EN=1, Q = D; when EN=0, Q holds)
|
| 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 |
+
# Inputs: Q3=0, Q2=1, Q1=2, Q0=3, D3=4, D2=5, D1=6, D0=7, EN=8
|
| 15 |
+
|
| 16 |
+
# N3: EN ? D3 : Q3
|
| 17 |
+
add_neuron('n3_new', [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0], -2.0) # D3 AND EN
|
| 18 |
+
add_neuron('n3_hold', [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0], 0.0) # Q3 AND NOT EN
|
| 19 |
+
|
| 20 |
+
# N2: EN ? D2 : Q2
|
| 21 |
+
add_neuron('n2_new', [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0], -2.0)
|
| 22 |
+
add_neuron('n2_hold', [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0], 0.0)
|
| 23 |
+
|
| 24 |
+
# N1: EN ? D1 : Q1
|
| 25 |
+
add_neuron('n1_new', [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0], -2.0)
|
| 26 |
+
add_neuron('n1_hold', [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0], 0.0)
|
| 27 |
+
|
| 28 |
+
# N0: EN ? D0 : Q0
|
| 29 |
+
add_neuron('n0_new', [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0], -2.0)
|
| 30 |
+
add_neuron('n0_hold', [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0], 0.0)
|
| 31 |
+
|
| 32 |
+
save_file(weights, 'model.safetensors')
|
| 33 |
+
|
| 34 |
+
def pipo(q3, q2, q1, q0, d3, d2, d1, d0, en):
|
| 35 |
+
if en:
|
| 36 |
+
return d3, d2, d1, d0
|
| 37 |
+
else:
|
| 38 |
+
return q3, q2, q1, q0
|
| 39 |
+
|
| 40 |
+
print("Verifying 4-bit PIPO register...")
|
| 41 |
+
errors = 0
|
| 42 |
+
for q in range(16):
|
| 43 |
+
for d in range(16):
|
| 44 |
+
for en in [0, 1]:
|
| 45 |
+
q3, q2, q1, q0 = (q>>3)&1, (q>>2)&1, (q>>1)&1, q&1
|
| 46 |
+
d3, d2, d1, d0 = (d>>3)&1, (d>>2)&1, (d>>1)&1, d&1
|
| 47 |
+
n3, n2, n1, n0 = pipo(q3, q2, q1, q0, d3, d2, d1, d0, en)
|
| 48 |
+
result = n3*8 + n2*4 + n1*2 + n0
|
| 49 |
+
expected = d if en else q
|
| 50 |
+
if result != expected:
|
| 51 |
+
errors += 1
|
| 52 |
+
|
| 53 |
+
if errors == 0:
|
| 54 |
+
print("All 512 test cases passed!")
|
| 55 |
+
else:
|
| 56 |
+
print(f"FAILED: {errors} errors")
|
| 57 |
+
|
| 58 |
+
mag = sum(t.abs().sum().item() for t in weights.values())
|
| 59 |
+
print(f"Magnitude: {mag:.0f}")
|
| 60 |
+
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:8cf0c752cdc7d15ae2014e1c972b6d1025e9ee58cfd9bbe1d3ba83df547f94a0
|
| 3 |
+
size 1432
|