Add KappaTuneSelector: condition-number-based automatic LoRA target selection#3106
Add KappaTuneSelector: condition-number-based automatic LoRA target selection#3106oswaldoludwig wants to merge 9 commits intohuggingface:mainfrom
Conversation
githubnemo
left a comment
There was a problem hiding this comment.
Thanks for the PR!
I think the interface is fine, KappaTuneSelector as a class to compute once and be able to experiment with different selections is good, having a short-cut one-liner is good as well.
There are only a few things missing:
- Let's add unit tests, e.g. in
tests/test_target_selection.py - Let's add an example, if possible re-creating the results from the paper
- Let's add documentation (entry in
_toctree.ymlunderUtilitiesand a package reference file inpackage_reference/target_selection)
Did you test this with other PEFT methods like MiSS or SHiRA to see if it has a similar effect? I wonder if this method generalizes to other methods as well!
src/peft/utils/target_selection.py
Outdated
| 3. threshold (all modules below kappa) | ||
| 4. everything (fallback) | ||
|
|
||
| Modules are sorted by ascending kappa (lowest = best for adaptation). |
There was a problem hiding this comment.
Let's document top_p, num_modules and threshold explicitly.
There was a problem hiding this comment.
I hadn't noticed that comment before. Check out the new comments in target_selection.py.
There was a problem hiding this comment.
I hope all reviewer feedback has been addressed (docstrings, tests, 4-bit support, processor note in the docs, and the experiment`) and the PR is ready for final review & merge @githubnemo
src/peft/utils/target_selection.py
Outdated
| top_p: float = 0.2, | ||
| max_dim_size_to_analyze: int = 16384, | ||
| ) -> List[str]: | ||
| """One-liner version for quick use.""" |
There was a problem hiding this comment.
Let's write a user-friendly documentation that explains the usage, default parameters and impact of parameter choice. Recommendations and examples are good.
Co-authored-by: githubnemo <githubnemo@users.noreply.github.com>
This script implements Kappa-Selection using the PEFT KappaTuneSelector for identifying higher-entropy, less-anisotropic modules. It includes data preparation, experiment execution, and evaluation of perplexity on IMDB and WikiText datasets.
Updated KappaTuneSelector to support bnb 4-bit models and improved comments (ready for paper experiments with QLoRA / 4-bit models).
The selector picks the layers with the lowest condition number (most isotropic = best for adaptation), exactly as shown in the KappaTune paper (https://arxiv.org/abs/2506.16289).
Add tests for KappaTuneSelector and target selection
Added detailed docstrings for target selection functions, documenting top_p, num_modules and threshold explicitly.
Avoiding a compatibility issue, reported dozens of times on HF discussions, between the DeepSeek-V2-Lite custom modeling code and Transformers v4.40+. The model’s forward pass still calls the old past_key_values.get_usable_length(...) method, but DynamicCache (the default cache class now) no longer has it.
What this PR does
This PR adds lightweight target selection tooling, a new utility that lets users automatically select the best LoRA target_modules before creating a LoraConfig based on the lowest condition number per tensor, the metric used in KappaTune (https://arxiv.org/abs/2506.16289).
New API