diff --git a/tests/test_darts.py b/tests/test_darts.py index 63383ea46f4cd368f30de8115f1fcb3b0e5f7eaf..9c6a5817c466aa11ae7f440fae64df9e6960f60d 100644 --- a/tests/test_darts.py +++ b/tests/test_darts.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import sys +sys.path.append("../") import paddle import unittest import paddle.fluid as fluid diff --git a/tests/test_earlystop.py b/tests/test_earlystop.py index 6af4de6df5336dc9c3faa97cf48f73df00fc2d5d..62ea3ed08b2a09b6ab58b794021b7c7eeaee936b 100644 --- a/tests/test_earlystop.py +++ b/tests/test_earlystop.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import sys +sys.path.append("../") import unittest import paddle from paddleslim.nas import SANAS diff --git a/tests/test_quant_embedding.py b/tests/test_quant_embedding.py index 107ce32ea536c87c8e92f047c89dcdd4b5ea766c..028d4a6183676ec596cf5cb80a5b1ba76b7bb90a 100644 --- a/tests/test_quant_embedding.py +++ b/tests/test_quant_embedding.py @@ -1,3 +1,18 @@ +# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License" +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys +sys.path.append("../") import paddle.fluid as fluid import paddleslim.quant as quant import unittest diff --git a/tests/test_quant_post_only_weight.py b/tests/test_quant_post_only_weight.py index e90b13e6fe54dc75f6f361b55f3a0581a6c9a7d1..ede4094dc2c7017cdad36669c51c4195e17fa498 100644 --- a/tests/test_quant_post_only_weight.py +++ b/tests/test_quant_post_only_weight.py @@ -77,9 +77,8 @@ class TestQuantPostOnlyWeightCase1(unittest.TestCase): fetch_list=outputs) iter += 1 if iter % 100 == 0: - print( - 'eval iter={}, avg loss {}, acc_top1 {}, acc_top5 {}'. - format(iter, cost, top1, top5)) + print('eval iter={}, avg loss {}, acc_top1 {}, acc_top5 {}'. + format(iter, cost, top1, top5)) result[0].append(cost) result[1].append(top1) result[2].append(top5) @@ -99,7 +98,7 @@ class TestQuantPostOnlyWeightCase1(unittest.TestCase): params_filename='params') quant_post_dynamic( - model_dir='./test_quant_post', + model_dir='./test_quant_post_dynamic', save_model_dir='./test_quant_post_inference', model_filename='model', params_filename='params', diff --git a/tests/test_rl_nas.py b/tests/test_rl_nas.py index cd81eaf15a1f71cf040898da63b6a27fb0b10af8..ba9c92210acb1bf0f6de6c1795d5255215dbfd16 100644 --- a/tests/test_rl_nas.py +++ b/tests/test_rl_nas.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import sys +sys.path.append("../") import unittest import paddle.fluid as fluid from paddleslim.nas import RLNAS diff --git a/tests/test_sa_nas.py b/tests/test_sa_nas.py index 8630136ef256075f6d83e934b9bb2e30f8d22ef6..1ba7df9befbcd1def0f5353c0c6f164494620ff9 100644 --- a/tests/test_sa_nas.py +++ b/tests/test_sa_nas.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import sys +sys.path.append("../") import os import sys import unittest @@ -19,24 +21,27 @@ from paddleslim.nas import SANAS from paddleslim.analysis import flops import numpy as np + def compute_op_num(program): params = {} ch_list = [] for block in program.blocks: for param in block.all_parameters(): - if len(param.shape) == 4: + if len(param.shape) == 4: params[param.name] = param.shape ch_list.append(int(param.shape[0])) return params, ch_list + class TestSANAS(unittest.TestCase): def setUp(self): self.init_test_case() port = np.random.randint(8337, 8773) - self.sanas = SANAS(configs=self.configs, server_addr=("", port), save_checkpoint=None) + self.sanas = SANAS( + configs=self.configs, server_addr=("", port), save_checkpoint=None) def init_test_case(self): - self.configs=[('MobileNetV2BlockSpace', {'block_mask':[0]})] + self.configs = [('MobileNetV2BlockSpace', {'block_mask': [0]})] self.filter_num = np.array([ 3, 4, 8, 12, 16, 24, 32, 48, 64, 80, 96, 128, 144, 160, 192, 224, 256, 320, 384, 512 @@ -53,7 +58,10 @@ class TestSANAS(unittest.TestCase): conv_list, ch_pro = compute_op_num(program) ### assert conv number - self.assertTrue((repeat_num * 3) == len(conv_list), "the number of conv is NOT match, the number compute from token: {}, actual conv number: {}".format(repeat_num * 3, len(conv_list))) + self.assertTrue((repeat_num * 3) == len( + conv_list + ), "the number of conv is NOT match, the number compute from token: {}, actual conv number: {}". + format(repeat_num * 3, len(conv_list))) ### assert number of channels ch_token = [] @@ -64,7 +72,10 @@ class TestSANAS(unittest.TestCase): ch_token.append(filter_num) init_ch_num = filter_num - self.assertTrue(str(ch_token) == str(ch_pro), "channel num is WRONG, channel num from token is {}, channel num come fom program is {}".format(str(ch_token), str(ch_pro))) + self.assertTrue( + str(ch_token) == str(ch_pro), + "channel num is WRONG, channel num from token is {}, channel num come fom program is {}". + format(str(ch_token), str(ch_pro))) def test_all_function(self): ### unittest for next_archs @@ -73,7 +84,8 @@ class TestSANAS(unittest.TestCase): token2arch_program = fluid.Program() with fluid.program_guard(next_program, startup_program): - inputs = fluid.data(name='input', shape=[None, 3, 32, 32], dtype='float32') + inputs = fluid.data( + name='input', shape=[None, 3, 32, 32], dtype='float32') archs = self.sanas.next_archs() for arch in archs: output = arch(inputs) @@ -85,8 +97,10 @@ class TestSANAS(unittest.TestCase): ### uniitest for tokens2arch with fluid.program_guard(token2arch_program, startup_program): - inputs = fluid.data(name='input', shape=[None, 3, 32, 32], dtype='float32') - arch = self.sanas.tokens2arch(self.sanas.current_info()['current_tokens']) + inputs = fluid.data( + name='input', shape=[None, 3, 32, 32], dtype='float32') + arch = self.sanas.tokens2arch(self.sanas.current_info()[ + 'current_tokens']) for arch in archs: output = arch(inputs) inputs = output @@ -94,7 +108,11 @@ class TestSANAS(unittest.TestCase): ### unittest for current_info current_info = self.sanas.current_info() - self.assertTrue(isinstance(current_info, dict), "the type of current info must be dict, but now is {}".format(type(current_info))) + self.assertTrue( + isinstance(current_info, dict), + "the type of current info must be dict, but now is {}".format( + type(current_info))) + if __name__ == '__main__': unittest.main()