micm_nlp.models.peft

PEFT dispatch: stock PEFT methods or the Cross-Prompt Encoder path.

PEFT.setup_model() is the single entry point MODEL calls. It branches three ways: load a pretrained adapter when model.pretrained.adapter is set, build a Cross-Prompt Encoder when is_xpe_config() recognises the peft block, or fall through to stock PEFT (LoRA, prefix tuning, P-tuning).

from_pretrained() sniffs adapter_config.json so checkpoints written before the XPE peft_type existed — P_TUNING plus an encoder_ratio — still load.

Classes

PEFT

Dispatch between stock PEFT methods and the Cross-Prompt Encoder path.

Module Contents

class micm_nlp.models.peft.PEFT

Dispatch between stock PEFT methods and the Cross-Prompt Encoder path.

A namespace of static methods rather than an object: MODEL calls into it, passing itself as base, and PEFT mutates base._model in place.

Two things route here. A model.pretrained.adapter path loads an already trained adapter; a peft config block builds a fresh one. Either way the XPE path is taken when the adapter directory or the config says so, and stock PEFT otherwise.

static from_pretrained(base_model, path)

Load a saved adapter, choosing the loader by what is in the directory.

Cross-Prompt Encoder adapters are not loadable by stock PeftModel, so the directory is sniffed first; anything else goes through PEFT itself.

static get_total_virtual_tokens(base)

Total virtual-token count injected by the active prompt encoder, or None if no prompt encoder is attached. Handles the ModuleDict-wrapped form that PEFT uses after adapter load.

static is_peft(base)

Whether this run involves PEFT at all.

True if a peft block names a peft_type, or if model.pretrained.adapter points at an adapter to load. Both are checked because a run can attach PEFT either way.

static setup_model(base)

Attach PEFT to base._model, replacing it with the wrapped model.

Order matters: a pretrained adapter wins over a peft block, so a config that both names an adapter and describes one loads the adapter rather than building a new one.

prompt_encoder_key = 'default'