Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move OMP_NUM_THREADS setting into servlet to avoid setting it on import #731

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions runhouse/servers/env_servlet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
import traceback
from functools import wraps
from typing import Any, Dict, Optional
Expand Down Expand Up @@ -69,6 +70,20 @@ async def __init__(self, env_name: str, *args, **kwargs):
setup_cluster_servlet=ClusterServletSetupOption.GET_OR_FAIL,
)

# Ray defaults to setting OMP_NUM_THREADS to 1, which unexpectedly limit parallelism in user programs.
# We delete it by default, but if we find that the user explicitly set it to another value, we respect that.
# This is really only a factor if the user set the value inside the VM or container, or inside the base_env
# which a cluster was initialized with. If they set it inside the env constructor and the env was sent to the
# cluster normally with .to, it will be set after this point.
# TODO this had no effect when we did it below where we set CUDA_VISIBLE_DEVICES, so we may need to move that
# here and mirror the same behavior (setting it based on the detected gpus in the whole cluster may not work
# for multinode, but popping it may also break things, it needs to be tested).
num_threads = os.environ.get("OMP_NUM_THREADS")
if num_threads is not None and num_threads != "1":
os.environ["OMP_NUM_THREADS"] = num_threads
else:
os.environ["OMP_NUM_THREADS"] = ""

self.output_types = {}
self.thread_ids = {}

Expand Down
14 changes: 0 additions & 14 deletions runhouse/servers/obj_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,6 @@ def __init__(self):
self._kv_store: Dict[Any, Any] = None
self.env_servlet_cache = {}

# Ray defaults to setting OMP_NUM_THREADS to 1, which unexpectedly limit parallelism in user programs.
# We delete it by default, but if we find that the user explicitly set it to another value, we respect that.
# This is really only a factor if the user set the value inside the VM or container, or inside the base_env
# which a cluster was initialized with. If they set it inside the env constructor and the env was sent to the
# cluster normally with .to, it will be set after this point.
# TODO this had no effect when we did it below where we set CUDA_VISIBLE_DEVICES, so we may need to move that
# here and mirror the same behavior (setting it based on the detected gpus in the whole cluster may not work
# for multinode, but popping it may also break things, it needs to be tested).
num_threads = os.environ.get("OMP_NUM_THREADS")
if num_threads is not None and num_threads != "1":
os.environ["OMP_NUM_THREADS"] = num_threads
else:
os.environ["OMP_NUM_THREADS"] = ""

async def ainitialize(
self,
servlet_name: Optional[str] = None,
Expand Down
Loading