| import torch | |
| from safetensors.torch import load_file | |
| def load_model(path='model.safetensors'): | |
| return load_file(path) | |
| def atmost2(bits, weights): | |
| """At-most-2-out-of-8: fires when 0, 1, or 2 inputs are active.""" | |
| 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('AtMost2OutOf8 truth table:') | |
| for hw in range(9): | |
| bits = [1]*hw + [0]*(8-hw) | |
| result = atmost2(bits, w) | |
| print(f'HW={hw}: {result}') | |