Upload folder using huggingface_hub
Browse files- README.md +27 -0
- config.json +9 -0
- create_safetensors.py +60 -0
- model.safetensors +3 -0
README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- pytorch
|
| 5 |
+
- safetensors
|
| 6 |
+
- threshold-logic
|
| 7 |
+
- neuromorphic
|
| 8 |
+
- error-detection
|
| 9 |
+
- crc
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# threshold-crc16
|
| 13 |
+
|
| 14 |
+
CRC-16 CCITT step function. Polynomial: x^16 + x^12 + x^5 + 1 (0x1021).
|
| 15 |
+
|
| 16 |
+
## Parameters
|
| 17 |
+
|
| 18 |
+
| | |
|
| 19 |
+
|---|---|
|
| 20 |
+
| Polynomial | 0x1021 |
|
| 21 |
+
| Inputs | 17 |
|
| 22 |
+
| Outputs | 16 |
|
| 23 |
+
| Parameters | 324 |
|
| 24 |
+
|
| 25 |
+
## License
|
| 26 |
+
|
| 27 |
+
MIT
|
config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "threshold-crc16",
|
| 3 |
+
"description": "CRC-16 CCITT single-bit step function",
|
| 4 |
+
"inputs": 17,
|
| 5 |
+
"outputs": 16,
|
| 6 |
+
"neurons": 18,
|
| 7 |
+
"layers": 2,
|
| 8 |
+
"parameters": 324
|
| 9 |
+
}
|
create_safetensors.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from safetensors.torch import save_file
|
| 3 |
+
|
| 4 |
+
weights = {}
|
| 5 |
+
|
| 6 |
+
# CRC-16-CCITT (polynomial 0x1021: x^16 + x^12 + x^5 + 1)
|
| 7 |
+
# Computes one step of CRC given current CRC state and input bit
|
| 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 |
+
# Inputs: C[15:0] (16 bits), D (1 bit) = 17 inputs total
|
| 14 |
+
|
| 15 |
+
# Feedback = C15 XOR D
|
| 16 |
+
add_neuron('fb_or', [1.0] + [0.0]*15 + [1.0], -1.0)
|
| 17 |
+
add_neuron('fb_nand', [-1.0] + [0.0]*15 + [-1.0], 1.0)
|
| 18 |
+
|
| 19 |
+
# Shift neurons
|
| 20 |
+
for i in range(16):
|
| 21 |
+
w = [0.0] * 17
|
| 22 |
+
if i < 15:
|
| 23 |
+
w[i+1] = 1.0 # Shift from next position
|
| 24 |
+
add_neuron(f'c{i}_shift', w, -1.0 if i < 15 else 0.0)
|
| 25 |
+
|
| 26 |
+
save_file(weights, 'model.safetensors')
|
| 27 |
+
|
| 28 |
+
def crc16_step(crc, data_bit, poly=0x1021):
|
| 29 |
+
feedback = ((crc >> 15) ^ data_bit) & 1
|
| 30 |
+
crc = (crc << 1) & 0xFFFF
|
| 31 |
+
if feedback:
|
| 32 |
+
crc ^= poly
|
| 33 |
+
return crc
|
| 34 |
+
|
| 35 |
+
print("Verifying CRC-16 step function...")
|
| 36 |
+
errors = 0
|
| 37 |
+
# Test subset (full test would be 2^17 cases)
|
| 38 |
+
for crc in [0, 0x1234, 0xFFFF, 0x8000, 0x0001]:
|
| 39 |
+
for d in [0, 1]:
|
| 40 |
+
result = crc16_step(crc, d)
|
| 41 |
+
fb = ((crc >> 15) ^ d) & 1
|
| 42 |
+
expected = ((crc << 1) & 0xFFFF) ^ (0x1021 if fb else 0)
|
| 43 |
+
if result != expected:
|
| 44 |
+
errors += 1
|
| 45 |
+
|
| 46 |
+
if errors == 0:
|
| 47 |
+
print("All test cases passed!")
|
| 48 |
+
else:
|
| 49 |
+
print(f"FAILED: {errors} errors")
|
| 50 |
+
|
| 51 |
+
# Test with message
|
| 52 |
+
msg = [0, 1, 0, 1, 0, 1, 0, 1]
|
| 53 |
+
crc = 0xFFFF # Standard initial value
|
| 54 |
+
for bit in msg:
|
| 55 |
+
crc = crc16_step(crc, bit)
|
| 56 |
+
print(f"CRC-16 of message: 0x{crc:04X}")
|
| 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:2f08603dde686d12c8a9254ef94f01c8c1a2d2b833b7ead88ae2c5f12ceec02c
|
| 3 |
+
size 3896
|