API
thunder.benchmark.benchmark(model, dataset, task, loading_mode='online_loading', lora=False, ckpt_save_all=False, online_wandb=False, recomp_embs=False, retrain_model=False, **kwargs)
Runs a benchmark for a pretrained model on a dataset with a task-specific approach.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The name of the pretrained model to use. |
required |
dataset
|
str
|
The name of the dataset to use. |
required |
task
|
str
|
The name of the task to perform. |
required |
loading_mode
|
str
|
The type of data loading to use. |
'online_loading'
|
lora
|
bool
|
Whether to use LoRA (Low-Rank Adaptation) for model adaptation. Default is False. |
False
|
ckpt_save_all
|
bool
|
Whether to save all checkpoints during training. Default is False which means that only the best is saved. |
False
|
online_wandb
|
bool
|
Whether to use online mode for Weights & Biases (wandb) logging. Default is False which means offline mode. |
False
|
recomp_embs
|
bool
|
Whether to recompute embeddings if already saved. |
False
|
retrain_model
|
bool
|
Whether to retrain model if already trained and saved ckpts. |
False
|
Source code in src/thunder/benchmark.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
thunder.download_datasets(datasets, make_splits=False)
Downloads the benchmark datasets specified in the list of dataset names.
This function requires the $THUNDER_BASE_DATA_FOLDER environment variable to be set,
which indicates the base directory where the datasets will be downloaded.
The list of all available datasets
- bach
- bracs
- break_his
- ccrcc
- crc
- esca
- mhist
- ocelot
- pannuke
- patch_camelyon
- segpath_epithelial
- segpath_lymphocytes
- spider_breast
- spider_colorectal
- spider_skin
- spider_thorax
- tcga_crc_msi
- tcga_tils
- tcga_uniform
- wilds
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datasets
|
List[str] or str
|
A dataset name string or a List of dataset names to download or one of the following aliases: |
required |
make_splits
|
bool
|
Whether to generate data splits for the datasets. Defaults to False. |
False
|
Source code in src/thunder/datasets/download.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
thunder.download_models(models)
Download model checkpoints from Hugging Face.
The list of all available models
- uni
- uni2h
- virchow
- virchow2
- hoptimus0
- hoptimus1
- conch
- titan
- phikon
- phikon2
- hiboub
- hiboul
- midnight
- keep
- quiltb32
- plip
- musk
- dinov2base
- dinov2large
- dinov3vits16pretrainlvd1689m
- dinov3vitb16pretrainlvd1689m
- dinov3vitl16pretrainlvd1689m
- vitbasepatch16224in21k
- vitlargepatch16224in21k
- clipvitbasepatch32
- clipvitlargepatch14
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models
|
List[str] or str
|
a list of model names or single a model name str. |
required |
Source code in src/thunder/models/download.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
thunder.generate_splits(datasets)
Generates the data splits for all datasets in input list.
This function requires the $THUNDER_BASE_DATA_FOLDER environment variable to be set,
which indicates the base directory where the datasets will be downloaded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datasets
|
List[str]
|
List of dataset names to generate splits for or one of the following aliases: |
required |
Source code in src/thunder/datasets/data_splits.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
thunder.models.PretrainedModel
Bases: Module, ABC
Abstract class to be inherited by custom pretrained models.
Source code in src/thunder/models/pretrained_models.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
get_linear_probing_embeddings(x)
abstractmethod
Returns the embeddings for linear probing.
Source code in src/thunder/models/pretrained_models.py
22 23 24 25 | |
get_segmentation_embeddings(x)
abstractmethod
Returns the pixel dense embeddings for segmentation.
Source code in src/thunder/models/pretrained_models.py
27 28 29 30 | |
get_transform()
abstractmethod
Returns the transform function to be applied to the input images.
Source code in src/thunder/models/pretrained_models.py
17 18 19 20 | |
thunder.models.get_model_from_name(model_name, device)
Loading pretrained model from input name.
The list of all available models
- uni
- uni2h
- virchow
- virchow2
- hoptimus0
- hoptimus1
- provgigapath
- conch
- titan
- phikon
- phikon2
- hiboub
- hiboul
- midnight
- kaiko_vits8
- kaiko_vits16
- kaiko_vitb8
- kaiko_vitb16
- keep
- quiltb32
- plip
- musk
- dinov2base
- dinov2large
- dinov3vits16pretrainlvd1689m
- dinov3vitb16pretrainlvd1689m
- dinov3vitl16pretrainlvd1689m
- vitbasepatch16224in21k
- vitlargepatch16224in21k
- clipvitbasepatch32
- clipvitlargepatch14
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
The name of the model to use. |
required |
device
|
str
|
Device to use (cpu, cuda). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
model |
Module
|
Pytorch model instance. |
transform |
Compose
|
Transform to apply to input image. |
get_embeddings |
Callable
|
Function to extract embeddings. |
output function get_embeddings signature.
- src (torch.Tensor): Batch of transformed images with shape (B, 3, H, W).
- pretrained_model (torch.nn.Module): Model to extract embeddings with.
- pooled_emb (bool): Whether to output pooled (True) or spatial (False) embeddings.
Source code in src/thunder/models/pretrained_models.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |