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

[Feature Request] same random seed for every env in AsyncEval #253

Open
2 tasks done
1-Bart-1 opened this issue Jul 29, 2024 · 1 comment
Open
2 tasks done

[Feature Request] same random seed for every env in AsyncEval #253

1-Bart-1 opened this issue Jul 29, 2024 · 1 comment
Labels
check the checklist You have checked the required items in the checklist but you didn't do what is written... enhancement New feature or request

Comments

@1-Bart-1
Copy link

1-Bart-1 commented Jul 29, 2024

🚀 Feature

When training with ARS in combination with AsyncEval, multiple environments are run at the same time. When seeding these environments, all environments get a different seed. There should be an option to seed all the environments with the same seed at the start of each time ARS.evaluate_candidates() is run.

def evaluate_candidates(

def seed(self, seed: Optional[int] = None) -> List[Union[None, int]]:

Motivation

Some environments have random values generated in the reset function, for instance external factors that are random. When running evaluate_candidates, these random values can have an effect on the returned rewards, which makes that some good sets of params get bad rewards and bad params get good rewards. This makes training slower. In order to mitigate this, while still generating different random values for external values, all environments in AsyncEval should be seeded with the same random number at the start of evaluate_candidates, or this should at least be an option.

Pitch

Add the following lines to the start of ARS.evaluate_candidates:


        if async_eval is not None:
            # Multiprocess asynchronous version
            async_eval.send_jobs(candidate_weights, self.pop_size)
            results = async_eval.get_results()
            async_eval.seed(self.seed)

Add the following lines to AsyncEval.seed

  if seed is None or seed == 0:
            for idx, remote in enumerate(self.remotes):
                remote.send(("seed", np.random.randint(2**32 - 1, dtype="int64").item() )) # seed all envs with the same random seed
        else:
            for idx, remote in enumerate(self.remotes):
                remote.send(("seed", seed + idx))
        return None

And change the worker so that it doesnt return values after seed:

elif cmd == "seed":
                # Note: the seed will only be effective at the next reset
                vec_env.seed(seed=data)

Alternatives

None.

Additional context

At least in my specific environment this method leads to great improvements in training.

Checklist

  • I have checked that there is no similar issue in the repo
  • If I'm requesting a new feature, I have proposed alternatives
@1-Bart-1 1-Bart-1 added the enhancement New feature or request label Jul 29, 2024
@araffin araffin added the check the checklist You have checked the required items in the checklist but you didn't do what is written... label Jul 31, 2024
@araffin
Copy link
Member

araffin commented Jul 31, 2024

Hello,
I think you are missing an important alternative, which is also recommended: evaluating each candidate for multiple episodes to remove noise due to env stochasticity.

Also, even if you seed the each env the same the first time, they will end up in different states after each trial because of the different candidates (you also don't want to optimize for a specific seed of your env).

See issues in RL Zoo:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
check the checklist You have checked the required items in the checklist but you didn't do what is written... enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants