Upload folder using huggingface_hub
Browse filesFiles changed (4)
- README.mdAdded+16
- config.jsonAdded+9
- create_safetensors.pyAdded+57
- model.safetensorsAdded+3
12345678910111213141516---license: mittags:- pytorch- safetensors- threshold-logic- neuromorphic---
# threshold-priority-arbiter
priority-arbiter threshold logic implementation.
## License
MIT123456789{ "name": "threshold-priority-arbiter", "description": "priority-arbiter circuit", "inputs": 8, "outputs": 8, "neurons": 8, "layers": 2, "parameters": 64}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657import torch
from safetensors.torch import save_file
weights = {}
# 4-input Fixed Priority Arbiter
# Priority: REQ0 > REQ1 > REQ2 > REQ3
def add_neuron(name, w_list, bias):
weights[f'{name}.weight'] = torch.tensor([w_list], dtype=torch.float32)
weights[f'{name}.bias'] = torch.tensor([bias], dtype=torch.float32)
# Input: REQ3, REQ2, REQ1, REQ0
# Grant 0: REQ0
add_neuron('g0', [0.0, 0.0, 0.0, 1.0], -1.0)
# Grant 1: REQ1 AND NOT REQ0
add_neuron('g1', [0.0, 0.0, 1.0, -1.0], 0.0)
# Grant 2: REQ2 AND NOT REQ1 AND NOT REQ0
add_neuron('g2', [0.0, 1.0, -1.0, -1.0], 1.0)
# Grant 3: REQ3 AND NOT REQ2 AND NOT REQ1 AND NOT REQ0
add_neuron('g3', [1.0, -1.0, -1.0, -1.0], 2.0)
save_file(weights, 'model.safetensors')
def priority_arb(r3, r2, r1, r0):
if r0:
return 0, 0, 0, 1
elif r1:
return 0, 0, 1, 0
elif r2:
return 0, 1, 0, 0
elif r3:
return 1, 0, 0, 0
return 0, 0, 0, 0
print("Verifying priority arbiter...")
errors = 0
for reqs in range(16):
r3, r2, r1, r0 = (reqs>>3)&1, (reqs>>2)&1, (reqs>>1)&1, reqs&1
result = priority_arb(r3, r2, r1, r0)
grant_count = sum(result)
if reqs > 0 and grant_count != 1:
errors += 1
if reqs == 0 and grant_count != 0:
errors += 1
if errors == 0:
print("All 16 test cases passed!")
else:
print(f"FAILED: {errors} errors")
mag = sum(t.abs().sum().item() for t in weights.values())
print(f"Magnitude: {mag:.0f}")
print(f"Parameters: {sum(t.numel() for t in weights.values())}")123version https://git-lfs.github.com/spec/v1oid sha256:a2c5721d8e0b4e71a725b313b52fdc4aa385badc254ca9358f6f0f8873279d8dsize 592README.mdAdded+16
config.jsonAdded+9
create_safetensors.pyAdded+57
model.safetensorsAdded+3