fn
preprocess_loraga
→Nonepreprocess_loraga(model: nn.Module, lora_config: LoraConfig, train_step: Callable[[], None], cache_file: str | os.PathLike[str] | None = None)Estimate and attach per-layer weight gradients on model before get_peft_model(..., LoraConfig(init_lora_weights='lora_ga')).
Parameters
modelnn.ModuleUnadapted base model whose target
nn.Linear layers will be adapted by LoRA-GA.lora_ configLoraConfigA
LoraConfig with init_lora_weights="lora_ga".train_ stepcallableZero-argument callback that runs forward and
loss.backward() on calibration batches.cache_ filestr or PathLike= NoneIf provided and the file already exists, cached gradients are loaded from it without
running
train_step; otherwise the captured gradients are saved to cache_file.