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.

Increasing memory usage throughout run time

See original GitHub issue

Describe the bug Ever increasing memory usage while running. Each process has a similar amount of usage that increases linearly with the time it runs for. Eventually resulting in slow performance or system instability on long runs.

Code example

import gym

from stable_baselines.common.policies import MlpPolicy
from stable_baselines.common.vec_env import SubprocVecEnv
from stable_baselines import A2C

n_cpu = 8
env = SubprocVecEnv([lambda: gym.make('CartPole-v1') for _ in range(n_cpu)])

model = A2C(MlpPolicy, env)
model.learn(total_timesteps=int(1e10))

This appears to be the minimal code needed to view the memory issues. It becomes more obvious if you increase the number of processes, or in larger environments.

Initially ran on some custom environments from https://github.com/rubenrtorrado/GVGAI_GYM and also tried it with DQN or a CnnPolicy both of which still had this problem.

System Info Describe the characteristic of your environment:

  • Tried on a Ubuntu Desktop and a MacBook Pro
  • Library installed via pip (tensorflow too)
  • GTX 1080 for Desktop, None in Laptop
  • Python 3.6.8
  • Tensorflow 1.12.0 (gpu version for desktop)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

4reactions
ArthurFirminocommented, Jan 31, 2019

I have also encountered this issue, as has someone else on the openai repo, https://github.com/openai/baselines/issues/804.

I have determined this to be a bug with the latest version of numpy, in particular 1.16.0. Downgrading to numpy==1.15.4 fixed the issue for me.

Below is a minimal, complete, and verifiable example of the bug:

from multiprocessing import Process, Pipe
from os import getpid
import numpy as np

def f(conn):
    print("Sub pid:", getpid())
    while True:
        a = np.zeros(shape=(64,64,8), dtype=np.uint8)
        conn.send(a)
        conn.recv()

if __name__ == "__main__":
    parent_conn, child_conn = Pipe()
    p = Process(target=f, args=(child_conn,))
    print("Main pid:", getpid())
    p.start()
    while True:
        a = parent_conn.recv()
        parent_conn.send('')

On numpy==1.16.0 this will quickly OOM, on 1.15.4 it is fine. In their release notes they said they changed to a different pickling protocol, which I guess is the source of the bug.

edit: https://github.com/numpy/numpy/issues/12896

2reactions
ArthurFirminocommented, Feb 1, 2019

@hill-a @Kuldr Confirmed numpy 1.16.1 fixes the issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix High RAM Memory Usage Issue on Windows 11/10 [10 ...
1. Close Unnecessary Running Programs/Applications; 2. Disable Startup Programs; 3. Defragment Hard Drive & Adjust Best Performance; 4. Fix Disk ...
Read more >
Why does process memory usage increase in runtime? - Quora
If the RAM memory demands of a process continually increase over the runtime of a program your program most likely has a memory...
Read more >
Windows 10 High Memory Usage [Causes and Solutions]
Fix 1: Close unnecessary programs. If the high memory usage is caused by the computer running multiple programs at the same time, users...
Read more >
High Memory utilization and their root causes | Dynatrace
Increasing memory is the obvious workaround for memory leaks or badly written software. Let's discuss the two most common causes for Java high...
Read more >
Why does my App's Memory Use Grow Over Time? - Schneems
It takes a while, but over time, memory use doubles. The height of thread one and two roughly max out at about 390...
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