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

"add init seed" #6221

Merged
merged 4 commits into from
Dec 5, 2017
Merged

"add init seed" #6221

merged 4 commits into from
Dec 5, 2017

Conversation

dzhwinter
Copy link
Contributor

fix #6220

@@ -302,7 +312,7 @@ class MSRAInitializer(Initializer):
(https://arxiv.org/abs/1502.01852)
"""

def __init__(self, uniform=True, fan_in=None, seed=0):
def __init__(self, uniform=True, fan_in=None, seed=set_random_seed(0)):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could the user set the seed globally instead of setting the seed at each parameter initializer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't get an elegant way to implement it. Use a global seed seems ugly,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -1,7 +1,13 @@
import framework
import numpy as np

__all__ = ['Constant', 'Uniform', 'Normal', 'Xavier']
__all__ = ['Constant', 'Uniform', 'Normal', 'Xavier', 'set_random_seed']
Copy link
Contributor

Choose a reason for hiding this comment

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

set_random_seed seems a private function, if it is, do not expose it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

@@ -132,6 +132,8 @@ def __call__(self, var, block):
assert isinstance(var, framework.Variable)
assert isinstance(block, framework.Block)
# Initialization Ops should be prepended and not appended
if block.program.random_seed != 0 and self._seed == 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

If we don't consider case that user need to overwrite program default rand seed with 0, just use if self._seed == 0 is fine, maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's true.

Copy link
Contributor

@typhoonzero typhoonzero left a comment

Choose a reason for hiding this comment

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

LGTM

@dzhwinter dzhwinter merged commit 4eac85c into PaddlePaddle:develop Dec 5, 2017
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.

need to set global random seed
3 participants