DeepMTP.integrations package

Optional integrations remain separate from the core training and HPO implementations. Importing DeepMTP.integrations does not load Transformers or Streamlit.

Hugging Face foundation models

Install the optional dependency before tokenizing or loading a foundation model:

python -m pip install "DeepMTP[foundation]"

Optional Hugging Face tokenization and sequence-encoder integration.

class DeepMTP.integrations.huggingface.FoundationLoRASpec(target_modules: tuple[str, ...], rank: int = 8, alpha: int = 16, dropout: float = 0.0)

Bases: object

Serializable LoRA settings supported by the foundation adapter.

alpha: int = 16
dropout: float = 0.0
classmethod from_config(value: FoundationLoRASpec | Mapping[str, Any]) → FoundationLoRASpec

Validate a public mapping as a LoRA specification.

rank: int = 8
target_modules: tuple[str, ...]
to_dict() → dict[str, Any]

Return JSON-compatible LoRA settings.

class DeepMTP.integrations.huggingface.FoundationModelSpec(model_name: str, revision: str | None = None, tokenizer_name: str | None = None, tokenizer_revision: str | None = None, pooling: Literal['cls', 'masked_mean', 'pooler'] | str = 'masked_mean', train_mode: Literal['frozen', 'full', 'lora'] | str = 'frozen', trust_remote_code: bool = False, local_files_only: bool = False, max_length: int | None = None, truncation: bool = False, exclude_special_tokens_from_pooling: bool = True, pooling_excluded_token_ids: tuple[int, ...] = (), resolved_model_revision: str | None = None, resolved_tokenizer_revision: str | None = None, lora: FoundationLoRASpec | Mapping[str, Any] | None = None, cache: FoundationCacheSpec | Mapping[str, Any] | None = None)

Bases: object

Serializable model, tokenizer, pooling, and training settings.

cache: FoundationCacheSpec | Mapping[str, Any] | None = None
exclude_special_tokens_from_pooling: bool = True
classmethod from_config(value: FoundationModelSpec | Mapping[str, Any] | None) → FoundationModelSpec

Validate a public mapping as a foundation-model specification.

local_files_only: bool = False
lora: FoundationLoRASpec | Mapping[str, Any] | None = None
max_length: int | None = None
property model_load_revision: str | None

Immutable resolved revision when known, otherwise the requested one.

model_name: str
pooling: Literal['cls', 'masked_mean', 'pooler'] | str = 'masked_mean'
pooling_excluded_token_ids: tuple[int, ...] = ()
resolved_model_revision: str | None = None
resolved_tokenizer_revision: str | None = None
revision: str | None = None
to_dict() → dict[str, Any]

Return JSON-compatible settings for config, W&B, and checkpoints.

property tokenizer_load_revision: str | None

Immutable tokenizer revision when known, otherwise the requested one.

tokenizer_name: str | None = None
tokenizer_revision: str | None = None
train_mode: Literal['frozen', 'full', 'lora'] | str = 'frozen'
truncation: bool = False
trust_remote_code: bool = False
class DeepMTP.integrations.huggingface.HuggingFaceSequenceEncoder(*args: Any, **kwargs: Any)

Bases: Module

Pool and project one Hugging Face encoder as a DeepMTP branch.

property cache_stats: dict[str, Any]

JSON-compatible cache statistics for diagnostics and reporting.

clear_cache(*, memory: bool = True, disk: bool = False) → None

Clear this encoder’s derived memory and optionally disk entries.

forward(values: SequenceInput) → torch.Tensor
input_kind: ClassVar[BranchInputKind] = 'sequence'
train(mode: bool = True) → HuggingFaceSequenceEncoder

Keep a frozen backbone deterministic while training its projection.

class DeepMTP.integrations.huggingface.TokenizedFoundationSequences(rows: tuple[ndarray, ...], vocabulary_size: int, padding_idx: int, spec: FoundationModelSpec)

Bases: Sequence[ndarray]

Unpadded token rows plus their reproducible tokenizer settings.

padding_idx: int
rows: tuple[ndarray, ...]
spec: FoundationModelSpec
vocabulary_size: int
DeepMTP.integrations.huggingface.tokenize_foundation_sequences(values: Sequence[str], spec: FoundationModelSpec | Mapping[str, Any]) → TokenizedFoundationSequences

Tokenize raw protein, SMILES, or text rows without batch padding.

Streamlit

Install the optional dependency before constructing a Streamlit adapter:

python -m pip install "DeepMTP[streamlit]"

The canonical Streamlit API is available from one namespace:

from DeepMTP.integrations.streamlit import (
    DeepMTP as StreamlitDeepMTP,
    HyperBand,
    RandomSearch,
    StreamlitHPOProgressObserver,
    StreamlitProgressObserver,
)

Trainer

Core trainer configured with Streamlit progress rendering.

