File size: 778 Bytes
4009f50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import torch
from safetensors.torch import load_file

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

def isone8(a7, a6, a5, a4, a3, a2, a1, a0, weights):
    """Returns 1 if 8-bit input equals 1 (00000001), else 0"""
    inp = torch.tensor([float(a7), float(a6), float(a5), float(a4),
                        float(a3), float(a2), float(a1), float(a0)])
    return int((inp @ weights['neuron.weight'].T + weights['neuron.bias'] >= 0).item())

if __name__ == '__main__':
    w = load_model()
    print('isone8 selected tests:')
    for i in [0, 1, 2, 127, 128, 255]:
        bits = [(i >> (7-j)) & 1 for j in range(8)]
        result = isone8(*bits, w)
        marker = ' <-- ONE' if result else ''
        print(f'  {i:3d} ({i:08b}) -> {result}{marker}')