Skip to content

Commit

Permalink
Basic test working
Browse files Browse the repository at this point in the history
  • Loading branch information
ErisMik committed Apr 10, 2024
1 parent f1882f8 commit f7796af
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ jobs:
python3 setup.py sdist bdist_wheel
pip3 install --force-reinstall dist/pvmvm-0.1.0-py3-none-any.whl
# - name: Download resource files
# run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/xpu/res/mvm-weights-4096x4096x256.bin/latest/mvm-weights-4096x4096x256.bin -o mvm-weights-4096x4096x256.bin
- name: Download resource files
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.bin/latest/phi2-290.bin -o phi2-290.bin

- name: Test
run: python3 mvm_demo_file.py --input_weight_file ./mvm-weights-4096x4096x256.bin
4 changes: 2 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
run: pip3 install -r requirements.txt

- name: Download resource files
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/xpu/res/mvm-weights-4096x4096x256.bin/latest/mvm-weights-4096x4096x256.bin -o mvm-weights-4096x4096x256.bin
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.bin/latest/phi2-290.bin -o phi2-290.bin

- name: Test
run: python3 test_mvm.py ./mvm-weights-4096x4096x256.bin
run: python3 test_picollm.py ${{secrets.PV_VALID_ACCESS_KEY}} ./phi2-290.bin
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.DS_Store
.idea
__pycache__
mvm-weights*.bin
*.bin
80 changes: 44 additions & 36 deletions binding/python/test_picollm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,65 +14,73 @@

import numpy as np

from _picollm import Picollm, PicollmError
from _picollm import PicoLLM
from _util import *


class PicollmTestCase(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls._access_key = sys.argv[1]
cls._model_path = sys.argv[2]

def setUp(self):
self._picollm = Picollm(device_string="best:0", library_path=pv_library_path('../..'))
self._picollm = PicoLLM(
access_key=self._access_key,
model_path=self._model_path,
library_path=pv_library_path('../..'))

def tearDown(self):
self._picollm.delete()
self._picollm.release()

def test_load_chunk(self):
with open(sys.argv[1], 'rb') as model_file:
model_loaded = False
while not model_loaded:
data = model_file.read(self._picollm.max_chunk_size)
if not data:
break
model_loaded = self._picollm.load_model_chunk(data)
self.assertTrue(model_loaded)
# def test_load_chunk(self):
# with open(sys.argv[1], 'rb') as model_file:
# model_loaded = False
# while not model_loaded:
# data = model_file.read(self._picollm.max_chunk_size)
# if not data:
# break
# model_loaded = self._picollm.load_model_chunk(data)
# self.assertTrue(model_loaded)

def test_chain_multiply(self):
self._picollm.load_model_file(sys.argv[1])
# def test_chain_multiply(self):
# self._picollm.load_model_file(sys.argv[1])

_, matrix_n = self._picollm.matrix_dimensions()
vector = [1.0] * matrix_n
# _, matrix_n = self._picollm.matrix_dimensions()
# vector = [1.0] * matrix_n

result_vector = self._picollm.chain_multiply(vector)
# result_vector = self._picollm.chain_multiply(vector)

self.assertEqual(len(vector), len(result_vector))
# self.assertEqual(len(vector), len(result_vector))

def test_version(self):
self.assertIsInstance(self._picollm.version, str)

def test_message_stack(self):
relative_path = '../..'
# def test_message_stack(self):
# relative_path = '../..'

error = None
try:
c = Picollm(device_string="invalid", library_path=pv_library_path(relative_path))
self.assertIsNone(c)
except PicollmError as e:
error = e.message_stack
# error = None
# try:
# c = Picollm(device_string="invalid", library_path=pv_library_path(relative_path))
# self.assertIsNone(c)
# except PicollmError as e:
# error = e.message_stack

self.assertIsNotNone(error)
self.assertGreater(len(error), 0)
# self.assertIsNotNone(error)
# self.assertGreater(len(error), 0)

try:
c = Picollm(device_string="invalid", library_path=pv_library_path(relative_path))
self.assertIsNone(c)
except PicollmError as e:
self.assertEqual(len(error), len(e.message_stack))
self.assertListEqual(list(error), list(e.message_stack))
# try:
# c = Picollm(device_string="invalid", library_path=pv_library_path(relative_path))
# self.assertIsNone(c)
# except PicollmError as e:
# self.assertEqual(len(error), len(e.message_stack))
# self.assertListEqual(list(error), list(e.message_stack))


if __name__ == '__main__':
if len(sys.argv) != 2:
print("usage: test_picollm.py ${WeightFile}")
if len(sys.argv) != 3:
print("usage: test_picollm.py ${AccessKey} ${ModelFile}")
exit(1)

unittest.main(argv=sys.argv[:1])
File renamed without changes.
Binary file removed lib/linux/x86_64/libpv_mvm.so
Binary file not shown.
Binary file added lib/linux/x86_64/libpv_picollm.so
Binary file not shown.

0 comments on commit f7796af

Please sign in to comment.