Repository navigation
[Core] Add initial foundational configurations and flags for fork server - #67356
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
213b493 to
9d6cc18
Compare
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
ff3dc87 to
0512a5e
Compare
| os.environ["OMP_NUM_THREADS"] = str(omp_num_threads) | ||
| # If torch was pre-imported before fork(), its OpenMP thread pool is already | ||
| # initialized and ignores subsequent os.environ["OMP_NUM_THREADS"] updates. | ||
| if "torch" in sys.modules: |
There was a problem hiding this comment.
Prefer a constant str list (or just str if we can validate torch is the only sys module that needs this branching logic) here rather than hard-coding the "torch" module name
There was a problem hiding this comment.
Added a THREAD_POOL_MODULES var to iterator over.
|
created a Ray issue here: #67446 to link in the PRs so that they're easier to track |
59b838c to
5bcd33a
Compare
6dfd31c to
be33589
Compare
|
cc: @MengjinYan @edoakes for Ray core review, or if you know someone else able to approve that it'd be good to work with on this |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Reviewed by Cursor Bugbot for commit b97eb39. Configure here.
Kunchd
left a comment
There was a problem hiding this comment.
Thanks for the PR! The first milestone looks good, and I look forward to the future milestones! I mainly left some questions to clarify my understanding of the change.
| ) | ||
| if stripped not in validated: | ||
| validated.append(stripped) | ||
| return validated |
There was a problem hiding this comment.
If the validated module doesn't actually exist, what's our plan for surfacing the import error to the user?
There was a problem hiding this comment.
This is actually being taken care of in the follow-up PR (#67514 but WIP), it will catch and log preload import errors in the fork server logs without failing server startup. If the task or actor imports that missing module at runtime, Python will raise ModuleNotFoundError to the user. Please let me know if you have thoughts on this!
| num_threads = str(max(math.floor(num_assigned_cpus), 1)) | ||
| for name in unset_env_vars: | ||
| os.environ[name] = num_threads | ||
| if "OMP_NUM_THREADS" in unset_env_vars: |
There was a problem hiding this comment.
In the design doc, if I'm understanding the diagram correctly, the forkserver with the specified modules is started before the env vars is configured. If the user specifies OMP_NUM_THREADS to configure torch threads in the runtime env vars, would that configuration be ignored here?
There was a problem hiding this comment.
No, it won't be ignored. This current change is only here to handle the case where the user doesn't set OMP_NUM_THREADS and Ray defaults it from num_cpus.
Followup changes will apply env_vars right after fork() and call torch.set_num_threads(...) when OMP_NUM_THREADS is set.
| RAY_LOG(WARNING) << "Worker " << pid << " pgid (" << pgid | ||
| << ") != pid; skipping SetSavedProcessGroupId to avoid " | ||
| << "signaling parent process group."; |
There was a problem hiding this comment.
Will this branch always trigger for the fork server? If so, this is intended behavior, should we be emitting at INFO level instead?
There was a problem hiding this comment.
So this branch won't trigger usually, this is just a safeguard in case setpgid fails unexpectedly. The plan is to place each forked child into its own process group via setpgid so forked workers will also have pgid == pid in normal operation.
Kunchd
left a comment
There was a problem hiding this comment.
Might need to merge master again. But everything looks good!
46e4591 to
63d36fa
Compare
6efb430 to
1f098a5
Compare
Signed-off-by: Aaron Liang <aaronliang@google.com>

Description
Sets up configuration and fork-safety needed for the Python worker fork server.
No behavior change by default (
RAY_enable_worker_fork_server=false).Key Changes
preload_modulesoption toRuntimeEnvandfork_server_socket_pathtoRuntimeEnvContextenable_worker_fork_serverandworker_fork_server_timeout_msconfig flags and forward fork server env vars toRuntimeEnvAgentinitialize_default_worker()indefault_worker.pyso forked workers can initialize directlytorchthread count, and only save worker PGID whenpgid == pid)Related issues
#67446 - Python worker fork server
Additional information
N/A