X-LoRA
3 memberslucid.peft.tuners.xloralucid.peft.tuners.xlora — X-LoRA: a mixture of LoRA experts weighed per token by a learned classifier.
X-LoRA (Buehler & Buehler, 2024, arXiv:2402.07148) starts from several LoRA adapters trained on different tasks and learns only how to combine them. A scalings pass runs the model with the experts held at a fixed weight; a small classifier on its final hidden states then predicts, for every token (and, if asked, every adapted layer), one weight per expert; the real pass adds each expert's low-rank update on the input scaled by its weight, optionally keeping only the top-k. Pick it to specialise a model on a mix of skills without choosing one expert up front, and to train a few thousand classifier parameters rather than the experts.
The experts are loaded by name through the multi-adapter API (XLoraModel.lora_model), the
model is called as usual, and the adapter file holds the classifier alone
(internal_xlora_classifier.*) — the experts stay where they were saved, named by
XLoraConfig.adapters. The weights come from the whole sequence, so generate with
use_cache=False; nothing merges. XLoraConfig and XLoraModel are here and exported from
lucid.peft; XLoraClassifier is the classifier. Importing the package registers the method
under PeftType.XLORA.
Buehler, Eric L., and Markus J. Buehler. "X-LoRA: Mixture of Low-Rank Adapter Experts, a Flexible Framework for Large Language Models with Applications in Protein Mechanics and Molecular Design." [arXiv:2402.07148](https://arxiv.org/abs/2402.07148), 2024.
X-LoRA (Buehler & Buehler, 2024, arXiv:2402.07148) keeps several trained LoRA adapters (the
experts) and a small classifier on the base model's final hidden states that scales each
expert per token: a scalings pass computes the hidden states with the experts held at a
fixed value, the classifier turns them into one weight per expert (per adapted layer if
layerwise_scalings), and the real pass adds each expert's update with its weight. Only the
classifier trains unless use_trainable_adapters.