Skip to content

Commit

Permalink
added codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
justanhduc committed Aug 17, 2020
1 parent ed5c9fd commit 6bda19f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 67 deletions.
13 changes: 10 additions & 3 deletions .travis.yml
Expand Up @@ -21,7 +21,8 @@ install:
- ./.travis/travis_install.sh
- source activate pyenv
- conda install -y pytorch torchvision cpuonly -c pytorch
- pip install pytest
- pip install pytest-cov pytest
- pip install codecov
- pip install flake8
- pip install -r requirements.txt
- pip install .
Expand All @@ -44,8 +45,14 @@ script:
- echo "$PART"
- python -c 'import torch; print(torch.__version__)'
- python -c 'import neuralnet_pytorch; print(neuralnet_pytorch.__version__)'
- python -m pytest -sv tests/
- python -m pytest -v --cov=neuralnet_pytorch/
- flake8 neuralnet_pytorch

env:
- CODECOV_TOKEN="41bdb269-8e93-42a6-a87d-65339e8145e9"

after_failure:
- cat /home/travis/.pip/pip.log
- cat /home/travis/.pip/pip.log

after_success:
- bash <(curl -s https://codecov.io/bash)
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -6,6 +6,7 @@
[![License](https://img.shields.io/github/license/justanhduc/neuralnet-pytorch.svg)](https://github.com/justanhduc/neuralnet-pytorch/blob/master/LICENSE.txt)
[![Build Status](https://travis-ci.org/justanhduc/neuralnet-pytorch.svg?branch=master)](https://travis-ci.org/justanhduc/neuralnet-pytorch)
[![Documentation Status](https://readthedocs.org/projects/neuralnet-pytorch/badge/?version=latest)](https://neuralnet-pytorch.readthedocs.io/en/latest/?badge=latest)
[![codecov](https://codecov.io/gh/justanhduc/neuralnet-pytorch/branch/master/graph/badge.svg)](https://codecov.io/gh/justanhduc/neuralnet-pytorch)

__A high level framework for general purpose neural networks in Pytorch.__

Expand Down Expand Up @@ -48,7 +49,7 @@ model = nnt.Sequential(input_shape=1)
model.add_module('conv1', nnt.Conv2d(model.output_shape, 20, 5, padding='half', activation='relu'))
model.add_module('conv2', nnt.Conv2d(model.output_shape, 64, 5, padding='half', activation='relu'))
```
which frees you from a lot of memorizations and manual calculations when adding one layer on top of another.
which frees you from a lot of memorization and manual calculations when adding one layer on top of another.
Theano folks will also find some reminiscence as many functions are highly inspired by Theano.

# Requirements
Expand Down
80 changes: 41 additions & 39 deletions tests/function_test.py
Expand Up @@ -142,49 +142,51 @@ def test_batch_pairwise_distance(device):
actual = nnt.utils.batch_pairwise_dist(xyz, xyz, c_code=False)
testing.assert_allclose(T.diag(actual[0]), T.zeros(actual.shape[1]).to(device))

if nnt.cuda_ext_available:
xyz1 = T.rand(10, 4000, 3).to(device).requires_grad_(True)
xyz2 = T.rand(10, 5000, 3).to(device)
expected = nnt.utils.batch_pairwise_dist(xyz1, xyz2, c_code=False)
actual = nnt.utils.batch_pairwise_dist(xyz1, xyz2, c_code=True)
testing.assert_allclose(actual, expected)
if dev != 'cuda' or not nnt.cuda_ext_available:
pytest.skip('Requires CUDA extension to be installed')

expected_cost = T.sum(expected)
expected_cost.backward()
expected_grad = xyz1.grad
xyz1.grad.zero_()
xyz1 = T.rand(10, 4000, 3).to(device).requires_grad_(True)
xyz2 = T.rand(10, 5000, 3).to(device)
expected = nnt.utils.batch_pairwise_dist(xyz1, xyz2, c_code=False)
actual = nnt.utils.batch_pairwise_dist(xyz1, xyz2, c_code=True)
testing.assert_allclose(actual, expected)

actual_cost = T.sum(actual)
actual_cost.backward()
actual_grad = xyz1.grad
testing.assert_allclose(actual_grad, expected_grad)
expected_cost = T.sum(expected)
expected_cost.backward()
expected_grad = xyz1.grad
xyz1.grad.zero_()

for _ in range(10):
t1 = nnt.utils.time_cuda_module(nnt.utils.batch_pairwise_dist, xyz1, xyz2, c_code=False)
t2 = nnt.utils.time_cuda_module(nnt.utils.batch_pairwise_dist, xyz1, xyz2, c_code=True)
print('pt: %f, cpp: %f' % (t1, t2))
actual_cost = T.sum(actual)
actual_cost.backward()
actual_grad = xyz1.grad
testing.assert_allclose(actual_grad, expected_grad)

for _ in range(10):
t1 = nnt.utils.time_cuda_module(nnt.utils.batch_pairwise_dist, xyz1, xyz2, c_code=False)
t2 = nnt.utils.time_cuda_module(nnt.utils.batch_pairwise_dist, xyz1, xyz2, c_code=True)
print('pt: %f, cpp: %f' % (t1, t2))


@pytest.mark.skipif(not nnt.cuda_ext_available, reason='Requires CUDA extension to be installed')
@pytest.mark.parametrize('device', dev)
def test_pointcloud_to_voxel(device):
if nnt.cuda_ext_available:
xyz = T.rand(10, 4000, 3).to(device).requires_grad_(True)
pc = xyz * 2. - 1.
expected = nnt.utils.pc2vox_fast(pc, c_code=False)
actual = nnt.utils.pc2vox_fast(pc, c_code=True)
testing.assert_allclose(actual, expected)

expected_cost = T.sum(expected)
expected_cost.backward(retain_graph=True)
expected_grad = xyz.grad
xyz.grad.zero_()

actual_cost = T.sum(actual)
actual_cost.backward()
actual_grad = xyz.grad
testing.assert_allclose(actual_grad, expected_grad)

for _ in range(10):
t1 = nnt.utils.time_cuda_module(nnt.utils.pc2vox_fast, pc, c_code=False)
t2 = nnt.utils.time_cuda_module(nnt.utils.pc2vox_fast, pc)
print('pt: %f, cpp: %f' % (t1, t2))
xyz = T.rand(10, 4000, 3).to(device).requires_grad_(True)
pc = xyz * 2. - 1.
expected = nnt.utils.pc2vox_fast(pc, c_code=False)
actual = nnt.utils.pc2vox_fast(pc, c_code=True)
testing.assert_allclose(actual, expected)

expected_cost = T.sum(expected)
expected_cost.backward(retain_graph=True)
expected_grad = xyz.grad
xyz.grad.zero_()

actual_cost = T.sum(actual)
actual_cost.backward()
actual_grad = xyz.grad
testing.assert_allclose(actual_grad, expected_grad)

for _ in range(10):
t1 = nnt.utils.time_cuda_module(nnt.utils.pc2vox_fast, pc, c_code=False)
t2 = nnt.utils.time_cuda_module(nnt.utils.pc2vox_fast, pc)
print('pt: %f, cpp: %f' % (t1, t2))
36 changes: 12 additions & 24 deletions tests/misc_test.py
Expand Up @@ -64,41 +64,29 @@ def test_monitor(device):
loaded = mon.load('foo.pkl')
testing.assert_allclose(a, loaded)

mon.epoch = 0
for epoch in mon.iter_epoch(range(n_epochs)):
for it in mon.iter_batch(range(n_iters)):
mon.dump('foo.pkl', a + it, keep=3)
mon.plot('parabol1', (it + epoch) ** 2)
mon.hist('histogram1', a + (it * epoch))
mon.imwrite('image', a[None, None])
mon.plot_matrix('random', a)

loaded = mon.load('foo.pkl', version=48)
testing.assert_allclose(a + 8., loaded)

mon.dump('foo.txt', nnt.utils.to_numpy(a), 'txt')
loaded = T.from_numpy(mon.load('foo.txt', 'txt', dtype='float32')).to(device)
testing.assert_allclose(a, loaded)

mon.epoch = 0
for epoch in mon.iter_epoch(range(n_epochs)):
for it in mon.iter_batch(range(n_iters)):
mon.plot('parabol2', (it + epoch) ** 2)
mon.hist('histogram2', a + (it * epoch))
mon.dump('foo.txt', nnt.utils.to_numpy(a + it), 'txt', keep=3)
loaded = T.from_numpy(mon.load('foo.txt', 'txt', version=48, dtype='float32')).to(device)
testing.assert_allclose(a + 8., loaded)

mon.dump('foo.pt', {'a': a}, 'torch')
loaded = mon.load('foo.pt', 'torch')['a']
testing.assert_allclose(a, loaded)

mon.epoch = 0
for epoch in mon.iter_epoch(range(n_epochs)):
for it in mon.iter_batch(range(n_iters)):
mon.plot('parabol3', (it + epoch) ** 2)
mon.hist('histogram3', a + (it * epoch))
mon.plot('parabol', (it + epoch) ** 2)
mon.hist('histogram', a + (it * epoch))
mon.imwrite('image', a[None, None])
mon.plot_matrix('random', a)
mon.dump('foo.pkl', a + it, keep=3)
mon.dump('foo.txt', nnt.utils.to_numpy(a + it), 'txt', keep=3)
mon.dump('foo.pt', {'a': a + it}, 'torch', keep=4)

loaded = mon.load('foo.pkl', version=48)
testing.assert_allclose(a + 8., loaded)
loaded = T.from_numpy(mon.load('foo.txt', 'txt', version=48, dtype='float32')).to(device)
testing.assert_allclose(a + 8., loaded)
loaded = mon.load('foo.pt', 'torch', version=49)['a']
testing.assert_allclose(a + 9, loaded)

Expand Down Expand Up @@ -143,7 +131,7 @@ def __init__(self, input_shape):
@pytest.mark.parametrize('pin_memory', (True, False))
def test_dataloader(device, bs, shuffle, drop_last, pin_memory):
if device == 'cpu' and pin_memory:
pytest.skip('Skip test for pin_memory=True and device=cpu')
pytest.skip('Wrong settings for pin_memory=True and device=cpu')

from torch.utils.data import TensorDataset
data, label = T.arange(10), T.arange(10) + 10
Expand Down

0 comments on commit 6bda19f

Please sign in to comment.