Skip to content

Add an option to cap the torch thread count - #266

Open
eliasnaha wants to merge 1 commit into
edbeeching:mainfrom
eliasnaha:cap-torch-threads
Open

eliasnaha wants to merge 1 commit into
edbeeching:mainfrom
eliasnaha:cap-torch-threads

Conversation

@eliasnaha

Copy link
Copy Markdown

Torch takes one intra op thread per core by default. As soon as several game instances run next to the learner, which is the point of --n_parallel, the machine is oversubscribed and the update step slows right down. It is easy to miss because nothing fails, the run is just slow, and it gets worse the more cores the machine has. I hit this on a 32 core node where raising n_parallel stopped buying any throughput at all.

examples/stable_baselines3_hp_tuning.py:169 already calls torch.set_num_threads(1) for the same reason, so this just makes the knob reachable from the normal training path.

Adds set_torch_threads in core.utils and a --torch_num_threads flag to the sb3 example. The default is None, so nothing changes unless the flag is passed. The torch import sits inside the helper so core.utils does not pull torch in at import time.

Torch takes one intra op thread per core by default. Once several game instances
run next to the learner, which is the point of --n_parallel, the machine is
oversubscribed and the update step slows down badly. This is easy to miss because
nothing fails, the run is just slow, and it gets worse the more cores the machine
has.

Adds set_torch_threads in core.utils and a --torch_num_threads flag to the sb3
example. Default is None so nothing changes unless the flag is used. The torch
import stays inside the helper to keep core.utils free of it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant