Skip to content
data

XLoraConfig

extendsPeftConfig
XLoraConfig(task_type: TaskType | str | None = None, peft_type: PeftType | str | None = None, auto_mapping: dict[str, str] | None = None, peft_version: str | None = None, base_model_name_or_path: str | None = None, revision: str | None = None, inference_mode: bool = False, hidden_size: int | None = None, adapters: dict[str, str] | None = None, enable_softmax: bool = True, enable_softmax_topk: bool = False, layerwise_scalings: bool = False, xlora_depth: int = 1, xlora_size: int = 2048, xlora_dropout_p: float = 0.2, use_trainable_adapters: bool = False, softmax_temperature: float = 1.0, top_k_lora: int | None = None, scaling_pass_value: float = 0.0, global_scaling_weight: float = 1.0)

How lucid.peft.get_peft_model mixes LoRA adapters with X-LoRA.

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.

Field names, their order, defaults and adapter_config.json are the reference adapter library's. Unlike the reference's, hidden_size left unset is read off the model rather than guessed, and an empty adapters is refused when the model is built.

Parameters

task_typeTaskType | str | None= None
As in lucid.peft.PeftConfig.
peft_typeTaskType | str | None= None
As in lucid.peft.PeftConfig.
auto_mappingTaskType | str | None= None
As in lucid.peft.PeftConfig.
peft_versionTaskType | str | None= None
As in lucid.peft.PeftConfig.
base_model_name_or_pathTaskType | str | None= None
As in lucid.peft.PeftConfig.
revisionTaskType | str | None= None
As in lucid.peft.PeftConfig.
inference_modeTaskType | str | None= None
As in lucid.peft.PeftConfig.
hidden_sizeint= None
Hidden size of the base model, the classifier's input width; the model's when None.
adaptersdict of str to str= None
The experts: each name maps to the directory of a saved LoRA adapter. They are loaded under the names "0", "1", ... in this order, which is also the order of the classifier's outputs. Needed when the model is built.
enable_softmaxbool= True
Normalise each token's expert weights with a softmax.
enable_softmax_topkbool= False
Softmax over the top_k_lora kept experts instead; set enable_softmax off with it.
layerwise_scalingsbool= False
One set of weights per adapted layer (the classifier outputs n_experts * n_layers) instead of one set shared by every layer.
xlora_depthint= 1
Linear layers of the classifier.
xlora_sizeint= 2048
Width of its hidden layers; unused at depth one.
xlora_dropout_pfloat= 0.2
Dropout between its hidden layers; unused at depth one.
use_trainable_adaptersbool= False
Train the experts too.
softmax_temperaturefloat= 1.0
Divides the logits before the softmax; lower is sharper.
top_k_loraint= None
Keep only this many experts per token (the rest weigh zero).
scaling_pass_valuefloat= 0.0
The weight every expert has in the scalings pass; 0 makes that pass the base model.
global_scaling_weightfloat= 1.0
A factor on every expert's update.

Raises

TypeError
A field holds a value of the wrong type.
ValueError
A count is not positive, or top_k_lora is below one.

Examples

>>> from lucid.peft import XLoraConfig
>>> config = XLoraConfig(hidden_size=64, adapters={"a": "/tmp/a", "b": "/tmp/b"}, xlora_depth=2)
>>> config.peft_type, sorted(config.adapters)
(<PeftType.XLORA: 'XLORA'>, ['a', 'b'])
>>> XLoraConfig.from_dict(config.to_dict()) == config
True

Used by 4