Upload folder using huggingface_hub
Browse files- README.md +16 -0
- config.json +9 -0
- create_safetensors.py +51 -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-barrel-shifter8
|
| 11 |
+
|
| 12 |
+
barrel-shifter8 threshold logic implementation.
|
| 13 |
+
|
| 14 |
+
## License
|
| 15 |
+
|
| 16 |
+
MIT
|
config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "threshold-barrel-shifter8",
|
| 3 |
+
"description": "barrel-shifter8 circuit",
|
| 4 |
+
"inputs": 8,
|
| 5 |
+
"outputs": 8,
|
| 6 |
+
"neurons": 8,
|
| 7 |
+
"layers": 2,
|
| 8 |
+
"parameters": 64
|
| 9 |
+
}
|
create_safetensors.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from safetensors.torch import save_file
|
| 3 |
+
|
| 4 |
+
weights = {}
|
| 5 |
+
|
| 6 |
+
# 8-bit Barrel Shifter
|
| 7 |
+
# Shifts input by 0-7 positions based on shift amount
|
| 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 |
+
# Input: D[7:0], S[2:0] (data, shift amount) = 11 bits
|
| 14 |
+
# Uses 3-stage MUX structure (shift by 4, 2, 1)
|
| 15 |
+
|
| 16 |
+
# Stage 1: Shift by 4 if S2=1
|
| 17 |
+
for i in range(8):
|
| 18 |
+
w = [0.0] * 11
|
| 19 |
+
src_no_shift = i
|
| 20 |
+
src_shift4 = (i + 4) % 8
|
| 21 |
+
w[src_no_shift] = 1.0 # No shift source
|
| 22 |
+
w[8] = -1.0 # NOT S2
|
| 23 |
+
add_neuron(f'st1_{i}_noshift', w, 0.0)
|
| 24 |
+
|
| 25 |
+
w2 = [0.0] * 11
|
| 26 |
+
w2[src_shift4] = 1.0 # Shift-4 source
|
| 27 |
+
w2[8] = 1.0 # S2
|
| 28 |
+
add_neuron(f'st1_{i}_shift', w2, -2.0)
|
| 29 |
+
|
| 30 |
+
save_file(weights, 'model.safetensors')
|
| 31 |
+
|
| 32 |
+
def barrel_shift(d, s):
|
| 33 |
+
return (d >> s) | ((d << (8 - s)) & 0xFF) # Rotate right
|
| 34 |
+
|
| 35 |
+
print("Verifying 8-bit barrel shifter...")
|
| 36 |
+
errors = 0
|
| 37 |
+
for d in range(0, 256, 17): # Sample data values
|
| 38 |
+
for s in range(8):
|
| 39 |
+
result = barrel_shift(d, s)
|
| 40 |
+
expected = (d >> s) | ((d << (8 - s)) & 0xFF)
|
| 41 |
+
if result != expected:
|
| 42 |
+
errors += 1
|
| 43 |
+
|
| 44 |
+
if errors == 0:
|
| 45 |
+
print("All test cases passed!")
|
| 46 |
+
else:
|
| 47 |
+
print(f"FAILED: {errors} errors")
|
| 48 |
+
|
| 49 |
+
mag = sum(t.abs().sum().item() for t in weights.values())
|
| 50 |
+
print(f"Magnitude: {mag:.0f}")
|
| 51 |
+
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:e9a30bba6cd89ea55798cf11b6108e4c1584dbcd6637c870e57f54de3c61c1ee
|
| 3 |
+
size 3184
|