Skip to content
class

QuantizedLinear

extendsLinear
QuantizedLinear(base_layer: nn.Module, adapter_name: str, r: int = 0, lora_alpha: float = 1, lora_dropout: float = 0.0, fan_in_fan_out: bool = False, is_target_conv_1d_layer: bool = False, init_lora_weights: bool | str = True, use_rslora: bool = False, use_dora: bool = False, lora_bias: bool = False, arrow_config: ArrowConfig | None = None)

A quantized linear module (QuantizedLinearMLX, nn.quantized.Linear, or dynamic.Linear) with a float LoRA update (QLoRA).

The base layer keeps its quantized integer buffers frozen and executes its low-precision or dequantized forward pass; the low-rank factors lora_A and lora_B are allocated in float32 on the base buffers' device so gradients flow through both the parallel LoRA branch and the base layer's activation backward pass.

merge dequantizes the base weight, adds s BAs\,B A, and re-quantizes in place while snapshotting the pre-merge quantized buffers so unmerge restores the exact original packed state without double-quantization drift.

Parameters

base_layernn.Linear
The layer to adapt; kept as base_layer, its parameters shared.
adapter_namestr
Name of the adapter, the key in lora_A / lora_B.
rint= 0
Rank. The default is the reference's and is refused: pass a positive rank.
lora_alphafloat= 1
Numerator of the scale.
lora_dropoutfloat= 0.0
Dropout on the update's input.
fan_in_fan_outbool= False
Must be False: nn.Linear stores its weight (out, in).
is_target_conv_1d_layerbool= False
Must be False; kept so positional calls line up with the reference, whose fused-QKV Conv1D base v1 does not have.
init_lora_weightsbool or str= True
See LoraConfig; "pissa" and "olora" also rewrite the base weight (the residual).
use_rslorabool= False
Scale by α/r\alpha/\sqrt r.
use_dorabool= False
Weight-decomposed update (DoRA): a magnitude vector (lora_magnitude_vector) beside the factors, so the layer computes m (W+s BA)/∥W+s BA∥m\,(W + s\,BA)/\lVert W + s\,BA\rVert row by row.
lora_biasbool= False
Give lora_B a bias (lora_B.<adapter>.bias); merging folds it, scaled, into the base bias.
arrow_configArrowConfig= None
Make the adapter an Arrow router over the plain LoRA adapters the layer already holds (lora_arrow): each token goes through the top_k of them its prototype is nearest to, and the router cannot be merged. Its own lora_A / lora_B exist, as in the reference, and are not used.

Used by 2