Skip to content

Comments

"add init seed"#6221

Merged
dzhwinter merged 4 commits intoPaddlePaddle:developfrom
dzhwinter:feature/config
Dec 5, 2017
Merged

"add init seed"#6221
dzhwinter merged 4 commits intoPaddlePaddle:developfrom
dzhwinter:feature/config

Conversation

@dzhwinter
Copy link
Contributor

fix #6220

"""

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

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.

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