Skip to content
fn

get_base_model_state_dict

→dict of str to Tensor
get_base_model_state_dict(model: PeftModel)

Return the base model's state dict, under the key names it had before it was adapted.

The adapters' tensors are left out, and the wrappers adapting put in the tree are undone in the names: q.base_layer.weight comes back as q.weight, and head.original_module.weight (a module saved in full) as head.weight. The tensors are the model's own, not copies.

Parameters

An adapted model, as lucid.peft.get_peft_model returns it.

Returns

dict of str to Tensor

The base model's state dict.

Raises

TypeError
model is not a PeftModel.

Examples

>>> import lucid.nn as nn
>>> from lucid.peft import LoraConfig, get_base_model_state_dict, get_peft_model
>>> net = nn.Sequential(nn.Linear(4, 4), nn.Linear(4, 2))
>>> peft = get_peft_model(net, LoraConfig(r=2, target_modules=["0"]))
>>> sorted(get_base_model_state_dict(peft))
['0.bias', '0.weight', '1.bias', '1.weight']

Used by 1