question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to predict in multiprocess environment

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
hill-acommented, Jun 3, 2019

Without multiprocess environment learning is very slow

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.

0reactions
araffincommented, Jun 15, 2019
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found