lazyslide_models.multimodal.Prism2

lazyslide_models.multimodal.Prism2#

class Prism2(model_path=None, token=None)#

Bases: ModelBase

prism2 🤗Hugging Face Paper Params: 4.4B CC-BY-NC-ND-4.0 [Vorontsov et al., 2026] An end-to-end multimodal pathology foundation model with clinical dialogue, PRISM2 encodes slide-level embeddings and generates free-text responses from Virchow2 tile embeddings. PRISM2 slide encoder and single-turn text generator.

The model consumes pre-extracted Virchow2 tile embeddings, not raw slides. Per slide, pass an (N, 1280) tensor (or (B, N, 1280) for a batch) extracted with:

  • the class token only (not class + mean),

  • 20x magnification (0.5 mpp),

  • 224x224 tiles,

  • background/glass tiles removed.

Requires flash-attn, and therefore a CUDA GPU: the upstream modeling_prism2.py imports flash_attn_varlen_func at module level.

encode_slide(embeddings, coords=None, attention_mask=None, **kwargs)#

Encode tile embeddings into base and diagnostic slide embeddings.

coords is accepted for interface compatibility and ignored — PRISM2’s perceiver is position-free.

respond(embeddings, prompt, attention_mask=None, **gen_kwargs)#

Generate a free-text response per slide for a single-turn prompt.

Parameters:
embeddingsarray-like

Virchow2 tile embeddings, (N, 1280) per slide or a batched (B, N, 1280) tensor.

promptstr

The user text. Use "Write a report" for report generation; any other single-turn instruction or question also works. The <|image_1|> placeholder is added by the model.

**gen_kwargs

Forwarded to HuggingFace generate (max_new_tokens, num_beams, do_sample, …).

Returns:
list of str

One decoded response per slide.

yes_no_score(embeddings, question, attention_mask=None, return_log_probs=False)#

Score one Yes/No question against every slide in the batch.

Returns P('Yes' | answer in {'Yes', 'No'}) as a (B,) tensor, or (B, 2) log-probabilities when return_log_probs=True.

This is deliberately not named score: unlike the score(embeddings, prompts) -> (B, n_classes) zero-shot contract implemented by Titan and Prism, it takes tile embeddings and a single question.