Native multi-threading backend #382
Open
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
To use this: In your
config.ini, setbackend=Multithreadinginstead ofMultiprocessingunder[vec]to take advantage of it. For envs that are CPU deep (i.e. envs that do a lot of computation perc_step) but not GPU wide (i.e. not too many params), this offers a nice speed up anywhere from 1.1x to 3x as fast.For envs that have a very few CPU cycles as part of
c_step, this may not provide a good speedup and in fact may be slower (see below for results). You can also limit the max number of threads saymax_num_threads=4under[vec]if your env is very short and still take advantage of native multi-threading.Performance Comparison: Multithreading vs. Multiprocessing
Notes:
(*) For some envs, it's better to do Multiprocessing or even Serial with a worker just going through the envs one by one rather than shard it across too many threads. I verified this matches the perf when limiting
max_num_threadsto be a small number (or even 0 to force Serial mode) rather than spread to all cores.(**) GPU bound. Most time spent copying/learning.