#🔒 Help with passing connection to existing pool

15 messages · Page 1 of 1 (latest)

wanton imp
#

Have a somewhat complex issue that hinges around the distributed message passing as in this pastebin file:

https://paste.pythondiscord.com/DIRA

I got the following traceback when using the above code:

https://paste.pythondiscord.com/CF4Q

Outline:

  1. The context is vectorized reinforcement learning using SB3
  2. I am modifying their implementation of a class called SubprocVecEnv
  3. The original implementation used multiprocessing
  4. I'm trying to use billiard to get better memory control of the child proccesses
  5. Each environment in the vectorized environment has a communication pipe to the parent process that manages the overall state of the training process

Previous implementation generated ctx.Processes in the start_worker method, and this worked. My motivation is to get more control over the resource allocation of these processes, either using Billiard, Celery's prefork worker model, or something else.

lime pollenBOT
#

@wanton imp

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

cobalt zenith
#

I think you're trying to pass a multiprocessing.Connection to a billiard.Pool

#

You'll need to use a billiard.Connection instead

wanton imp
#

I also saw those error messages in the traceback referencing multiprocessing instead of billiard but the way I'm creating the connection is like this:

import billiard as mp

...

        ctx = mp.get_context(start_method)
        self.pool = ctx.Pool()

        self.remotes, self.work_remotes = zip(*[ctx.Pipe() for _ in range(n_envs)])
cobalt zenith
#

Are you still using celery?

wanton imp
#

celery launches prefork processes that launch this process yes

cobalt zenith
#

Yeah so I'd probably ditch celery here

wanton imp
#

yeah switching back to threads still didn't work, I think you were right about me somehow using mp even though I thought I changed the code, probably just a stateful thing where I forgot to restart the server after saving:
https://paste.pythondiscord.com/H2DQ

#

do I want to completely ditch celery or add another layer of abstraction between celery and sb3

#

right now the way it works is I have a web server that talks to celery and they both talk to the DB

#

I have celery because I want to send the requests to a distributed queue instead of having the actual heavy lifting be done by the webserver

#

I do think a large part of the memory usage has to do with trying to use the sb3 code with celery because I didn't have any resource issues except for GPU until I put this stuff in a celery app

lime pollenBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.