Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
distiller
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
llvm
distiller
Commits
8cffe6c9
Commit
8cffe6c9
authored
5 years ago
by
levzlotnik
Browse files
Options
Downloads
Patches
Plain Diff
Update _Regularizer docstrings for clarity of API
parent
cdc1775f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
distiller/regularization/regularizer.py
+25
-3
25 additions, 3 deletions
distiller/regularization/regularizer.py
with
25 additions
and
3 deletions
distiller/regularization/regularizer.py
+
25
−
3
View file @
8cffe6c9
...
...
@@ -13,16 +13,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import
torch
import
torch.nn
as
nn
EPSILON
=
1e-8
class
_Regularizer
(
object
):
def
__init__
(
self
,
name
,
model
,
reg_regims
,
threshold_criteria
):
"""
Regularization base class.
Args:
reg_regims: regularization regiment. A dictionary of
reg_regims[<param-name>] = [ lambda, structure-type]
name (str): the name of the regularizer.
model (nn.Module): the model on which to apply regularization.
reg_regims (dict[str, float or tuple[float, Any]]): regularization regiment. A dictionary of
reg_regims[<param-name>] = [ lambda[, additional_configuration]]
threshold_criteria (str): the criterion for which to calculate the threshold.
"""
self
.
name
=
name
self
.
model
=
model
...
...
@@ -30,7 +35,24 @@ class _Regularizer(object):
self
.
threshold_criteria
=
threshold_criteria
def
loss
(
self
,
param
,
param_name
,
regularizer_loss
,
zeros_mask_dict
):
"""
Applies the regularization loss onto regularization loss.
Args:
param (nn.Parameter): the parameter on which to calculate the regularization
param_name (str): the name of the parameter relative to top level module.
regularizer_loss (torch.Tensor): the previous regularization loss calculated,
zeros_mask_dict (dict): the masks configuration.
Returns:
torch.Tensor: regularization_loss after applying the additional loss from current parameter.
"""
raise
NotImplementedError
def
threshold
(
self
,
param
,
param_name
,
zeros_mask_dict
):
"""
Calculates the threshold for pruning.
Args:
param (nn.Parameter): the parameter on which to calculate the regularization
param_name (str): the name of the parameter relative to top level module.
zeros_mask_dict (dict): the masks configuration.
"""
raise
NotImplementedError
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment