Make test_mnist runnable by pytest and directly
MODIFY
.github/workflows/test.yml
.github/workflows/test.yml
@@ -17,9 +17,6 @@ jobs:
with:
python-version: 3.8
- name: Install Dependencies
- run: pip install ipython numpy tqdm requests torch
- - name: Run mnist test
- run: ipython3 test/mnist.py
- - name: Run compare to torch test
- run: ipython3 test/test.py
-
+ run: pip install pytest numpy tqdm requests torch
+ - name: Run Pytest
+ run: python -m pytest -s -v

MODIFY
test/test_mnist.py
test/test_mnist.py
#!/usr/bin/env python
import os
+import unittest
import numpy as np
from tinygrad.tensor import Tensor
from tinygrad.utils import layer_init_uniform, fetch_mnist
-import tinygrad.optim as optim
+import tinygrad.optim as tinygrad_optim
from tqdm import trange
np.random.seed(1337)
@@ -33,13 +34,17 @@ class TinyConvNet:
x = x.conv2d(self.c1).reshape(Tensor(np.array((-1, 26*26*self.chans)))).relu()
return x.dot(self.l1).relu().dot(self.l2).logsoftmax()
+
+class TestMNIST(unittest.TestCase):
+
+ def test_mnist(self):
if os.getenv("CONV") == "1":
model = TinyConvNet()
- optim = optim.Adam([model.c1, model.l1, model.l2], lr=0.001)
+ optim = tinygrad_optim.Adam([model.c1, model.l1, model.l2], lr=0.001)
steps = 400
else:
model = TinyBobNet()
- optim = optim.SGD([model.l1, model.l2], lr=0.001)
+ optim = tinygrad_optim.SGD([model.l1, model.l2], lr=0.001)
steps = 1000
BS = 128
@@ -81,3 +86,5 @@ accuracy = numpy_eval()
print("test set accuracy is %f" % accuracy)
assert accuracy > 0.95
+if __name__ == '__main__':
+ unittest.main()

Make test_mnist runnable by pytest and directly