class
XLoraClassifier
extends
ModuleXLoraClassifier(config: XLoraConfig, n_classes: int, n_layers: int, dtype: DTypeLike, device: str)Predicts, for each token, how much each LoRA expert should weigh.
A stack of xlora_depth linear layers (ReLU and dropout between them) over the hidden
states, (batch, tokens, hidden_size) to (batch, tokens, n_classes) — or
n_classes * n_layers outputs with layerwise_scalings, spread over the adapted layers.
The result is (batch, tokens, n_layers, n_classes), softmax-normalised over the experts
(at softmax_temperature) unless enable_softmax is off. It reads its settings from
the config it is given, so changing the config's softmax_temperature or
scaling_pass_value takes effect at the next call.
Parameters
configXLoraConfigThe classifier's shape (
hidden_size set) and behaviour.n_ classesintHow many experts it weighs.
n_ layersintHow many adapted layers the weights are for.
dtypelucid.dtypeThe dtype of its parameters and of the weights it returns (the adapter's: the base
model's, float32 for a half-precision one).
devicestrThe device it lives on (the base model's).
Attributes
layersnn.SequentialThe linear layers; their keys (
layers.0.weight ...) are the adapter file's.log_ scalingslist of TensorThe scalings of each call, while
scalings_logging is on.Examples
>>> import lucid
>>> from lucid.peft import XLoraConfig
>>> from lucid.peft.tuners.xlora._classifier import XLoraClassifier
>>> config = XLoraConfig(hidden_size=8, adapters={"a": "x", "b": "y"})
>>> classifier = XLoraClassifier(config, n_classes=2, n_layers=3, dtype=lucid.float32, device="cpu")
>>> classifier(lucid.randn(1, 5, 8)).shape
(1, 5, 3, 2)