Upload folder using huggingface_hub
Browse files- README.md +16 -0
- config.json +9 -0
- create_safetensors.py +48 -0
- 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-binary2bcd
|
| 11 |
+
|
| 12 |
+
binary2bcd threshold logic implementation.
|
| 13 |
+
|
| 14 |
+
## License
|
| 15 |
+
|
| 16 |
+
MIT
|
config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "threshold-binary2bcd",
|
| 3 |
+
"description": "binary2bcd circuit",
|
| 4 |
+
"inputs": 8,
|
| 5 |
+
"outputs": 8,
|
| 6 |
+
"neurons": 8,
|
| 7 |
+
"layers": 2,
|
| 8 |
+
"parameters": 64
|
| 9 |
+
}
|
create_safetensors.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from safetensors.torch import save_file
|
| 3 |
+
|
| 4 |
+
weights = {}
|
| 5 |
+
|
| 6 |
+
# 4-bit Binary to BCD (for 0-9, identity; 10-15 invalid)
|
| 7 |
+
# Extended: detect if value >= 10 for two-digit output
|
| 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 |
+
# Pass through bits
|
| 14 |
+
for i in range(4):
|
| 15 |
+
w = [0.0] * 4
|
| 16 |
+
w[i] = 1.0
|
| 17 |
+
add_neuron(f'd{3-i}', w, -1.0)
|
| 18 |
+
|
| 19 |
+
# Detect >= 10 (for overflow into tens digit)
|
| 20 |
+
add_neuron('ge10', [8.0, 4.0, 2.0, 1.0], -10.0)
|
| 21 |
+
|
| 22 |
+
save_file(weights, 'model.safetensors')
|
| 23 |
+
|
| 24 |
+
def binary2bcd(b3, b2, b1, b0):
|
| 25 |
+
val = b3*8 + b2*4 + b1*2 + b0
|
| 26 |
+
if val < 10:
|
| 27 |
+
return 0, b3, b2, b1, b0
|
| 28 |
+
else:
|
| 29 |
+
ones = val - 10
|
| 30 |
+
return 1, (ones>>3)&1, (ones>>2)&1, (ones>>1)&1, ones&1
|
| 31 |
+
|
| 32 |
+
print("Verifying Binary to BCD...")
|
| 33 |
+
errors = 0
|
| 34 |
+
for b in range(16):
|
| 35 |
+
b3, b2, b1, b0 = (b>>3)&1, (b>>2)&1, (b>>1)&1, b&1
|
| 36 |
+
tens, d3, d2, d1, d0 = binary2bcd(b3, b2, b1, b0)
|
| 37 |
+
result = tens * 10 + d3*8 + d2*4 + d1*2 + d0
|
| 38 |
+
if result != b:
|
| 39 |
+
errors += 1
|
| 40 |
+
|
| 41 |
+
if errors == 0:
|
| 42 |
+
print("All 16 test cases passed!")
|
| 43 |
+
else:
|
| 44 |
+
print(f"FAILED: {errors} errors")
|
| 45 |
+
|
| 46 |
+
mag = sum(t.abs().sum().item() for t in weights.values())
|
| 47 |
+
print(f"Magnitude: {mag:.0f}")
|
| 48 |
+
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:7b32cedd67f13aef13801b6e1f5b0da6bef160244949e56420fcb4c02fa81fcc
|
| 3 |
+
size 748
|