initialize_kv_prefix_from_past_key_values(model: PeftModel, adapter_name: str | None = None, past_key_values: object, num_virtual_tokens: int | None = None)Start a Cartridge (or an unprojected prefix) from the keys and values of a cache you have.
The first num_virtual_tokens tokens of the cache of one sequence become the adapter's rows
(prompt_embeddings_from_past_key_values), frozen ones first.
Parameters
modelPeftModelA model with a
CARTRIDGE or PREFIX_TUNING adapter.adapter_ namestr= NoneThe adapter to initialise; the active one when left out.
past_ key_ valuesobjectThe cache, in a form
prompt_embeddings_from_past_key_values takes.num_ virtual_ tokensint= NoneHow many leading tokens to take; the adapter's own count when left out.
Returns
TensorThe rows that were loaded.
Raises
ValueErrorThe adapter is neither a Cartridge nor a prefix, is a prefix with
prefix_projection, or the
cache does not fit (see prompt_embeddings_from_past_key_values); the adapter's rows are
untouched then.