File size: 582 Bytes
0ff50a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import torch
from safetensors.torch import load_file

def load_model(path='model.safetensors'):
    return load_file(path)

def atmost7(bits, weights):
    """At-most-7-out-of-8: fires when 7 or fewer inputs are active (NOT all)."""
    inp = torch.tensor([float(b) for b in bits])
    return int((inp * weights['weight']).sum() + weights['bias'] >= 0)

if __name__ == '__main__':
    w = load_model()
    print('AtMost7OutOf8: HW <= 7 (i.e., NOT unanimity)')
    for hw in range(9):
        bits = [1]*hw + [0]*(8-hw)
        print(f'HW={hw}: {atmost7(bits, w)}')