def test_can_create_magnitude_algo__without_levels(): config = get_basic_magnitude_sparsity_config() config['compression']['params'] = { 'schedule': 'multistep', 'multistep_steps': [1] } _, compression_ctrl = create_compressed_model_and_algo_for_test( get_mock_model(), config) assert compression_ctrl.scheduler.current_sparsity_level == approx(0.1)
def test_can_not_create_magnitude_algo__with_not_matched_steps_and_levels(): config = get_basic_magnitude_sparsity_config() config['compression']['params'] = { 'schedule': 'multistep', 'multistep_sparsity_levels': [0.1], 'multistep_steps': [1, 2] } with pytest.raises(ValueError): _, _ = create_compressed_model_and_algo_for_test( get_mock_model(), config)
def test_can_not_create_magnitude_algo__with_adaptive_scheduler(): config = get_empty_config() config['compression'] = { 'algorithm': 'magnitude_sparsity', 'params': { 'schedule': 'adaptive' } } with pytest.raises(ValueError): _, _ = create_compressed_model_and_algo_for_test( get_mock_model(), config)
def test_can_choose_scheduler(algo, schedule_type, scheduler_class): config = get_empty_config() config['compression'] = Dict({ 'algorithm': algo, 'params': { 'schedule': schedule_type } }) _, compression_ctrl = create_compressed_model_and_algo_for_test( get_mock_model(), config) assert isinstance(compression_ctrl.scheduler, scheduler_class)
def test_can_create_sparse_scheduler__with_defaults(self, algo): config = get_empty_config() config['compression'] = Dict({ 'algorithm': algo, 'params': { 'schedule': 'polynomial' } }) _, compression_ctrl = create_compressed_model_and_algo_for_test( get_mock_model(), config) scheduler = compression_ctrl.scheduler assert scheduler.initial_level == 0 assert scheduler.target_level == 0.5 assert scheduler.target_epoch == 90 assert scheduler.freeze_epoch == 100