Skip to content
fn

preprocess_loraga

→None
preprocess_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

Unadapted base model whose target nn.Linear layers will be adapted by LoRA-GA.
lora_configLoraConfig
A LoraConfig with init_lora_weights="lora_ga".
train_stepcallable
Zero-argument callback that runs forward and loss.backward() on calibration batches.
cache_filestr or PathLike= None
If 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.

Used by 1