Trying to initialize multiple stable_baselines3 models, each in their own process
The following code hangs when using Pool to initialize models. If the initialize_model(1)
line is commented, the code runs to completion
What is the issue with running initialize_model(1)
before multiprocessing, and is there a way to fix it?
(I am aware that stable_baselines3 has its own parallelization functionality, I cannot use it due to the specifics of my use case)
<code>from multiprocessing import Pool
# pathos has same issue
# from pathos.multiprocessing import Pool
from stable_baselines3 import PPO
from stable_baselines3.ppo import MlpPolicy
def initialize_model(t):
model = PPO(policy=MlpPolicy, env='CartPole-v1', batch_size=128, n_steps=128)
return 1
# TODO: with the following line uncommented, it does not work
initialize_model(1)
with Pool(processes=2) as pool:
test = pool.map(initialize_model, [None for _ in range(2)])
print('done')
</code>
<code>from multiprocessing import Pool
# pathos has same issue
# from pathos.multiprocessing import Pool
from stable_baselines3 import PPO
from stable_baselines3.ppo import MlpPolicy
def initialize_model(t):
model = PPO(policy=MlpPolicy, env='CartPole-v1', batch_size=128, n_steps=128)
return 1
# TODO: with the following line uncommented, it does not work
initialize_model(1)
with Pool(processes=2) as pool:
test = pool.map(initialize_model, [None for _ in range(2)])
print('done')
</code>
from multiprocessing import Pool
# pathos has same issue
# from pathos.multiprocessing import Pool
from stable_baselines3 import PPO
from stable_baselines3.ppo import MlpPolicy
def initialize_model(t):
model = PPO(policy=MlpPolicy, env='CartPole-v1', batch_size=128, n_steps=128)
return 1
# TODO: with the following line uncommented, it does not work
initialize_model(1)
with Pool(processes=2) as pool:
test = pool.map(initialize_model, [None for _ in range(2)])
print('done')
New contributor
pav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.