import torch from safetensors.torch import save_file weights = {} # Input: [a3, a2, a1, a0], Output: [a2, a1, a0, a3] (MSB wraps to LSB) weights['y3.weight'] = torch.tensor([[0.0, 1.0, 0.0, 0.0]], dtype=torch.float32) weights['y3.bias'] = torch.tensor([-1.0], dtype=torch.float32) weights['y2.weight'] = torch.tensor([[0.0, 0.0, 1.0, 0.0]], dtype=torch.float32) weights['y2.bias'] = torch.tensor([-1.0], dtype=torch.float32) weights['y1.weight'] = torch.tensor([[0.0, 0.0, 0.0, 1.0]], dtype=torch.float32) weights['y1.bias'] = torch.tensor([-1.0], dtype=torch.float32) weights['y0.weight'] = torch.tensor([[1.0, 0.0, 0.0, 0.0]], dtype=torch.float32) weights['y0.bias'] = torch.tensor([-1.0], dtype=torch.float32) save_file(weights, 'model.safetensors') print("Verifying rotateleft4...") errors = 0 for i in range(16): a3, a2, a1, a0 = (i >> 3) & 1, (i >> 2) & 1, (i >> 1) & 1, i & 1 inp = torch.tensor([float(a3), float(a2), float(a1), float(a0)]) result = [int((inp @ weights[f'y{j}.weight'].T + weights[f'y{j}.bias'] >= 0).item()) for j in [3,2,1,0]] expected = [a2, a1, a0, a3] if result != expected: errors += 1 print(f"ERROR: {a3}{a2}{a1}{a0} -> {result}, expected {expected}") if errors == 0: print("All 16 test cases passed!") print(f"Magnitude: {sum(t.abs().sum().item() for t in weights.values()):.0f}")