forked from IntelLabs/distiller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Model thinning: bug fix – aggressive channel/filter pruning raises an…
… exception * Fix bug: taking the len() of a zero-dimensional ‘indices’ tensor is not legal. Use nelement() instead. A zero-dim ‘indices’ tensor occurs when the pruning is very aggressive and leaves one channel or filter in the tensor. * Protect again pruning of all channels/filters of a layer: Raise ValueError if trying to create (thru thinning) a Convolution layer with zero channels or filters. * Tests: * Some PEP8 cleanup. * Add some test documentation. * Refactored some test code to tests/common.py * Added testing of pruning all the channels/filters in a Convolution
- Loading branch information
Showing
3 changed files
with
162 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# | ||
# Copyright (c) 2018 Intel Corporation | ||
# | ||
# 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 os | ||
import sys | ||
module_path = os.path.abspath(os.path.join('..')) | ||
if module_path not in sys.path: | ||
sys.path.append(module_path) | ||
import distiller | ||
from models import create_model | ||
|
||
|
||
def setup_test(arch, dataset): | ||
model = create_model(False, dataset, arch, parallel=False) | ||
assert model is not None | ||
|
||
# Create the masks | ||
zeros_mask_dict = {} | ||
for name, param in model.named_parameters(): | ||
masker = distiller.ParameterMasker(name) | ||
zeros_mask_dict[name] = masker | ||
return model, zeros_mask_dict | ||
|
||
|
||
def find_module_by_name(model, module_to_find): | ||
for name, m in model.named_modules(): | ||
if name == module_to_find: | ||
return m | ||
return None |
Oops, something went wrong.