Skip to content

vllm.utils.system_utils

Functions:

_maybe_force_spawn()

Check if we need to force the use of the spawn multiprocessing start method.

_release_libgomp_threads()

Join libgomp's idle worker threads so a forked child can use OpenMP.

libgomp has no fork handler: once this process has run a parallel region (e.g. any multi-threaded torch CPU op), a forked child deadlocks in its own first parallel region. Pausing the runtime (OpenMP 5.0) joins the workers; this process recreates them on its next parallel region.

_sync_visible_devices_env_vars()

Sync HIP/CUDA visibility env vars before spawning (ROCm only).

decorate_logs(process_name=None, *, skip_if_decorated=False)

Add vLLM process metadata to subsequent log records.

find_loaded_libraries(lib_name)

According to https://man7.org/linux/man-pages/man5/proc_pid_maps.5.html, the file /proc/self/maps contains the memory maps of the process, which includes the shared libraries loaded by the process. We can use this file to find the path of the loaded library.

get_mp_context()

Get a multiprocessing context with a particular method (spawn or fork). By default we follow the value of the VLLM_WORKER_MULTIPROC_METHOD to determine the multiprocessing method (default is fork). However, under certain conditions, we may enforce spawn and override the value of VLLM_WORKER_MULTIPROC_METHOD.

kill_process_tree(pid)

Kills all descendant processes of the given pid by sending SIGKILL.

Parameters:

  • pid

    (int) –

    Process ID of the parent process

set_env_var(key, value)

Temporarily set an environment variable.

set_process_title(name, suffix='', prefix=envs.VLLM_PROCESS_NAME_PREFIX)

Set the current process title with optional suffix.

suppress_stdout()

Suppress stdout from C libraries at the file descriptor level.

Only suppresses stdout, not stderr, to preserve error messages. Suppression is disabled when vLLM debug logging is enabled.

Example

with suppress_stdout(): # C library calls that would normally print to stdout torch.distributed.new_group(ranks, backend="gloo")

unique_filepath(fn)

Generate a unique file path by trying incrementing integers.

Note: This function has a TOCTOU race condition. Caller should use atomic operations (e.g., open with 'x' mode) when creating the file to ensure thread safety.

update_environment_variables(envs_dict)

Update multiple environment variables with logging.