import torch from safetensors.torch import load_file def load_model(path='model.safetensors'): return load_file(path) def isone4(a3, a2, a1, a0, weights): """Returns 1 if 4-bit input equals 1 (0001), else 0""" inp = torch.tensor([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('isone4 truth table:') for i in range(16): a3, a2, a1, a0 = (i >> 3) & 1, (i >> 2) & 1, (i >> 1) & 1, i & 1 result = isone4(a3, a2, a1, a0, w) marker = ' <-- ONE' if result else '' print(f' {a3}{a2}{a1}{a0} (={i:2d}) -> {result}{marker}')