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-crc32
|
| 13 |
+
|
| 14 |
+
CRC-32 IEEE 802.3 step function. Polynomial: 0x04C11DB7.
|
| 15 |
+
|
| 16 |
+
## Parameters
|
| 17 |
+
|
| 18 |
+
| | |
|
| 19 |
+
|---|---|
|
| 20 |
+
| Polynomial | 0x04C11DB7 |
|
| 21 |
+
| Inputs | 33 |
|
| 22 |
+
| Outputs | 32 |
|
| 23 |
+
| Parameters | 1156 |
|
| 24 |
+
|
| 25 |
+
## License
|
| 26 |
+
|
| 27 |
+
MIT
|
config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "threshold-crc32",
|
| 3 |
+
"description": "CRC-32 IEEE single-bit step function",
|
| 4 |
+
"inputs": 33,
|
| 5 |
+
"outputs": 32,
|
| 6 |
+
"neurons": 34,
|
| 7 |
+
"layers": 2,
|
| 8 |
+
"parameters": 1156
|
| 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-32 (IEEE 802.3 polynomial)
|
| 7 |
+
# Polynomial: 0x04C11DB7
|
| 8 |
+
# Computes one step of CRC given current CRC state and input bit
|
| 9 |
+
|
| 10 |
+
def add_neuron(name, w_list, bias):
|
| 11 |
+
weights[f'{name}.weight'] = torch.tensor([w_list], dtype=torch.float32)
|
| 12 |
+
weights[f'{name}.bias'] = torch.tensor([bias], dtype=torch.float32)
|
| 13 |
+
|
| 14 |
+
# Inputs: C[31:0] (32 bits), D (1 bit) = 33 inputs
|
| 15 |
+
|
| 16 |
+
# Feedback = C31 XOR D
|
| 17 |
+
add_neuron('fb_or', [1.0] + [0.0]*31 + [1.0], -1.0)
|
| 18 |
+
add_neuron('fb_nand', [-1.0] + [0.0]*31 + [-1.0], 1.0)
|
| 19 |
+
|
| 20 |
+
# Shift neurons
|
| 21 |
+
for i in range(32):
|
| 22 |
+
w = [0.0] * 33
|
| 23 |
+
if i < 31:
|
| 24 |
+
w[i+1] = 1.0
|
| 25 |
+
add_neuron(f'c{i}_shift', w, -1.0 if i < 31 else 0.0)
|
| 26 |
+
|
| 27 |
+
save_file(weights, 'model.safetensors')
|
| 28 |
+
|
| 29 |
+
def crc32_step(crc, data_bit, poly=0x04C11DB7):
|
| 30 |
+
feedback = ((crc >> 31) ^ data_bit) & 1
|
| 31 |
+
crc = (crc << 1) & 0xFFFFFFFF
|
| 32 |
+
if feedback:
|
| 33 |
+
crc ^= poly
|
| 34 |
+
return crc
|
| 35 |
+
|
| 36 |
+
print("Verifying CRC-32 step function...")
|
| 37 |
+
errors = 0
|
| 38 |
+
for crc in [0, 0xFFFFFFFF, 0x12345678, 0x80000000]:
|
| 39 |
+
for d in [0, 1]:
|
| 40 |
+
result = crc32_step(crc, d)
|
| 41 |
+
fb = ((crc >> 31) ^ d) & 1
|
| 42 |
+
expected = ((crc << 1) & 0xFFFFFFFF) ^ (0x04C11DB7 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, 0, 1, 0, 0, 1] # ASCII 'I'
|
| 53 |
+
crc = 0xFFFFFFFF
|
| 54 |
+
for bit in msg:
|
| 55 |
+
crc = crc32_step(crc, bit)
|
| 56 |
+
print(f"CRC-32 partial: 0x{crc:08X}")
|
| 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:9e2be396f754a6c241218aa65c58dbbb19ffed252241b2bd9162ea2d053da1e7
|
| 3 |
+
size 9632
|