test(train): add GPU bitwise-reproducibility test and document determinism#57
Open
Chouffe wants to merge 3 commits into
Open
test(train): add GPU bitwise-reproducibility test and document determinism#57Chouffe wants to merge 3 commits into
Chouffe wants to merge 3 commits into
Conversation
…inism Same-seed training is bitwise reproducible on GPU as well as CPU: Trainer(deterministic=True) enables strict use_deterministic_algorithms and sets CUBLAS_WORKSPACE_CONFIG. The GPU twin of the reproducibility test guards this (skipped where CUDA is unavailable, e.g. CI). README documents the guarantee and its scope: same seed + same device type + same torch/CUDA versions; CPU vs GPU (or different GPU models) diverge by floating-point rounding, which is inherent. Closes #36
Review follow-ups: the README guarantee now says same GPU model (not device type, which two different GPUs share) and scopes the test to what it actually asserts — same-seed weight reproducibility; optimizer state and best-epoch selection were verified end-to-end, not by the test. The GPU test drops the different-seed negative control (seeds diverge init on CPU, so it proves nothing GPU-specific) and _fit_once_transformer's accelerator parameter is now required.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #36.
Summary
Exploration for #36 found training is already fully deterministic —
L.seed_everything(seed, workers=True)+Trainer(deterministic=True)cover everything, including on GPU (Lightning setsCUBLAS_WORKSPACE_CONFIG=:4096:8and enables stricttorch.use_deterministic_algorithmsitself). This PR locks the property in:skipifno CUDA — skips onubuntu-latestCI, runs on dev GPU machines). Strict deterministic mode means any future nondeterministic op (e.g. mixed precision, attention backend changes) raises instead of silently diverging; the test catches the rest.Determinismsection stating the guarantee and its scope.Verification (RTX 4070 Ti SUPER)
vit_small_patch14_dinov2.lvd142m, finetune last block, dropout 0.1, full augment pipeline), same seed, two GPU fits: 0/202 weight tensors differ.train.pyCLI on a 32+8-sequence subset of the real data, two runs: checkpoints bitwise identical — weights, optimizer state, best epoch, andbest val/f1equal to the last float bit.Test plan
uv run pytest tests/test_reproducibility.py -v→ 2 passed (GPU machine)CUDA_VISIBLE_DEVICES="" uv run pytest tests/test_reproducibility.py -v→ 1 passed, 1 skipped (CI behavior)make lintclean