File size: 832 Bytes
df35550
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import torch
from safetensors.torch import load_file

def load_model(path='model.safetensors'):
    return load_file(path)

def popcount8(a7, a6, a5, a4, a3, a2, a1, a0, weights):
    """8-bit population count: returns count of 1 bits as 4-bit value"""
    inp = torch.tensor([float(a7), float(a6), float(a5), float(a4),
                        float(a3), float(a2), float(a1), float(a0)])
    # See create_safetensors.py for full implementation
    # Returns [y3, y2, y1, y0] where y3y2y1y0 is the count in binary
    pass

if __name__ == '__main__':
    w = load_model()
    print('Popcount8 examples:')
    examples = [0b00000000, 0b00000001, 0b01010101, 0b11111111, 0b11110000]
    for val in examples:
        bits = [(val >> j) & 1 for j in range(7, -1, -1)]
        count = sum(bits)
        print(f'  {val:08b} -> {count}')