micm_nlp.models.xpe.save_load

XPE-aware save/load helpers.

These replace peft.utils.save_and_load.get_peft_model_state_dict and set_peft_model_state_dict while an XPE model saves or loads (the PeftModel subclasses swap them in). Their bodies started as copies of peft 0.14’s; the XPE differences:

  • The prompt encoder’s weights are read from and written to the encoder itself, as prompt_encoder.<param>. Stock PEFT reduces a prompt encoder to one prompt_embeddings tensor, and since peft 0.17 a CAUSAL_LM encoder’s parts are never wrapped by modules_to_save either. The keys are the ones peft 0.14-era adapters were saved under, so those still load; a missing encoder weight raises.

  • The PEFT_TYPE_TO_PREFIX_MAPPING branch is skipped for prompt learning: since peft 0.15 XPE is in that mapping as xpe_, and inserting the adapter name after that prefix would corrupt the xpe_embedding / xpe_head keys.

  • Everything else – save_embedding_layers, modules_to_save for the rest of the model (a SEQ_CLS classifier) – follows upstream.

Functions

xpe_get_peft_model_state_dict(model[, state_dict, ...])

See module docstring. Mirrors upstream except the prompt-learning collapse.

xpe_set_peft_model_state_dict(model, peft_model_state_dict)

See module docstring. Mirrors upstream except it skips the destructive

Module Contents

micm_nlp.models.xpe.save_load.xpe_get_peft_model_state_dict(model, state_dict=None, adapter_name='default', unwrap_compiled=False, save_embedding_layers='auto')

See module docstring. Mirrors upstream except the prompt-learning collapse.

micm_nlp.models.xpe.save_load.xpe_set_peft_model_state_dict(model, peft_model_state_dict, adapter_name='default', ignore_mismatched_sizes: bool = False, low_cpu_mem_usage: bool = False)

See module docstring. Mirrors upstream except it skips the destructive prompt_embeddings single-tensor load and instead does a non-strict prompt_encoder.load_state_dict so XPE’s multi-component state loads.