From 380fc251f440f42485170ee9dbff239fa3e1550b Mon Sep 17 00:00:00 2001 From: FengZiYjun Date: Sat, 11 Aug 2018 10:11:09 +0800 Subject: [PATCH 1/5] add code coverage --- .travis.yml | 13 +++++++++++++ README.md | 2 ++ 2 files changed, 15 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..077bd1c4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +language: python +python: + - "3.6" +# command to install dependencies +install: + - pip install --quiet -r requirements.txt + - pip install pytest pytest-cov +# command to run tests +script: + - pytest --cov=./ + +after_success: + - codecov \ No newline at end of file diff --git a/README.md b/README.md index 71357775..4068febc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # FastNLP +[![Build Status](https://travis-ci.org/fastnlp/fastNLP.svg?branch=master)](https://travis-ci.org/fastnlp/fastNLP) +[![codecov](https://codecov.io/gh/fastnlp/fastNLP/branch/master/graph/badge.svg)](https://codecov.io/gh/fastnlp/fastNLP) ``` FastNLP ├── docs From 2961afd326c5bb4273523ff555587b58f8203139 Mon Sep 17 00:00:00 2001 From: choosewhatulike <1901722105@qq.com> Date: Sun, 12 Aug 2018 19:55:19 +0800 Subject: [PATCH 2/5] remove unused file --- fastNLP/action/optimizer.py | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 fastNLP/action/optimizer.py diff --git a/fastNLP/action/optimizer.py b/fastNLP/action/optimizer.py deleted file mode 100644 index b493e3f0..00000000 --- a/fastNLP/action/optimizer.py +++ /dev/null @@ -1,5 +0,0 @@ -''' -use optimizer from Pytorch -''' - -from torch.optim import * \ No newline at end of file From d6ef1322071234483b8087bcf651d4fcd2b87a32 Mon Sep 17 00:00:00 2001 From: choosewhatulike <1901722105@qq.com> Date: Sun, 12 Aug 2018 20:04:38 +0800 Subject: [PATCH 3/5] fix test_metrics bug --- fastNLP/core/metrics.py | 1 - test/test_metrics.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/fastNLP/core/metrics.py b/fastNLP/core/metrics.py index ad22eed5..089ee4f7 100644 --- a/fastNLP/core/metrics.py +++ b/fastNLP/core/metrics.py @@ -9,7 +9,6 @@ To do: """ import numpy as np import torch -import sklearn.metrics as M import warnings def _conver_numpy(x): diff --git a/test/test_metrics.py b/test/test_metrics.py index 47007106..4d4d7e05 100644 --- a/test/test_metrics.py +++ b/test/test_metrics.py @@ -1,7 +1,7 @@ import sys, os sys.path = [os.path.join(os.path.dirname(__file__), '..')] + sys.path -from fastNLP.action import metrics +from fastNLP.core import metrics from sklearn import metrics as skmetrics import unittest import numpy as np From 762a559fab31f7d245a8163cb20cef3f8f250929 Mon Sep 17 00:00:00 2001 From: Yunfan Shao <15307130288@fudan.edu.cn> Date: Tue, 14 Aug 2018 00:10:44 +0800 Subject: [PATCH 4/5] fix bug in SeqLabelTester --- fastNLP/core/tester.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fastNLP/core/tester.py b/fastNLP/core/tester.py index 3799eed1..1e7b654a 100644 --- a/fastNLP/core/tester.py +++ b/fastNLP/core/tester.py @@ -59,6 +59,8 @@ class BaseTester(object): self.batch_output.append(prediction) if self.save_loss: self.eval_history.append(eval_results) + if step % n_print == 0: + print('[test step: {:>4}]'.format(step)) step += 1 def prepare_input(self, data_path): @@ -134,7 +136,7 @@ class SeqLabelTester(BaseTester): results = torch.Tensor(prediction).view(-1,) # make sure "results" is in the same device as "truth" results = results.to(truth) - accuracy = torch.sum(results == truth.view((-1,))) / results.shape[0] + accuracy = torch.sum(results == truth.view((-1,))).to(torch.float) / results.shape[0] return [loss.data, accuracy.data] def metrics(self): @@ -153,7 +155,6 @@ class SeqLabelTester(BaseTester): def make_batch(self, iterator, data): return Action.make_batch(iterator, data, use_cuda=self.use_cuda, output_length=True) - class ClassificationTester(BaseTester): """Tester for classification.""" From 8a87807274735046a48be8eb4b1ca10801875039 Mon Sep 17 00:00:00 2001 From: choosewhatulike <1901722105@qq.com> Date: Tue, 14 Aug 2018 00:35:48 +0800 Subject: [PATCH 5/5] set no_grad() for test & inference, reduce memory usage --- fastNLP/core/inference.py | 4 ++-- fastNLP/core/tester.py | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/fastNLP/core/inference.py b/fastNLP/core/inference.py index 3937e3f4..d4f53164 100644 --- a/fastNLP/core/inference.py +++ b/fastNLP/core/inference.py @@ -76,8 +76,8 @@ class Inference(object): iterator = iter(Batchifier(SequentialSampler(data), self.batch_size, drop_last=False)) for batch_x in self.make_batch(iterator, data, use_cuda=False): - - prediction = self.data_forward(network, batch_x) + with torch.no_grad(): + prediction = self.data_forward(network, batch_x) self.batch_output.append(prediction) diff --git a/fastNLP/core/tester.py b/fastNLP/core/tester.py index 1e7b654a..e08ac894 100644 --- a/fastNLP/core/tester.py +++ b/fastNLP/core/tester.py @@ -50,10 +50,9 @@ class BaseTester(object): step = 0 for batch_x, batch_y in self.make_batch(iterator, dev_data): - - prediction = self.data_forward(network, batch_x) - - eval_results = self.evaluate(prediction, batch_y) + with torch.no_grad(): + prediction = self.data_forward(network, batch_x) + eval_results = self.evaluate(prediction, batch_y) if self.save_output: self.batch_output.append(prediction)