Skip to content

Add gpus argument for chainerrl.misc.set_random_seed - #207

Merged
toslunar merged 2 commits into
chainer:masterfrom
muupan:improve-set-random-seed
Dec 22, 2017
Merged

Add gpus argument for chainerrl.misc.set_random_seed#207
toslunar merged 2 commits into
chainer:masterfrom
muupan:improve-set-random-seed

Conversation

@muupan

@muupan muupan commented Dec 21, 2017

Copy link
Copy Markdown
Member
  • Add gpus argument to chainerrl.misc.set_random_seed to set a seed of cupy.random as well as random and numpy.random.
  • Add docstring and tests

@muupan

muupan commented Dec 21, 2017

Copy link
Copy Markdown
Member Author

The test passed with cupy and a single gpu.

I also manually checked with two gpus:

$ python -c "import cupy; import chainerrl; chainerrl.misc.set_random_seed(0, gpus=(0,1)); cupy.cuda.Device(0).use(); print(cupy.random.rand())"
0.5615491552815766
$ python -c "import cupy; import chainerrl; chainerrl.misc.set_random_seed(0, gpus=(0,1)); cupy.cuda.Device(1).use(); print(cupy.random.rand())"
0.5615491552815766
$ python -c "import cupy; import chainerrl; chainerrl.misc.set_random_seed(1, gpus=(0,1)); cupy.cuda.Device(0).use(); print(cupy.random.rand())"
0.27550817398125504
$ python -c "import cupy; import chainerrl; chainerrl.misc.set_random_seed(1, gpus=(0,1)); cupy.cuda.Device(1).use(); print(cupy.random.rand())"
0.27550817398125504

@toslunar toslunar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

Let me leave a survey on seeds.

  • random.seed (with the current default version=2) uses all the bits of int.
  • numpy.random.seed accepts int in [0, 2 ** 32).
  • cupy.random.seed accepts int that can be casted safely to uint64.

@toslunar
toslunar merged commit 5d2507d into chainer:master Dec 22, 2017
@muupan muupan added this to the v0.4 milestone Jul 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants