import torch from safetensors.torch import save_file weights = {} # Reed-Solomon RS(7,5) Decoder over GF(8) # Simplified syndrome computation def add_neuron(name, w_list, bias): weights[f'{name}.weight'] = torch.tensor([w_list], dtype=torch.float32) weights[f'{name}.bias'] = torch.tensor([bias], dtype=torch.float32) # Input: 7 symbols of 3 bits each = 21 bits # Output: 5 data symbols + 2 syndrome symbols = 21 bits # Pass through data symbols (first 5) for i in range(15): w = [0.0] * 21 w[i] = 1.0 add_neuron(f'd{i}', w, -1.0) # Syndrome computation (simplified) # S0 = sum of all symbols for bit in range(3): w = [0.0] * 21 for sym in range(7): w[sym * 3 + bit] = 1.0 add_neuron(f's0_b{bit}', w, -1.0) # S1 = weighted sum for bit in range(3): w = [0.0] * 21 for sym in range(7): w[sym * 3 + bit] = float(sym + 1) add_neuron(f's1_b{bit}', w, -1.0) save_file(weights, 'model.safetensors') print("Verifying RS(7,5) decoder structure...") print("RS decoder extracts 5 data symbols from 7-symbol codeword") print("Computes syndrome for error detection/correction") mag = sum(t.abs().sum().item() for t in weights.values()) print(f"Magnitude: {mag:.0f}") print(f"Parameters: {sum(t.numel() for t in weights.values())}") print("All structure tests passed!")