Skip to content

Commit 8a430bb

Browse files
committed
Remove fastai tests using 1.x api
1 parent 23270a6 commit 8a430bb

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ RUN pip install bcolz && \
432432
# Don't install dependencies for fastai because it requires pytorch<0.4.
433433
# which downgrades pytorch. fastai does work with pytorch 0.4.
434434
pip install fastai==0.7.0 --no-deps && \
435+
pip install torchtext && \
435436
# clean up pip cache
436437
rm -rf /root/.cache/pip/* && \
437438
cd && rm -rf /usr/local/src/*

tests/test_fastai.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,40 @@
44
import pandas as pd
55
import torch
66

7-
from fastai.tabular import tabular_data_from_df, get_tabular_learner
87
from fastai.core import partition
9-
from fastai.torch_core import tensor
8+
from fastai.layer_optimizer import LayerOptimizer
109

1110
class TestFastAI(unittest.TestCase):
1211
def test_partition(self):
1312
result = partition([1,2,3,4,5], 2)
1413

1514
self.assertEqual(3, len(result))
1615

17-
def test_has_version(self):
18-
self.assertGreater(len(fastai.__version__), 1)
19-
20-
# based on https://github.com/fastai/fastai/blob/master/tests/test_torch_core.py#L17
21-
def test_torch_tensor(self):
22-
a = tensor([1, 2, 3])
23-
b = torch.tensor([1, 2, 3])
16+
# based on https://github.com/fastai/fastai/blob/0.7.0/tests/test_layer_optimizer.py
17+
def test_layer_optimizer(self):
18+
lo = LayerOptimizer(FakeOpt, fastai_params_('A', 'B', 'C'), 1e-2, 1e-4)
19+
fast_check_optimizer_(lo.opt, [(nm, 1e-2, 1e-4) for nm in 'ABC'])
2420

25-
self.assertTrue(torch.all(a == b))
2621

27-
def test_tabular(self):
28-
df = pd.read_csv("/input/tests/data/train.csv")
22+
class Par(object):
23+
def __init__(self, x, grad=True):
24+
self.x = x
25+
self.requires_grad = grad
26+
def parameters(self): return [self]
2927

30-
train_df, valid_df = df[:-5].copy(),df[-5:].copy()
31-
dep_var = "label"
32-
cont_names = []
33-
for i in range(784):
34-
cont_names.append("pixel" + str(i))
3528

36-
data = tabular_data_from_df("", train_df, valid_df, dep_var, cont_names=cont_names, cat_names=[])
37-
learn = get_tabular_learner(data, layers=[200, 100])
38-
learn.fit(epochs=1)
29+
class FakeOpt(object):
30+
def __init__(self, params): self.param_groups = params
31+
32+
33+
def fastai_params_(*names): return [Par(nm) for nm in names]
34+
35+
def fast_check_optimizer_(opt, expected):
36+
actual = opt.param_groups
37+
assert len(actual) == len(expected)
38+
for (a, e) in zip(actual, expected): fastai_check_param_(a, *e)
39+
40+
def fastai_check_param_(par, nm, lr, wd):
41+
assert par['params'][0].x == nm
42+
assert par['lr'] == lr
43+
assert par['weight_decay'] == wd

0 commit comments

Comments
 (0)