Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Y
yapt
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
yapt
Commits
284f0772
Commit
284f0772
authored
4 years ago
by
Yifan Zhao
Browse files
Options
Downloads
Patches
Plain Diff
Better logging of pruning decisions
parent
84d04d43
No related branches found
No related tags found
No related merge requests found
Pipeline
#191974
failed
4 years ago
Stage: build
Stage: test
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
yapt/pruning/struct_pruning.py
+14
-5
14 additions, 5 deletions
yapt/pruning/struct_pruning.py
with
14 additions
and
5 deletions
yapt/pruning/struct_pruning.py
+
14
−
5
View file @
284f0772
...
...
@@ -58,10 +58,12 @@ class StructuredPruner:
conv_names
=
find_prunable_conv2d
(
self
.
syminf
)
if
self
.
layers
is
not
None
:
conv_names
=
filter_names_by_str_or_regex
(
conv_names
,
self
.
layers
)
params_flops_before
=
self
.
get_params_flops
(
*
args
)
# 1. Prune each prunable layer
params_flops_before
=
self
.
get_params_flops
(
*
args
)
nfilters_before
=
{}
for
name
in
conv_names
:
layer
=
rgetattr
(
self
.
module
,
name
)
nfilters_before
[
name
]
=
layer
.
weight
.
shape
[
0
]
filters
=
select_filters_by_norm
(
layer
,
self
.
get_prune_fraction
(
name
))
prune_conv2d_
(
layer
,
filters
)
# inplace
self
.
prune_decisions
[
name
]
=
filters
...
...
@@ -72,11 +74,11 @@ class StructuredPruner:
self
.
module
(
*
args
)
# 4. Print some stats
params_flops_after
=
self
.
get_params_flops
(
*
args
)
self
.
print_stats
(
params_flops_before
,
params_flops_after
)
self
.
print_stats
(
nfilters_before
,
params_flops_before
,
params_flops_after
)
def
print_stats
(
self
,
before
,
after
):
params_before
,
flops_before
=
before
params_after
,
flops_after
=
after
def
print_stats
(
self
,
nfilters_before
,
params_flops_before
,
params_flops_
after
):
params_before
,
flops_before
=
params_flops_
before
params_after
,
flops_after
=
params_flops_
after
log
.
info
(
"
%.3fX reduction in parameters after pruning (%d -> %d)
"
,
params_before
/
params_after
,
...
...
@@ -90,6 +92,13 @@ class StructuredPruner:
flops_after
,
)
lines
=
[]
for
layer_name
,
filters
in
self
.
prune_decisions
.
items
():
old_n
=
nfilters_before
[
layer_name
]
lines
.
append
(
f
"
{
layer_name
}
:
{
len
(
filters
)
}
pruned out of
{
old_n
}
"
)
lines
.
append
(
f
"
filters removed:
{
filters
}
"
)
log
.
debug
(
"
Layer pruned:
\n
%s
"
,
"
\n
"
.
join
(
lines
))
def
get_params_flops
(
self
,
*
args
):
summary
=
RunModelSummary
(
self
.
graphmodule
).
run
(
*
args
)
return
summary
[
"
params
"
].
sum
(),
summary
[
"
flops
"
].
sum
()
...
...
This diff is collapsed.
Click to expand it.
Yifan Zhao
@yifanz16
mentioned in commit
1eaa4654
·
4 years ago
mentioned in commit
1eaa4654
mentioned in commit 1eaa46542364c4a793163666c6b77180967ce760
Toggle commit list
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