How to predict in multiprocess environment
See original GitHub issueI am trying to use a trained model to predict on new data. The problem is that when I use multiple cpu’s (12) I get a matrix of actions instead of one row: I get a row for every process spawned. Do I need to average the results by columns? Is this the correct approach?
# multiprocess environment
n_cpu = 12
env = PortfolioEnv(history=history, abbreviation=instruments, steps=settings['steps'], window_length=settings['window_length'])
env = SubprocVecEnv([lambda: env for i in range(n_cpu)])
mdl = 'currencies_20050101_20180101_10000_3000_5_return'
model = PPO2.load(mdl)
# intialized here
obs = env.reset()
states = model.initial_state # get the initial state vector for the reccurent network
dones = np.zeros(states.shape[0]) # set all environment to not done
action, _states = model.predict(obs, states, dones)
weights = np.mean(action, axis=0)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:18 (9 by maintainers)
Top Results From Across the Web
multiprocessing for keras model predict with single GPU
I want to speed up the prediction procedure using multiprocessing lib with python2.7. The main idea is using different subprocesses to scan ...
Read more >Speeding Up and Perfecting Your Work Using Parallel ...
A detailed guide of Python multiprocessing vs. PySpark mapPartition. In science, behind every achievement is grinding, rigorous work.
Read more >Python Multiprocessing: The Complete Guide
We may want to know the number of CPU cores available. This can be determined via the multiprocessing.cpu_count() function.
Read more >PPO2 — Stable Baselines 2.10.3a0 documentation
For multiprocessing, it uses vectorized environments compared to PPO1 which ... _states = model.predict(obs) obs, rewards, dones, info = env.step(action) ...
Read more >On the Use of Multiprocessing Computers for Global ... - DTIC
A preliminary exploration is made of the uses of multiprocessing ... Keywords Numerical weather prediction Multiprocessors Atmosphere models Weather ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, the point of multiprocessing is to speed up the learning.
If you want to still use multiprocessing, during prediction you can make observations with zeros except the first observation, then take the first action.
For LSTM policies predict, related: https://github.com/hill-a/stable-baselines/issues/166#issuecomment-502350843