Use LoRAConfig to define how Low-Rank Adaptation (LoRA) is applied to a SAM3 model. You can specify the rank, scaling factor, dropout, and which specific module patterns should receive LoRA layers.
Parameters:
rank (int): The rank of the LoRA matrices. Defaults to 4.alpha (float): The LoRA scaling factor. Defaults to 1.0.dropout (float): The dropout probability. Defaults to 0.0.target_modules (List[str]): A list of module name patterns to target. If None, it defaults to a comprehensive list covering standard attention, vision backbone (ViT-style), language backbone (CLIP-style), and transformer FFN layers. If 'all' is included in the list, it enables all possible modules including in_proj for MultiheadAttention.
Supported Target Module Patterns:
- Standard attention:
q_proj, k_proj, v_proj, out_proj - Vision backbone (ViT-style):
qkv (fused), proj (output), fc1, fc2 (MLP) - Language backbone (CLIP-style):
c_fc, c_proj (MLP) - Transformer FFN:
linear1, linear2 - Special:
all (enables everything listed above plus in_proj)
from src.lora.lora_utils import LoRAConfig
config = LoRAConfig(
rank=8,
alpha=2.0,
dropout=0.1,
target_modules=["q_proj", "v_proj"]
)