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¶
|
Wrap a base model in the Cross-Prompt Encoder PEFT model for its task type. |
|
Peek at |
|
Dispatch helper for callers that don't want to import PeftType directly. |
|
Load an XPE adapter via the task-type-specific XPE subclass. |
|
Copy |
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_typebyxpe_model_for(). After construction the prompt encoder’s gradient requirements are set and its layers printed, and anencoder_init_state_dict_pathin the config is loaded on top.- Parameters:
base_model – the backbone to wrap.
peft_config_vars – mapping of config fields;
Nonevalues are stripped before they reachCrossPromptEncoderConfig(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.jsonatpathand report whether it is an XPE adapter — canonicalpeft_type=XPEor legacypeft_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 legacypeft_type='P_TUNING' + encoder_ratiospelling — 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_typefromadapter_config.jsonatpath, resolves the matching XPE subclass, and delegates to itsfrom_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’smodules_to_save.defaultslot. No-op if the checkpoint has no classifier keys (e.g. CAUSAL_LM has none).