Repository navigation
fix(prune): PruneCallback logs the applied ratio and traces on the fit's own batch - #100
Merged
Merged
Conversation
…t's own batch PruneCallback.after_epoch printed levels[k - 1] after k prune steps, while torch-pruning's step() advances its counter before reading the level, so the model is at levels[k]; the last epoch now prints the final target. before_fit read a batch from dls.one_batch() and dropped it, so the Pruner traced on its default 1x3x224x224 input and failed on models that do not accept it. The batch is now passed as example_inputs; one given by the user still wins.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two
PruneCallbackfixes, follow-up of #98.1. The epoch log printed the previous step's ratio
torch-pruning's
step()incrementscurrent_stepthen appliesper_step_pruning_ratio[current_step]. Aftercompleted_stepssteps, the applied level is thereforelevels[completed_steps], butafter_epochprintedlevels[completed_steps - 1]. The last epoch never showed the final target ratio.levels[completed_steps], with the guardcompleted_steps < len(levels).2. The Pruner traced a fixed 224×224 input
before_fitreaddls.one_batch()but never passed it on, so thePrunertraced its defaulttorch.randn(1, 3, 224, 224)instead.example_inputs. Anexample_inputsgiven by the user still wins.before_fit(mat1 and mat2 shapes cannot be multiplied). GREEN: it traces on the (16, 3, 8, 8) batch, on the model's device, and a user-supplied (2, 3, 8, 8) input is kept.Tutorial
tutorials/prune/prune_callbackwas re-executed, since its stored epoch-log lines change. It is a single run with no seed, so every printed number moved. The prose was updated to the printed values and checked by a results review:The review also caught a pre-existing error: the head goes from 512 to 502 units, not from 1024. 1024 is the layer's input width.
Evidence
nbdev-testpasses, as do the slow prune tests.