File size: 608 Bytes
9326225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 carry_generate(a, b, weights):
    """Carry generate signal: G = a AND b."""
    inp = torch.tensor([float(a), float(b)])
    return int((inp @ weights['and.weight'].T + weights['and.bias'] >= 0).item())

if __name__ == '__main__':
    w = load_model()
    print('Carry Generate (G = a AND b):')
    print('a b | G')
    print('----+--')
    for a in [0, 1]:
        for b in [0, 1]:
            g = carry_generate(a, b, w)
            print(f'{a} {b} | {g}')