Skip to content

Commit

Permalink
Fix seed in test to avoid interactions on global random state (#20014)
Browse files Browse the repository at this point in the history
  • Loading branch information
awaelchli authored Jun 27, 2024
1 parent df0d462 commit 3f69134
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tests/tests_pytorch/core/test_lightning_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import pytest
import torch
from lightning.pytorch import Trainer
from lightning.pytorch import Trainer, seed_everything
from lightning.pytorch.core.optimizer import LightningOptimizer
from lightning.pytorch.demos.boring_classes import BoringModel
from lightning.pytorch.loops.optimization.automatic import Closure
Expand Down Expand Up @@ -239,6 +239,8 @@ def test_lightning_optimizer_automatic_optimization_lbfgs_zero_grad(tmp_path):
"""Test zero_grad is called the same number of times as LBFGS requires for reevaluation of the loss in
automatic_optimization."""

seed_everything(0)

class TestModel(BoringModel):
def configure_optimizers(self):
return torch.optim.LBFGS(self.parameters())
Expand Down

0 comments on commit 3f69134

Please sign in to comment.