Composite framework API¶
Component interfaces¶
interfaces
¶
Pluggable component interfaces for the composite WSI/VLM model.
Four building blocks compose into one model:
backbone -> SELECTORS (pipeline) -> PROMPTS (bank) -> AGGREGATORS (fused)
Selectors stack sequentially. Prompts fuse into a bank. Aggregators run in parallel and fuse via one of two modes:
- "logit_ensemble" (Level 1): each aggregator runs end-to-end and produces (C,) logits; logits combine at the very end. Most decoupled, most robust if any single aggregator is buggy.
- "vector_fusion" (Level 2): each aggregator returns a slide vector (D,); vectors are fused into one (D,) and a shared classifier head produces (C,). Tighter coupling, often higher capacity.
The user picks the mode in YAML.
PromptBank
dataclass
¶
Output of the prompt block.
text_features is the canonical [classes, dimension] tensor every
aggregator can consume. aux is a mapping of optional tensors that
specific aggregators may want (e.g. SLIP needs tissue prompts,
MAPLE-graph optionally provides per-entity features).
PatchSelector
¶
Bases: Module, ABC
Filters / re-orders patches before aggregation.
Implementations are functions (patches, text_features, coords) -> patches', where patches' is a (possibly smaller) subset of the input. Selectors stack: the output of one feeds the next.
PromptModule
¶
Bases: Module, ABC
Produces text features.
Each prompt module returns a (C, D) tensor in text_features.
Auxiliary tensors that don't fit that shape (entity attributes,
tissue prompts, chain-of-diagnosis hierarchy) go in aux.
Many prompt modules are themselves composed of CoOp-style learnable
context vectors; common code lives in common.models.coop.
Aggregator
¶
Bases: Module, ABC
Pools patch features into a slide-level prediction.
Each aggregator implements BOTH return modes:
forward_vector: returns (D,) slide vector (no classification)forward_logits: returns (C,) class logits (with internal head)
The composite model picks whichever mode matches the configured fusion strategy. Subclasses can implement only one of the two methods and inherit a default for the other (vector -> linear head; logits -> not vector-recoverable, raises).
forward_vector
¶
forward_vector(patches: Tensor, bank: PromptBank) -> Tensor
Return a pre-classification slide vector when supported.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the aggregator exposes only logits. |
Source code in common/composite/interfaces.py
Recipe
¶
Bases: ABC
Bundles optimizer + scheduler + epoch count for one paper's recipe.
Model¶
CompositeModel
¶
CompositeModel(
cfg: Dict[str, Any],
backbone: Module,
tokenizer: Any,
info: Any,
encoder_bundle: Optional[EncoderBundle] = None,
)
Bases: Module
Compose patch selectors, prompt modules, and slide aggregators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
Dict[str, Any]
|
Composite configuration containing class metadata and component registries. |
required |
backbone
|
Module
|
Native vision-language backbone used by prompt modules. |
required |
tokenizer
|
Any
|
Tokenizer paired with |
required |
info
|
Any
|
Legacy backbone dimension metadata. |
required |
encoder_bundle
|
Optional[EncoderBundle]
|
Validated capability-aware bundle for components that use black-box encoder operations. |
None
|
The model accepts one slide at a time as [patches, dim] or
[1, patches, dim] and returns class logits plus optional auxiliary loss
inputs.
Source code in common/composite/model.py
forward
¶
forward(
patches: Tensor,
coords: Tensor = None,
return_extras: bool = False,
) -> Tuple[Tensor, Dict[str, Any]]
Run the configured selector, prompt, and aggregation pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
patches
|
Tensor
|
One variable-length patch bag. |
required |
coords
|
Tensor
|
Optional patch coordinates aligned with |
None
|
return_extras
|
bool
|
Include tensors used by optional composite losses. |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Dict[str, Any]]
|
A pair containing class logits and an auxiliary tensor mapping. |