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

Fix multi-gpu seeds #162

Merged
merged 1 commit into from
May 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion rl_games/torch_runner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
import numpy as np
import random
import copy
Expand Down Expand Up @@ -55,20 +56,34 @@ def reset(self):

def load_config(self, params):
self.seed = params.get('seed', None)
if self.seed is None:
self.seed = int(time.time())

print("params['config'].get('multi_gpu', False)", params['config'].get('multi_gpu', False))
if params["config"].get('multi_gpu', False):
import horovod.torch as hvd

hvd.init()
self.seed += hvd.rank()
print(f"self.seed = {self.seed}")

self.algo_params = params['algo']
self.algo_name = self.algo_params['name']
self.exp_config = None

if self.seed:

torch.manual_seed(self.seed)
torch.cuda.manual_seed_all(self.seed)
np.random.seed(self.seed)
random.seed(self.seed)

# deal with environment specific seed if applicable
if 'env_config' in params['config']:
if not 'seed' in params['config']['env_config']:
params['config']['env_config']['seed'] = self.seed
else:
if params["config"].get('multi_gpu', False):
Copy link
Owner

Choose a reason for hiding this comment

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

did you mean true here?

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 assume by default multi_gpu is False?

Copy link
Owner

Choose a reason for hiding this comment

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

ah yes. I read it in the wrong way like if multi gpu is false then.

params['config']['env_config']['seed'] += hvd.rank()

config = params['config']
config['reward_shaper'] = tr_helpers.DefaultRewardsShaper(**config['reward_shaper'])
Expand Down