Skip to content

Commit 24bb995

Browse files
committed
Restore testability
__Solution__: When running tests from the command line, ___always__ import the module `-m unittest` and use the verbose (`-v`) flag to see where Python is breaking up. * Then you'll be able to trace down the problem. * Do this a few times, and it will be reflex
1 parent b085293 commit 24bb995

File tree

8 files changed

+49
-6
lines changed

8 files changed

+49
-6
lines changed

demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import morph.nn as net
77
from morph.layers.sparse import sparsify
88

9-
from morph._models import EasyMnist
9+
from morph.testing.models import EasyMnist
1010

1111

1212
def random_dataset():
@@ -19,7 +19,7 @@ def main():
1919

2020
print(modified) # take a peek at the new layers. You take it from here
2121

22-
my_dataloader = DataLoader(random_dataset)
22+
my_dataloader = DataLoader(random_dataset())
2323

2424
# get back the class that will do work
2525
morphed = net.Morph(my_model, epochs=5, dataloader=my_dataloader)

morph/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .nn.morph import once # facility tate "morph.once"
1+
from .nn import once # facilitate "morph.once"

morph/layers/widen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import torch.nn as nn
55

66
from ..nn.utils import layer_has_bias, redo_layer
7-
from .._utils import check, round
7+
from ..utils import check, round
88

99

1010
# NOTE: should factor be {smaller, default at all}?

morph/layers/widen_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import unittest
2+
3+
from .widen import widen, nn
4+
from .._error import ValidationError
5+
6+
7+
class TestWiden_Functional(unittest.TestCase):
8+
9+
DUD_LINEAR = nn.Linear(1, 1)
10+
11+
def test_widen_width_factor_too_small_should_fail(self):
12+
with self.assertRaises(ValidationError):
13+
widen(self.DUD_LINEAR, 0.8)
14+
15+
def test_widen_width_factor_identity_should_fail(self):
16+
with self.assertRaises(ValidationError):
17+
widen(self.DUD_LINEAR, 1.0)
18+
19+
def test_widen_width_factor_increases_layer_generously(self):
20+
pass
21+
22+
23+
if __name__ == "__main__":
24+
unittest.main()

morph/nn/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import torch.nn as nn
22

33
from morph.nn._types import type_name, type_supported
4-
from morph._utils import check
4+
from morph.utils import check
55

66
from typing import List, Tuple, TypeVar
77

8-
ML = TypeVar('MODULES', List[nn.Module])
8+
ML = List[nn.Module]
99
# Type constrained to be the results of nn.Module.children() or ...named_children()
1010
CL = TypeVar('MODULE_CHILDREN_LIST', ML, List[Tuple[str, nn.Module]])
1111

File renamed without changes.
File renamed without changes.

morph/utils_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import unittest
2+
3+
from .utils import round
4+
5+
class TestGlobalUtilities(unittest.TestCase):
6+
7+
def test_round_down(self):
8+
test = 1.2
9+
expected = 1
10+
self.assertEqual(expected, round(test), '1.2 should round DOWN, to 1')
11+
12+
def test_round_up(self):
13+
test = 1.7
14+
expected = 2
15+
self.assertEqual(expected, round(test), '1.7 should round UP, to 2')
16+
17+
18+
if __name__ == "__main__":
19+
unittest.main()

0 commit comments

Comments
 (0)