Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ uv run --extra benchmarks python benchmarks/regression_benchmark.py
python benchmarks/regression_benchmark.py
```

## Reproducibility

Both scripts fix every random seed and restrict PyTorch to deterministic kernels, so repeated runs on the same machine and software stack produce identical results.

On CUDA, one more setting is needed and has to come from the environment:

```bash
export CUBLAS_WORKSPACE_CONFIG=:4096:8
```

Without it, `torch.use_deterministic_algorithms(True)` raises as soon as a cuBLAS reduction runs.

Results still differ across GPU architectures, CUDA/cuDNN versions and PyTorch releases: floating-point addition is not associative, so a different kernel sums in a different order. The numbers reported here were produced on the hardware listed under [Runtime](#runtime); expect small deviations elsewhere.

## Requirements

- **Python:** 3.10–3.13
Expand Down
7 changes: 7 additions & 0 deletions benchmarks/classification_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ def set_seed(seed=42):
torch.cuda.manual_seed_all(seed)


def enable_determinism():
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
torch.use_deterministic_algorithms(True)


enable_determinism()
set_seed(42)
print(f"Running Bensemble Benchmark on {DEVICE}")

Expand Down
20 changes: 20 additions & 0 deletions benchmarks/regression_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Regression benchmark: PBP vs VI (ELBO) vs Laplace (K-FAC) vs MAP baseline on UCI datasets.
"""

import random
import time
from pathlib import Path

Expand All @@ -25,6 +26,7 @@
f"Running Bensemble Regression Benchmark on {DEVICE} (PBP itself always runs on CPU — see run_pbp)"
)

SEED = 42
HIDDEN = 50
N_SPLITS = 5
TEST_FRACTION = 0.1
Expand All @@ -36,6 +38,23 @@
RESULTS_DIR = Path("results_regression")
RESULTS_DIR.mkdir(exist_ok=True)


def set_seed(seed=SEED):
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
if torch.cuda.is_available():
torch.cuda.manual_seed_all(seed)


def enable_determinism():
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
torch.use_deterministic_algorithms(True)


enable_determinism()

DATASETS = {
"yacht": {"uci_id": None, "target_col": None, "direct": True},
"energy": {"uci_id": 242, "target_col": "Y1"},
Expand Down Expand Up @@ -314,6 +333,7 @@ def main():
Xtr_raw, ytr_raw, Xte_raw, yte_raw
)

set_seed(SEED + split_idx)
mean, var, elapsed = runner(Xtr, ytr, Xte, yte, epochs=NUM_EPOCHS)
rmse, nlpd = regression_metrics(mean, var, yte, y_mean, y_std)

Expand Down
Loading