01-magnitude-pruning zeros out a fixed fraction of weights in a single shot. Pruning a large fraction all at once tends to genuinely hurt accuracy — the network hasn't had any chance to adapt its remaining weights to compensate for what was just removed. Spreading the same total amount of pruning across many smaller steps, interleaved with retraining between them in a real pipeline, tends to reach the same final sparsity with far less accuracy loss.
Implement cubic_sparsity_schedule(step, total_steps, target_sparsity), which computes how much sparsity to reach by a given step, and iterative_prune(weight, target_sparsity, num_steps), which applies 01-magnitude-pruning's magnitude_prune repeatedly, once per step, following that schedule.
cubic_sparsity_schedule(0, ...) returns 0.0; cubic_sparsity_schedule(total_steps, ...) returns target_sparsity exactly.step beyond total_steps clamps to target_sparsity.iterative_prune returns a list of num_steps arrays, each pruned to that step's scheduled sparsity, with sparsity never decreasing from one step to the next.Open one at a time. Each gives away a little more than the last.
progress = step / total_steps goes from 0 to 1 — the cubic schedule is target_sparsity * (1 - (1 - progress)**3), which starts at 0 and reaches target_sparsity exactly when progress = 1.
iterative_prune is a loop over range(1, num_steps + 1), calling magnitude_prune(weight, cubic_sparsity_schedule(step, num_steps, target_sparsity)) at each step — always pruning the original weight, not the previous step's already-pruned result, since each step's sparsity target already accounts for everything pruned before it.
No results yet
Run your code to check it against the examples, or submit to run every test.