diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000000000000000000000000000000000..0e5cdddeddad80cee358b0f7e448826feba4dd10 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,34 @@ +language: python +cache: ccache +sudo: required +dist: trusty +services: + - docker +os: + - linux +env: + - JOB=PRE_COMMIT + +addons: + apt: + packages: + - git + - python + - python-pip + - python2.7-dev + ssh_known_hosts: 13.229.163.131 +before_install: + - sudo pip install -U virtualenv pre-commit pip + - docker pull paddlepaddle/paddle:latest + +script: + - exit_code=0 + - .travis/precommit.sh || exit_code=((exitcode|? )) + - docker run -i --rm -v "$PWD:/py_unittest" paddlepaddle/paddle:latest /bin/bash -c + 'cd /py_unittest; sh .travis/unittest.sh' || exit_code=((exitcode|? )) + - if [ $exit_code -eq 0 ]; then true; else exit 1; fi; + +notifications: + email: + on_success: change + on_failure: always diff --git a/.travis/precommit.sh b/.travis/precommit.sh new file mode 100644 index 0000000000000000000000000000000000000000..df98fe4bbd38c4ef6a57fec20f156f21210c7467 --- /dev/null +++ b/.travis/precommit.sh @@ -0,0 +1,21 @@ +#!/bin/bash +function abort(){ + echo "Your commit not fit PaddleSlim code style" 1>&2 + echo "Please use pre-commit scripts to auto-format your code" 1>&2 + exit 1 +} + +trap 'abort' 0 +set -e +cd `dirname $0` +cd .. +export PATH=/usr/bin:$PATH +pre-commit install + +if ! pre-commit run -a ; then + ls -lh + git diff --exit-code + exit 1 +fi + +trap : 0 diff --git a/tests/test_flops.py b/tests/test_flops.py index cd16b8618d0271e6a0b7e609f8820e16c380b9db..02e2d46deb9c17899a11a02d83d6407c93e43999 100644 --- a/tests/test_flops.py +++ b/tests/test_flops.py @@ -33,7 +33,8 @@ class TestPrune(unittest.TestCase): sum2 = conv4 + sum1 conv5 = conv_bn_layer(sum2, 8, 3, "conv5") conv6 = conv_bn_layer(conv5, 8, 3, "conv6") - self.assertTrue(1597440 == flops(main_program)) + print flops(main_program) + self.assertTrue(792576 == flops(main_program)) if __name__ == '__main__': diff --git a/tests/test_sensitivity.py b/tests/test_sensitivity.py index e2cfa01d889db2891fd7507b2d4d9aec018a1163..e687e32d6423fa4283da88353ee94c42bc70d44f 100644 --- a/tests/test_sensitivity.py +++ b/tests/test_sensitivity.py @@ -17,7 +17,7 @@ import unittest import numpy import paddle import paddle.fluid as fluid -from paddleslim.analysis import sensitivity +from paddleslim.prune import sensitivity from layers import conv_bn_layer @@ -46,13 +46,12 @@ class TestSensitivity(unittest.TestCase): val_reader = paddle.batch(paddle.dataset.mnist.test(), batch_size=128) - def eval_func(program, scope): + def eval_func(program): feeder = fluid.DataFeeder( feed_list=['image', 'label'], place=place, program=program) acc_set = [] for data in val_reader(): acc_np = exe.run(program=program, - scope=scope, feed=feeder.feed(data), fetch_list=[acc_top1]) acc_set.append(float(acc_np[0])) @@ -60,8 +59,7 @@ class TestSensitivity(unittest.TestCase): print("acc_val_mean: {}".format(acc_val_mean)) return acc_val_mean - sensitivity(eval_program, - fluid.global_scope(), place, ["conv4_weights"], eval_func, + sensitivity(eval_program, place, ["conv4_weights"], eval_func, "./sensitivities_file")