class DeepMTP.integrations.streamlit.trainer.DeepMTP(config: DeepMTPConfig | Mapping[str, Any], instance_branch_model: Callable[[Mapping[str, Any]], torch.nn.Module] | None = None, target_branch_model: Callable[[Mapping[str, Any]], torch.nn.Module] | None = None, checkpoint_dir: str | PathLike[str] | None = None, reporter: ExperimentReporter | None = None, progress: ProgressObserver | None = None)

Bases: DeepMTP

Core DeepMTP trainer configured with Streamlit progress rendering.

DeepMTP.integrations.streamlit.trainer.initialize_mode(config: DeepMTPConfig | Mapping[str, Any]) → DeepMTP

HPO adapters

Hyperparameter optimizers configured with Streamlit progress rendering.

class DeepMTP.integrations.streamlit.hpo.HyperBand(*args: Any, progress: HPOProgressObserver | None = None, **kwargs: Any)

Bases: HyperBand

Core Hyperband configured with Streamlit progress rendering.

class DeepMTP.integrations.streamlit.hpo.RandomSearch(*args: Any, progress: HPOProgressObserver | None = None, **kwargs: Any)

Bases: RandomSearch

Core random search configured with Streamlit progress rendering.

Progress renderers

Streamlit renderers for core DeepMTP progress events.

class DeepMTP.integrations.streamlit.progress.StreamlitAPI(*args, **kwargs)

Bases: Protocol

Small Streamlit surface used by the progress adapters.

empty() → Any

Create an empty UI slot.

progress(value: int) → Any

Create a progress indicator.

class DeepMTP.integrations.streamlit.progress.StreamlitHPOProgressObserver(*, streamlit_module: StreamlitAPI | None = None)

Bases: object

Render shared optimizer events in Streamlit.

on_event(event: HPOProgressEvent) → None
class DeepMTP.integrations.streamlit.progress.StreamlitProgressObserver(config: DeepMTPConfig | Mapping[str, Any] | None = None, *, experiment_dir: str | Path | None = None, streamlit_module: StreamlitAPI | None = None)

Bases: object

Render core training events without owning training logic.

clear() → None

Remove transient progress elements during HPO runs.

configure(config: DeepMTPConfig | Mapping[str, Any], *, experiment_dir: str | Path | None = None) → None

Attach the finalized trainer configuration.

on_event(event: ProgressEvent | EvaluationProgressEvent) → None
on_summary(summaries: RunSummaries, *, include_train: bool, include_validation: bool) → None

Package contents

Streamlit progress renderers and configured runtime adapters.

class DeepMTP.integrations.streamlit.DeepMTP(config: DeepMTPConfig | Mapping[str, Any], instance_branch_model: Callable[[Mapping[str, Any]], torch.nn.Module] | None = None, target_branch_model: Callable[[Mapping[str, Any]], torch.nn.Module] | None = None, checkpoint_dir: str | PathLike[str] | None = None, reporter: ExperimentReporter | None = None, progress: ProgressObserver | None = None)

Bases: DeepMTP

Core DeepMTP trainer configured with Streamlit progress rendering.

class DeepMTP.integrations.streamlit.HyperBand(*args: Any, progress: HPOProgressObserver | None = None, **kwargs: Any)

Bases: HyperBand

Core Hyperband configured with Streamlit progress rendering.

class DeepMTP.integrations.streamlit.RandomSearch(*args: Any, progress: HPOProgressObserver | None = None, **kwargs: Any)

Bases: RandomSearch

Core random search configured with Streamlit progress rendering.

class DeepMTP.integrations.streamlit.StreamlitAPI(*args, **kwargs)

Bases: Protocol

Small Streamlit surface used by the progress adapters.

empty() → Any

Create an empty UI slot.

progress(value: int) → Any

Create a progress indicator.

class DeepMTP.integrations.streamlit.StreamlitHPOProgressObserver(*, streamlit_module: StreamlitAPI | None = None)

Bases: object

Render shared optimizer events in Streamlit.

on_event(event: HPOProgressEvent) → None
class DeepMTP.integrations.streamlit.StreamlitProgressObserver(config: DeepMTPConfig | Mapping[str, Any] | None = None, *, experiment_dir: str | Path | None = None, streamlit_module: StreamlitAPI | None = None)

Bases: object

Render core training events without owning training logic.

clear() → None

Remove transient progress elements during HPO runs.

configure(config: DeepMTPConfig | Mapping[str, Any], *, experiment_dir: str | Path | None = None) → None

Attach the finalized trainer configuration.

on_event(event: ProgressEvent | EvaluationProgressEvent) → None
on_summary(summaries: RunSummaries, *, include_train: bool, include_validation: bool) → None
DeepMTP.integrations.streamlit.initialize_mode(config: DeepMTPConfig | Mapping[str, Any]) → DeepMTP