Download tests/test_vector_unit.py from StarAtNyte1/beam-boot: direct link, hf CLI and curl.
- Browser
- Download file 952 Bytes
-
https://huggingface.co/StarAtNyte1/beam-boot/resolve/main/tests/test_vector_unit.py
- Command line
-
hf download hf://StarAtNyte1/beam-boot/tests/test_vector_unit.py
-
curl -L -o test_vector_unit.py https://huggingface.co/StarAtNyte1/beam-boot/resolve/main/tests/test_vector_unit.py
952 Bytes
| import random | |
| import unittest | |
| from beamboot.vector_unit import VectorUnit, LANES, ROWS | |
| class VectorUnitTests(unittest.TestCase): | |
| def test_exact_int4_dot_against_reference(self): | |
| rng = random.Random(417) | |
| weights = [[rng.randint(-8, 7) for _ in range(LANES)] for _ in range(ROWS)] | |
| unit = VectorUnit(weights) | |
| for _ in range(300): | |
| row = rng.randrange(ROWS) | |
| acts = [rng.randint(0, 15) for _ in range(LANES)] | |
| expected = sum(w * a for w, a in zip(weights[row], acts)) | |
| self.assertEqual(unit.dot(row, acts), expected) | |
| def test_extremes(self): | |
| weights = [[-8]*LANES, [7]*LANES] + [[0]*LANES]*(ROWS-2) | |
| unit = VectorUnit(weights) | |
| self.assertEqual(unit.dot(0, [15]*LANES), -8*15*LANES) | |
| self.assertEqual(unit.dot(1, [15]*LANES), 7*15*LANES) | |
| self.assertEqual(unit.dot(2, [15]*LANES), 0) | |
| if __name__ == '__main__': | |
| unittest.main() | |