initialize_lora_eva_weights
→Noneinitialize_lora_eva_weights(model: nn.Module, dataloader: Iterable[object] | None = None, eva_state_dict: dict[str, Tensor] | None = None, forward_fn: _ForwardFn = _forward_fn_dict, prepare_model_inputs_fn: _ModelInputFn = _prepare_model_inputs_fn_language_modeling, prepare_layer_inputs_fn: _LayerInputFn = _prepare_layer_inputs_fn_language_modeling, adapter_name: str = 'default', gather_distributed_inputs: bool = True, show_progress_bar: bool = True)Initialise LoRA layers of model in place with EVA singular vectors and redistributed ranks.
A layer whose rank changes gets new factors (lora_A the singular vectors, lora_B
zero), so make the optimizer afterwards; rank_pattern and alpha_pattern of the
adapter's config record the new ranks, and a saved adapter is rebuilt at them.
Parameters
modelnn.ModulePeftModel holding an adapter made with init_lora_weights='eva'.dataloaderiterable= Noneeva_state_dict is given.get_eva_state_dict, to skip the forward passes.forward_ fncallable= _forward_fn_dictprepare_ model_ inputs_ fncallable= _prepare_model_inputs_fn_language_modelingprepare_layer_inputs_fn is given as model_input; by
default the token mask of a language-modelling batch.prepare_ layer_ inputs_ fncallable or dict of str to callable= _prepare_layer_inputs_fn_language_modelingadapter_ namestr= "default"gather_ distributed_ inputsbool= Trueshow_ progress_ barbool= TrueRaises
ValueErrormodel is not a PeftModel of an init_lora_weights='eva' adapter, more than one
adapter is active, no dataloader or eva_state_dict is given, the adapter is
merged into the base weights (unmerge_adapter() first), or EVA gives every layer
rank 0 (the adapter would hold no layer; the model is left as it was).Notes
A layer EVA gives rank 0 loses this adapter and no other: its factors are dropped from the
layer and the layer is left out of the adapter's target_modules, so a saved adapter is
rebuilt without it. Only a layer left holding no adapter at all is replaced by the module it
wrapped. The reference replaces the layer by its base module whatever else it holds,
deleting the other adapters on it while their configs still list the module; this does not.
rank_pattern and alpha_pattern match a name by its dotted tail, so the entry of
q_proj is also the one read for block.q_proj. A layer holding the config's r or
lora_alpha is therefore listed too when such an entry would be read for it, and a saved
adapter is rebuilt at the rank and scale of every layer. The reference lists only the layers
that differ, and reads a name through the first key that matches it, so it can rebuild
block.q_proj at the rank of q_proj; this does not.