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

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

def iszero8(bits, weights):
    inp = torch.tensor([float(b) for b in bits])
    return int((inp @ weights['neuron.weight'].T + weights['neuron.bias'] >= 0).item())

if __name__ == '__main__':
    w = load_model()
    print('iszero8: outputs 1 only for input 00000000')
    for i in [0, 1, 128, 255]:
        bits = [(i >> j) & 1 for j in range(8)]
        print(f'  {i:08b} -> {iszero8(bits, w)}')