Skip to content
data

BdLoraConfig

BdLoraConfig(target_modules_bd_a: list[str] | None = None, target_modules_bd_b: list[str] | None = None, nblocks: int = 1, match_strict: bool = True)

Options of block-diagonal LoRA, which makes chosen LoRA factors block-diagonal.

In BD-LoRA a LoRA factor AA or BB is a block-diagonal matrix of nblocks blocks, so the adapter splits across devices (or serving shards) without communication. target_modules_bd_a names the modules whose AA is block-diagonal (the query, key, value, up and gate projections) and target_modules_bd_b those whose BB is (the output and down projections). LoraConfig(use_bdlora=...) is refused: the extension is not implemented.

Parameters

target_modules_bd_alist of str= None
Modules whose LoRA-A is block-diagonal; a pattern matches a module whose name contains it.
target_modules_bd_blist of str= None
Modules whose LoRA-B is block-diagonal, matched the same way.
nblocksint= 1
Blocks per block-diagonal matrix. Set it to the sharding degree to serve with.
match_strictbool= True
Require every targeted module to have a block-diagonal A or B and raise otherwise. False allows mixing plain LoRA and BD-LoRA layers.

Raises

ValueError
A module is listed for both A and B.

Examples

>>> from lucid.peft import BdLoraConfig
>>> config = BdLoraConfig(target_modules_bd_a=["q_proj"], target_modules_bd_b=["o_proj"], nblocks=2)
>>> config.nblocks, config.match_strict
(2, True)

Used by 2