micm_nlp.models.xpe.factory

XPE factory — single entry point for building an XPE-wrapped model.

Replaces get_cross_prompt_encoder from the legacy path. Picks the task-type-specific XPE subclass via xpe_model_for(), constructs it directly (no dispatch via MODEL_TYPE_TO_PEFT_MODEL_MAPPING), primes grad requirements, logs the layer summary, and optionally restores a classifier head from a prior checkpoint (SEQ_CLS-only — a no-op for other task types).

Functions

get_xpe_model(base_model, peft_config_vars)

Wrap a base model in the Cross-Prompt Encoder PEFT model for its task type.

is_xpe_adapter_dir(path)

Peek at adapter_config.json at path and report whether it is an

is_xpe_config(config)

Dispatch helper for callers that don't want to import PeftType directly.

load_xpe_pretrained(base_model, path, **kwargs)

Load an XPE adapter via the task-type-specific XPE subclass.

maybe_load_pretrained_classifier_state(base_model, ...)

Copy base_model.classifier.* weights from a saved PEFT checkpoint into

Module Contents

micm_nlp.models.xpe.factory.get_xpe_model(base_model, peft_config_vars)

Wrap a base model in the Cross-Prompt Encoder PEFT model for its task type.

The PEFT-model class is chosen from task_type by xpe_model_for(). After construction the prompt encoder’s gradient requirements are set and its layers printed, and an encoder_init_state_dict_path in the config is loaded on top.

Parameters:
  • base_model – the backbone to wrap.

  • peft_config_vars – mapping of config fields; None values are stripped before they reach CrossPromptEncoderConfig (see _filtered_kwargs).

Returns:

the wrapped PEFT model, adapter name 'default'.

micm_nlp.models.xpe.factory.is_xpe_adapter_dir(path)

Peek at adapter_config.json at path and report whether it is an XPE adapter — canonical peft_type=XPE or legacy peft_type=P_TUNING + encoder_ratio. Returns False for non-directories and directories without an adapter_config.json.

micm_nlp.models.xpe.factory.is_xpe_config(config)

Dispatch helper for callers that don’t want to import PeftType directly.

Accepts the canonical peft_type='XPE' as well as the legacy peft_type='P_TUNING' + encoder_ratio spelling — paper-era checkpoints still ship with the legacy form.

micm_nlp.models.xpe.factory.load_xpe_pretrained(base_model, path, **kwargs)

Load an XPE adapter via the task-type-specific XPE subclass.

Reads task_type from adapter_config.json at path, resolves the matching XPE subclass, and delegates to its from_pretrained — which handles both canonical and legacy config spellings and bypasses the upstream task-type dispatch so our overrides actually run.

micm_nlp.models.xpe.factory.maybe_load_pretrained_classifier_state(base_model, init_state_dict_path)

Copy base_model.classifier.* weights from a saved PEFT checkpoint into the SEQ_CLS PeftModel’s modules_to_save.default slot. No-op if the checkpoint has no classifier keys (e.g. CAUSAL_LM has none).