Repository navigation
[Bugfix] Fix polynomial_decay pruning scheduler for even exponents - #3096
Conversation
polynomial_decay_scheduler computed the AGP decay factor as (t - 1)**exponent + 1, which only equals the intended 1 - (1 - t)**exponent for odd exponents. For even exponents -- including the default of 2 -- the sign of the decay term flips, so sparsity starts above final_sparsity and decreases over training instead of rising from init_sparsity. For example with init=0.0, final=0.9 the schedule started at 1.8 and fell to 0.9. Use 1 - (1 - t)**exponent, which is correct for all exponents and identical to the previous behaviour for odd exponents, so the cubic scheduler (exponent=3) is unchanged. Add regression tests for the schedulers. Signed-off-by: Madan Kumar <[email protected]>
|
👋 Hi! Thank you for contributing to llm-compressor. Please add the ready label when the PR is ready for review. Note: This is required to complete the testing suite, please only add the label once the PR is code complete and local testing has been performed. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Require one maintainer reviewAll PRs must have at least one approving review from a maintainer before merging.
|
There was a problem hiding this comment.
Code Review
This pull request corrects the AGP decay calculation in the polynomial decay scheduler to properly handle even exponents, ensuring sparsity increases monotonically, and adds corresponding unit tests. The review feedback highlights a potential issue where the completion ratio could exceed 1.0, leading to complex numbers with fractional exponents or non-monotonic behavior with even exponents. It is recommended to clamp the completion ratio to the [0.0, 1.0] range and expand the test suite to cover fractional exponents and out-of-bounds indices.
|
Thanks for the quick review and approve, @kylesayrs! |
|
@winklemad do you mind looking into the failing tests? |
The new tests/llmcompressor/modifiers/pruning/test_helpers.py had no __init__.py, so under pytest's default prepend import mode it was imported under the bare module name 'test_helpers', colliding with tests/llmcompressor/pipelines/ sequential/test_helpers.py and aborting collection with an import-file-mismatch error. Add the package marker (matching sibling dirs like modifiers/reap and modifiers/utils) so it imports as a unique dotted module. Signed-off-by: Madan Kumar <[email protected]>
Head branch was pushed to by a user without write access
|
Looked into it — the red build isn't the scheduler change, it's a pytest collection error that aborts the whole suite before any test runs: Root cause is on me: I added Fixed in 9af1153 by adding an empty |
Summary
polynomial_decay_schedulercomputes the AGP (Zhu & Gupta, 2017) sparsity decay factor as:This only equals the intended
1 - (1 - per_complete)**exponentwhenexponentis odd. For even exponents — including the default of2—(per_complete - 1)**exponent == (1 - per_complete)**exponent, so the decay term keeps the wrong sign: sparsity starts abovefinal_sparsityand decreases over training instead of rising frominit_sparsity.cubic_schedulersetsexponent=3(odd), so it happens to be correct — which is likely why this went unnoticed — but selecting"polynomial_decay"(defaultexponent=2) or any even exponent produces a broken schedule.Reproduce
Fix
Use
1 - pow(1 - per_complete, exponent), which is correct for all exponents and identical to the previous behaviour for odd exponents, socubic_scheduler(exponent=3) is byte-for-byte unchanged.After the fix the same schedule rises
0.0, 0.171, 0.324, …, 0.9.Testing
Adds
tests/llmcompressor/modifiers/pruning/test_helpers.py:polynomial_decayis monotonic and bounded in[init, final]for exponents 2, 3, and 4;init_sparsity;cubic_scheduleroutput is unchanged.The even-exponent tests fail on
mainand pass with the fix.ruff check/ruff format --checkclean.