phanerozoic's picture
Upload folder using huggingface_hub
d250ae9 verified
import torch
from safetensors.torch import load_file
def load_model(path='model.safetensors'):
return load_file(path)
def prefix_or(x3, x2, x1, x0, w):
inp = torch.tensor([float(x3), float(x2), float(x1), float(x0)])
y3 = int((inp @ w['y3.weight'].T + w['y3.bias'] >= 0).item())
y2 = int((inp @ w['y2.weight'].T + w['y2.bias'] >= 0).item())
y1 = int((inp @ w['y1.weight'].T + w['y1.bias'] >= 0).item())
y0 = int((inp @ w['y0.weight'].T + w['y0.bias'] >= 0).item())
return y3, y2, y1, y0
if __name__ == '__main__':
w = load_model()
print('Prefix-OR selected tests:')
for i in [0b0000, 0b0001, 0b0010, 0b0100, 0b1000, 0b1111]:
x3, x2, x1, x0 = (i >> 3) & 1, (i >> 2) & 1, (i >> 1) & 1, i & 1
y3, y2, y1, y0 = prefix_or(x3, x2, x1, x0, w)
print(f'{x3}{x2}{x1}{x0} -> {y3}{y2}{y1}{y0}')