Common
Common components shared across the benchmarking framework.
This module contains shared dataclasses and utility functions to avoid circular imports between modules. It provides the core data structures and measurement utilities used throughout the benchmarking framework.
BenchmarkResult
dataclass
Results from benchmarking a dataloader.
This class stores essential metrics and metadata about a dataloader benchmark run for CSV export and analysis.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Name/description of the benchmark |
warmup_time_seconds |
float
|
Time spent in warmup phase |
dataset_instantiation_time_seconds |
float
|
Time to load/create dataset only |
dataloader_instantiation_time_seconds |
float
|
Time to wrap dataset in dataloader only |
madvise_interval |
Optional[int]
|
Memory advice interval setting used |
data_path |
Optional[str]
|
Path to dataset used for benchmarking |
max_time_seconds |
Optional[float]
|
Maximum time limit set for the benchmark |
shuffle |
Optional[bool]
|
Whether the dataloader was shuffled |
num_workers |
Optional[int]
|
Number of worker processes used for data loading
|
epoch_results |
Optional[List[Dict[str, Any]]]
|
List of per-epoch benchmark results |
Source code in bionemo/scspeedtest/common.py
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 |
|
__post_init__()
Calculate derived metrics from epoch results.
Source code in bionemo/scspeedtest/common.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
download_example_dataset(cache_dir='.', filename='example_data.h5ad')
Download a small example AnnData dataset for testing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_dir
|
str
|
Directory to save the downloaded file (default: current directory) |
'.'
|
filename
|
str
|
Name of the file to save (default: "example_data.h5ad") |
'example_data.h5ad'
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Path to the downloaded file |
Raises:
Type | Description |
---|---|
RuntimeError
|
If download fails |
Source code in bionemo/scspeedtest/common.py
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 |
|
export_benchmark_results(results, output_prefix='benchmark_data')
Append benchmark results to detailed breakdown CSV, never overwriting existing data.
This function appends benchmark results to an existing CSV file or creates a new one if it doesn't exist. It never overwrites existing files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
results
|
Union[BenchmarkResult, List[BenchmarkResult]]
|
Single BenchmarkResult or list of BenchmarkResults to append |
required |
output_prefix
|
str
|
Prefix for the CSV filename |
'benchmark_data'
|
Source code in bionemo/scspeedtest/common.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 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 181 182 183 184 185 186 187 188 189 190 |
|
get_batch_size(batch)
Determine the size of a batch.
This function attempts to determine the batch size from various common batch formats including PyTorch tensors, lists, and dictionaries with common keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
Any
|
The batch object to measure |
required |
Returns:
Type | Description |
---|---|
int
|
Number of samples in the batch |
Source code in bionemo/scspeedtest/common.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
get_disk_size(path)
Get disk size of a file or directory in MB.
Tested on MacOS and Linux.
Source code in bionemo/scspeedtest/common.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
|
measure_peak_memory_full(func, *args, sample_interval=0.05, child_refresh_interval=5.0, multi_worker=False, **kwargs)
Measure peak & average memory while running func
.
If multi_worker=True, uses PSS across the process tree (slower but includes children). Otherwise uses RSS of just the main process (lightweight).
Returns:
Type | Description |
---|---|
(result, baseline_mib, peak_mib, avg_mib, delta_mib, final_mib, duration_s) |
Source code in bionemo/scspeedtest/common.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|