Commit f466830
committed
fix(analyze): faithful group-sensitivity for structural pruning
SensitivityAnalyzer's pruning mode isolated each layer by ignoring every other
compressible layer, then pruned the target. For residual/skip-coupled layers
(ResNet stem conv, block conv2s, downsample) the coupling could not be satisfied
— all the output-coupled partners were ignored — so torch-pruning pruned nothing.
The layer reported Δ=0.0000 and was ranked 'Most Robust (compressible)', the most
dangerous possible output: it recommended compressing exactly the layers that
cascade-degrade a real prune.
Now each layer is pruned with the exact per-layer target {name: level} that
Pruner/PruneCallback use, so the reported Δ is a FAITHFUL predictor — verified to
match a real prune to 1e-6 at every level (10/30/50%). Mechanics:
- _build_dependency_groups: detect output-coupled sets (torch-pruning
prune_out_channels handler) and tag coupled layers with a shared group_id;
layers Pruner ignores (output Linear, attention qkv) get no group.
- _apply_structural_pruning: prune {name: level} on a fresh copy (dict path),
with a channel-signature no-op guard; never evaluates a half-pruned model.
- LayerSensitivity gains group_id/group_members/prunable (additive; sparsity and
quantization modes keep prior behaviour).
- top()/summary() exclude not-prunable layers from the robust ranking and surface
them separately; to_layer_targets() collapses each group to one knob so coupled
layers aren't double-counted.
- analyze() gains a layer_types filter (e.g. (nn.Conv2d,) to skip the classifier
Linear), and internal Pruner construction is silenced so the analysis no longer
spams 'Ignoring output layer / Using per-layer pruning' once per layer.
Adds inline + #| slow ResNet-18 regression tests (coupled layers no longer Δ=0
robust; coupled members share group_id+delta; analysis Δ == real prune Δ).1 parent eb5500f commit f466830
3 files changed
Lines changed: 1230 additions & 164 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
| |||
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
40 | 50 | | |
41 | 51 | | |
42 | 52 | | |
| |||
0 commit comments