Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seed_everything() runs _select_seed_randomly() even if PL_GLOBAL_SEED is set #4741

Closed
bprus opened this issue Nov 18, 2020 · 5 comments · Fixed by #4743
Closed

seed_everything() runs _select_seed_randomly() even if PL_GLOBAL_SEED is set #4741

bprus opened this issue Nov 18, 2020 · 5 comments · Fixed by #4743
Assignees
Labels
bug Something isn't working priority: 1 Medium priority task

Comments

@bprus
Copy link

bprus commented Nov 18, 2020

🐛 Bug

There is a bug in pl.utilities.seed.seed_everything().

The problem is here:
https://github.com/PyTorchLightning/pytorch-lightning/blob/1.0.5/pytorch_lightning/utilities/seed.py#L44

If None is passed as a seed:
seed = os.environ.get("PL_GLOBAL_SEED", _select_seed_randomly(min_seed_value, max_seed_value))
is run. And _select_seed_randomly is run even if PL_GLOBAL_SEED is present in os.environ.

The seed is set properly, but there is a warning displayed that suggests a different seed had been set. This introduces some confusion, especially during training with ddp.

To Reproduce

import pytorch_lightning as pl
import os

pl.utilities.seed.seed_everything()
seed = os.environ.get('PL_GLOBAL_SEED')
print(seed)

pl.utilities.seed.seed_everything()
seed = os.environ.get('PL_GLOBAL_SEED')
print(seed)

Expected behavior

The code above produces the following output:

No correct seed found, seed set to 3315818503
3315818503
No correct seed found, seed set to 1668269197
3315818503

_select_seed_randomly(min_seed_value, max_seed_value) should only be run when there is no PL_GLOBAL_SEED set.

Environment

  • PyTorch Lightning Version (e.g., 1.0): 1.0.5
@bprus bprus added bug Something isn't working help wanted Open to be worked on labels Nov 18, 2020
@github-actions
Copy link
Contributor

Hi! thanks for your contribution!, great first issue!

@SeanNaren
Copy link
Contributor

Thanks for the issue! Could you verify #4743 fixes this?

@bprus
Copy link
Author

bprus commented Nov 19, 2020

It seems that this fixes my problem. But it introduces another one as any seed is now incorrect because of:
if not (seed < min_seed_value <= seed <= max_seed_value):
(someone already pointed it in PR comments)

@Borda Borda added the good first issue Good for newcomers label Dec 1, 2020
@stale
Copy link

stale bot commented Dec 31, 2020

This issue has been automatically marked as stale because it hasn't had any recent activity. This issue will be closed in 7 days if no further activity occurs. Thank you for your contributions, Pytorch Lightning Team!

@stale stale bot added the won't fix This will not be worked on label Dec 31, 2020
@bprus
Copy link
Author

bprus commented Jan 4, 2021

Still waiting for a fix.

@stale stale bot removed the won't fix This will not be worked on label Jan 4, 2021
@edenlightning edenlightning removed good first issue Good for newcomers help wanted Open to be worked on labels Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority: 1 Medium priority task
Projects
None yet
4 participants