fn
find_kappa_target_modules
→dict of str to list of str or Nonefind_kappa_target_modules(model: nn.Module, top_p: float = 0.2, max_dim_size_to_analyze: int = 16384, moe_param_suffixes: tuple[str, ...] | None = None, show_progress: bool = True)Choose what to adapt by the condition number of the weights (KappaTune).
The condition number of a weight matrix is its largest singular value over its
smallest. The top_p fraction of nn.Linear modules with the lowest numbers
are returned as target_modules, and the same fraction of the fused
mixture-of-experts weights (three-dimensional parameters named gate_up_proj,
down_proj and the like) as target_parameters, a pair ready to give to
lucid.peft.LoraConfig. An expert weight's number is the mean over its
experts. Every weight is decomposed, so a large model takes a while.
Parameters
modelnn.ModuleThe base model whose weights are analysed.
top_ pfloat= 0.2The fraction, between 0 and 1, of candidates to keep; at least one is kept
when there are any.
max_ dim_ size_ to_ analyzeint= 16384A weight with a dimension larger than this is skipped.
moe_ param_ suffixestuple of str= NoneThe endings of the names of fused expert parameters;
.gate_up_proj,
.down_proj, .gate_proj and .up_proj when None.show_ progressbool= TrueAccepted for the reference's signature; no progress bar is drawn.
Returns
dict of str to list of str or None{"target_modules": [...], "target_parameters": [...] or None}; the second is
None when the model has no fused expert weights.
Raises
ValueErrortop_p is outside [0, 1].Examples
>>> import lucid.nn as nn
>>> from lucid.peft import find_kappa_target_modules
>>> net = nn.Sequential(nn.Linear(8, 8), nn.Linear(8, 8), nn.Linear(8, 8))
>>> picked = find_kappa_target_modules(net, top_p=0.4)
>>> len(picked["target_modules"]), picked["target_parameters"]
(1, None)