def _compare_result_with_origin_model(self, check_func, use_cuda, delta2=1e-5, compare_seperately=True): if use_cuda and not core.is_compiled_with_cuda(): return func_1_first_loss, func_1_last_loss = self.check_network_convergence( seresnext_net.model, feed_dict=seresnext_net.feed_dict(use_cuda), iter=seresnext_net.iter(use_cuda), batch_size=seresnext_net.batch_size(), use_cuda=use_cuda, use_reduce=False, optimizer=seresnext_net.optimizer) func_2_first_loss, func_2_last_loss = check_func( seresnext_net.model, feed_dict=seresnext_net.feed_dict(use_cuda), iter=seresnext_net.iter(use_cuda), batch_size=seresnext_net.batch_size(), use_cuda=use_cuda) if compare_seperately: for loss in zip(func_1_first_loss, func_2_first_loss): self.assertAlmostEquals(loss[0], loss[1], delta=1e-5) for loss in zip(func_1_last_loss, func_2_last_loss): self.assertAlmostEquals(loss[0], loss[1], delta=delta2) else: self.assertAlmostEquals(np.mean(func_1_first_loss), func_2_first_loss[0], delta=1e-5) self.assertAlmostEquals(np.mean(func_1_last_loss), func_2_last_loss[0], delta=delta2)
def test_seresnet(self): with self.program_scope_guard(): self.check_prune_correctness( method=seresnext_net.model, feed_dict=seresnext_net.feed_dict(use_cuda=False), optimizer=seresnext_net.optimizer)
def _compare_reduce_and_allreduce(self, use_cuda, delta2=1e-5): if use_cuda and not core.is_compiled_with_cuda(): return all_reduce_first_loss, all_reduce_last_loss = self.check_network_convergence( seresnext_net.model, feed_dict=seresnext_net.feed_dict(use_cuda), iter=seresnext_net.iter(use_cuda), batch_size=seresnext_net.batch_size(), use_cuda=use_cuda, use_reduce=False, optimizer=seresnext_net.optimizer) reduce_first_loss, reduce_last_loss = self.check_network_convergence( seresnext_net.model, feed_dict=seresnext_net.feed_dict(use_cuda), iter=seresnext_net.iter(use_cuda), batch_size=seresnext_net.batch_size(), use_cuda=use_cuda, use_reduce=True, optimizer=seresnext_net.optimizer) for loss in zip(all_reduce_first_loss, reduce_first_loss): self.assertAlmostEquals(loss[0], loss[1], delta=1e-5) for loss in zip(all_reduce_last_loss, reduce_last_loss): self.assertAlmostEquals(loss[0], loss[1], delta=delta2) if not use_cuda: return all_reduce_first_loss_seq, all_reduce_last_loss_seq = self.check_network_convergence( seresnext_net.model, feed_dict=seresnext_net.feed_dict(use_cuda), iter=seresnext_net.iter(use_cuda), batch_size=seresnext_net.batch_size(), use_cuda=use_cuda, use_reduce=False, optimizer=seresnext_net.optimizer, enable_sequential_execution=True) reduce_first_loss_seq, reduce_last_loss_seq = self.check_network_convergence( seresnext_net.model, feed_dict=seresnext_net.feed_dict(use_cuda), iter=seresnext_net.iter(use_cuda), batch_size=seresnext_net.batch_size(), use_cuda=use_cuda, use_reduce=True, optimizer=seresnext_net.optimizer, enable_sequential_execution=True) for loss in zip(all_reduce_first_loss, all_reduce_first_loss_seq): self.assertAlmostEquals(loss[0], loss[1], delta=1e-5) for loss in zip(all_reduce_last_loss, all_reduce_last_loss_seq): self.assertAlmostEquals(loss[0], loss[1], delta=delta2) for loss in zip(reduce_first_loss, reduce_first_loss_seq): self.assertAlmostEquals(loss[0], loss[1], delta=1e-5) for loss in zip(reduce_last_loss, reduce_last_loss_seq): self.assertAlmostEquals(loss[0], loss[1], delta=delta2) for loss in zip(all_reduce_first_loss_seq, reduce_first_loss_seq): self.assertAlmostEquals(loss[0], loss[1], delta=1e-5) for loss in zip(all_reduce_last_loss_seq, reduce_last_loss_seq): self.assertAlmostEquals(loss[0], loss[1], delta=delta2)