PigeonColumba compressa

Lesson 6 of 10

Global magnitude pruning

Magnitude pruning keeps the largest weights and zeros the rest. Global pruning ranks the weights of all layers together, so a layer full of tiny weights can lose most of them while a sensitive layer keeps more.

Implement global_masks(weights, sparsity): given a list of weight matrices and the fraction to remove, return one 0/1 mask per matrix (same shapes) that removes exactly round(sparsity * total) weights, the smallest in absolute value across all matrices.

Then the training loop multiplies weights by their mask after every step so pruned weights stay dead (lab/nn.py:MLP.apply_masks).

Your code

Where this is used