Skip to content

fix(pruning): normalize a negative channel axis#45

Open
eyupcanakman wants to merge 1 commit into
apple:mainfrom
eyupcanakman:fix/pruning-negative-channel-axis
Open

fix(pruning): normalize a negative channel axis#45
eyupcanakman wants to merge 1 commit into
apple:mainfrom
eyupcanakman:fix/pruning-negative-channel-axis

Conversation

@eyupcanakman

Copy link
Copy Markdown
Contributor

ChannelStructured(axis=-1) prunes the wrong channels.

_compute_channel_mask compares each dim index against the raw axis when building its reduce list. A negative axis never matches, so nothing is excluded and the per-channel L1 norms collapse to a scalar. With one channel kept, channel 0 survives regardless. With more than one the call fails:

RuntimeError: selected index k out of range

Positive axes work. The fix normalizes the axis first, matching PerChannelGranularity, which documents and resolves negative indexing. An out-of-range axis now raises ValueError, since one addition leaves values below -ndim still negative. The tests cover Linear and Conv2d weights and the rejected range.

ChannelStructured(axis=-1) pruned the wrong channels.
_compute_channel_mask compared each dim index against the raw axis when building its reduce list, so a negative axis excluded nothing and the per-channel L1 norms collapsed to a scalar.
Normalize the axis first, matching PerChannelGranularity, and reject an out-of-range axis with ValueError rather than letting it reach the reduction.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants