Upload folder using huggingface_hub
Browse files- README.md +40 -0
- config.json +9 -0
- create_safetensors.py +51 -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 |
+
- counter
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# threshold-ring-counter
|
| 13 |
+
|
| 14 |
+
4-bit ring counter. One-hot encoding rotates through 4 states.
|
| 15 |
+
|
| 16 |
+
## Sequence
|
| 17 |
+
|
| 18 |
+
```
|
| 19 |
+
0001 → 0010 → 0100 → 1000 → 0001 (4 states)
|
| 20 |
+
```
|
| 21 |
+
|
| 22 |
+
## Applications
|
| 23 |
+
|
| 24 |
+
- State machine sequencing
|
| 25 |
+
- Phase generation
|
| 26 |
+
- Timing signals
|
| 27 |
+
|
| 28 |
+
## Parameters
|
| 29 |
+
|
| 30 |
+
| | |
|
| 31 |
+
|---|---|
|
| 32 |
+
| Inputs | 4 |
|
| 33 |
+
| Outputs | 4 |
|
| 34 |
+
| Neurons | 4 |
|
| 35 |
+
| Parameters | 20 |
|
| 36 |
+
| Magnitude | 8 |
|
| 37 |
+
|
| 38 |
+
## License
|
| 39 |
+
|
| 40 |
+
MIT
|
config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "threshold-ring-counter",
|
| 3 |
+
"description": "4-bit ring counter next-state logic",
|
| 4 |
+
"inputs": 4,
|
| 5 |
+
"outputs": 4,
|
| 6 |
+
"neurons": 4,
|
| 7 |
+
"layers": 1,
|
| 8 |
+
"parameters": 20
|
| 9 |
+
}
|
create_safetensors.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from safetensors.torch import save_file
|
| 3 |
+
|
| 4 |
+
weights = {}
|
| 5 |
+
|
| 6 |
+
# 4-bit Ring Counter (Next State Logic)
|
| 7 |
+
# One-hot encoding that rotates: 0001 -> 0010 -> 0100 -> 1000 -> 0001
|
| 8 |
+
# Input: Q[3:0] (current state, one-hot)
|
| 9 |
+
# Output: N[3:0] (next state, shifted left with wrap)
|
| 10 |
+
|
| 11 |
+
def add_neuron(name, w_list, bias):
|
| 12 |
+
weights[f'{name}.weight'] = torch.tensor([w_list], dtype=torch.float32)
|
| 13 |
+
weights[f'{name}.bias'] = torch.tensor([bias], dtype=torch.float32)
|
| 14 |
+
|
| 15 |
+
# N0 = Q3 (wrap around)
|
| 16 |
+
add_neuron('n0', [1.0, 0.0, 0.0, 0.0], -1.0)
|
| 17 |
+
|
| 18 |
+
# N1 = Q0
|
| 19 |
+
add_neuron('n1', [0.0, 0.0, 0.0, 1.0], -1.0)
|
| 20 |
+
|
| 21 |
+
# N2 = Q1
|
| 22 |
+
add_neuron('n2', [0.0, 0.0, 1.0, 0.0], -1.0)
|
| 23 |
+
|
| 24 |
+
# N3 = Q2
|
| 25 |
+
add_neuron('n3', [0.0, 1.0, 0.0, 0.0], -1.0)
|
| 26 |
+
|
| 27 |
+
save_file(weights, 'model.safetensors')
|
| 28 |
+
|
| 29 |
+
def ring_counter(q3, q2, q1, q0):
|
| 30 |
+
# Rotate left
|
| 31 |
+
return q2, q1, q0, q3
|
| 32 |
+
|
| 33 |
+
print("Verifying 4-bit ring counter...")
|
| 34 |
+
errors = 0
|
| 35 |
+
states = [(0,0,0,1), (0,0,1,0), (0,1,0,0), (1,0,0,0)]
|
| 36 |
+
for i, (q3, q2, q1, q0) in enumerate(states):
|
| 37 |
+
n3, n2, n1, n0 = ring_counter(q3, q2, q1, q0)
|
| 38 |
+
expected = states[(i + 1) % 4]
|
| 39 |
+
result = (n3, n2, n1, n0)
|
| 40 |
+
if result != expected:
|
| 41 |
+
errors += 1
|
| 42 |
+
print(f"ERROR: state {i} -> {result}, expected {expected}")
|
| 43 |
+
|
| 44 |
+
if errors == 0:
|
| 45 |
+
print("All 4 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:b0701e98972c7394d9689d735bd6842e9f8dbf741d8bc10d7b62db83e0be4590
|
| 3 |
+
size 592
|