| import torch | |
| from safetensors.torch import save_file | |
| weights = { | |
| 'neuron.weight': torch.tensor([[1.0, 1.0, 1.0, 1.0, 1.0, 1.0]], dtype=torch.float32), | |
| 'neuron.bias': torch.tensor([-6.0], dtype=torch.float32) | |
| } | |
| save_file(weights, 'model.safetensors') | |
| def test(bits): | |
| inputs = torch.tensor([float(b) for b in bits]) | |
| return int((inputs @ weights['neuron.weight'].T + weights['neuron.bias'] >= 0).item()) | |
| print("Verifying 6-out-of-6...") | |
| errors = 0 | |
| for i in range(64): | |
| bits = [(i >> j) & 1 for j in range(6)] | |
| result = test(bits) | |
| expected = 1 if sum(bits) >= 6 else 0 | |
| if result != expected: | |
| errors += 1 | |
| if errors == 0: | |
| print("All 64 test cases passed!") | |
| else: | |
| print(f"FAILED: {errors} errors") | |
| print(f"Magnitude: {sum(t.abs().sum().item() for t in weights.values()):.0f}") | |