| import torch | |
| from safetensors.torch import load_file | |
| def load_model(path='model.safetensors'): | |
| return load_file(path) | |
| def demux16(d, s3, s2, s1, s0, weights): | |
| """1:16 Demultiplexer: routes d to output y[s]""" | |
| inp = torch.tensor([float(d), float(s3), float(s2), float(s1), float(s0)]) | |
| outputs = [] | |
| for i in range(16): | |
| y = int((inp * weights[f'y{i}.weight']).sum() + weights[f'y{i}.bias'] >= 0) | |
| outputs.append(y) | |
| return outputs | |
| if __name__ == '__main__': | |
| w = load_model() | |
| print('DEMUX16 verification:') | |
| for s in range(16): | |
| s3, s2, s1, s0 = (s >> 3) & 1, (s >> 2) & 1, (s >> 1) & 1, s & 1 | |
| result = demux16(1, s3, s2, s1, s0, w) | |
| hot = result.index(1) if 1 in result else -1 | |
| print(f' d=1, s={s:2d} ({s3}{s2}{s1}{s0}) -> y{hot}=1') | |