Skip to content

Adding local Random state to fit_loop #12357

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

Closed
wants to merge 1 commit into from
Closed

Adding local Random state to fit_loop #12357

wants to merge 1 commit into from

Conversation

ConcurrencyPractitioner
Copy link
Contributor

@ConcurrencyPractitioner ConcurrencyPractitioner commented Feb 27, 2019

Summary

We want to avoid using the global numpy random generator as much as possible because it could potentially modify the behavior of other methods calling it as well.

Related Issues

#12258
#12259

PR Overview

  • This PR requires new unit tests [y/n] (make sure tests are included)
  • This PR requires to update the documentation [y/n] (make sure the docs are up-to-date)
  • This PR is backwards compatible [y/n]
  • This PR changes the current API [y/n] (all API changes need to be approved by fchollet)

@ConcurrencyPractitioner
Copy link
Contributor Author

@farizrahman4u Do you think this is good?

@zachmayer
Copy link
Contributor

This is a good idea, thanks for making the PR!

@ConcurrencyPractitioner
Copy link
Contributor Author

@fchollet Think you can take a look?

@zachmayer
Copy link
Contributor

@fchollet Can you take a look?

@@ -32,7 +32,8 @@ def fit_loop(model, fit_function, fit_inputs,
initial_epoch=0,
steps_per_epoch=None,
validation_steps=None,
validation_freq=1):
validation_freq=1,
seed=113):
Copy link
Collaborator

@fchollet fchollet Mar 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not use default seeds. This would dramatically reduce randomness (effectively remove randomness since there is no user-facing way to set the seed).

@@ -180,7 +183,7 @@ def fit_loop(model, fit_function, fit_inputs,
if shuffle == 'batch':
index_array = batch_shuffle(index_array, batch_size)
elif shuffle:
np.random.shuffle(index_array)
rng.shuffle(index_array)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous version already does not modify the global behavior of np.random. The purpose of this PR is not clear to me.

@ConcurrencyPractitioner
Copy link
Contributor Author

ConcurrencyPractitioner commented Mar 17, 2019

Instead of using a default value, we could use system time instead. Wouldn't that vary the seed more?

@fchollet
Copy link
Collaborator

Looked at the PR one more time. np.random.shuffle(index_array) does not modify the global random state of np.random (unlike, say, np.random.seed()), so this PR does not appear to change anything other making the shuffling follow the same pattern every time (which is not a desirable behavior).

@fchollet fchollet closed this Mar 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants