SubspaceAllocator
SubspaceAllocator(model: nn.Module, config: AdamssConfig, adapter_name: str)Decides, on a schedule, which subspaces of an AdaMSS model stay trainable.
Call update_and_allocate once per training step, after loss.backward() and before the
gradients are cleared; AdamssModel.update_and_allocate does so for the adapters that asked
for ASA. Importances are gathered every step from init_warmup to final_warmup; every
mask_interval steps in that window the subspaces are ranked across the whole model, all but
the best frozen, and the importances restarted. The number to keep falls from the model's total
number of subspaces to asa_target_subspaces as
truncated, with
the progress through the window and asa_schedule_exponent.
Parameters
modelnn.ModuleconfigAdamssConfigadapter_ namestrRaises
ValueErrormodel holds adapter_name.Examples
>>> import lucid.nn as nn
>>> from lucid.peft import AdamssConfig, AdamssModel
>>> net = nn.Sequential(nn.Linear(6, 6), nn.Linear(6, 2))
>>> config = AdamssConfig(r=4, num_subspaces=3, use_asa=True, asa_target_subspaces=2,
... init_warmup=1, final_warmup=5, mask_interval=1, target_modules=["0", "1"])
>>> allocator = AdamssModel(net, config, "default").allocator("default")
>>> allocator.total, [allocator.target(step) for step in range(1, 6)]
(5, [5, 3, 2, 2, 2])Used by 2
Constructors
1Properties
1Instance methods
5Freeze every recorded subspace whose score is not strictly above the target-th highest.
Nothing is frozen while target is at least the number of subspaces recorded. A frozen
factor loses its gradient and its requires_grad; a kept one is trainable.
Parameters
targetintForget the recorded importances.
How many subspaces step allows to stay trainable, or None before the window opens.
Parameters
stepintReturns
int or NoneThe truncated schedule value; asa_target_subspaces from final_warmup on.
One training step's worth of allocation: record importances, then freeze if the schedule says so.
Nothing happens outside the window init_warmup <= step <= final_warmup. Inside it the
importances are recorded every step; on a step that is a multiple of mask_interval the
subspaces are masked to the schedule's target and the importances restart.
Parameters
global_ stepintRecord the importance of every factor that has a gradient, at its current value.