threshold-mod11 / model.py
phanerozoic's picture
Rename from tiny-mod11-verified
120c7c1 verified
"""
Threshold Network for MOD-11 Circuit
For 8-bit inputs, HW ranges 0-8, all less than 11, so HW mod 11 = HW.
"""
import torch
from safetensors.torch import load_file
class ThresholdMod11:
def __init__(self, weights_dict):
self.weight = weights_dict['weight']
self.bias = weights_dict['bias']
def __call__(self, bits):
inputs = torch.tensor([float(b) for b in bits])
return (inputs * self.weight).sum() + self.bias
@classmethod
def from_safetensors(cls, path="model.safetensors"):
return cls(load_file(path))