Skip to content
Draft
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
16 changes: 16 additions & 0 deletions vllm/platforms/rocm.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ def _rocm_device_count_stateless(cuda_visible_devices: str | None = None) -> int
return r


def _clear_rocprofiler_register_library():
"""Unset ROCPROFILER_REGISTER_LIBRARY so child processes do not inherit it.

librocprofiler-sdk records its own path in this variable when HIP
initializes, and librocprofiler-register reads it to decide which library
to load. A process that starts with the variable already set produces
torch profiler traces containing no GPU records at all.

The variable is set by a C-level setenv() that os.environ never sees, so
os.unsetenv() is what clears it for both forked and spawned children; the
pop() only keeps os.environ consistent if it was also exported by the user.
"""
os.unsetenv("ROCPROFILER_REGISTER_LIBRARY")
os.environ.pop("ROCPROFILER_REGISTER_LIBRARY", None)


def _sync_hip_cuda_env_vars():
"""Ensure HIP_VISIBLE_DEVICES and CUDA_VISIBLE_DEVICES are consistent.
Treats empty string as unset. Raises on genuine conflicts."""
Expand Down
11 changes: 9 additions & 2 deletions vllm/utils/system_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,21 @@ def unique_filepath(fn: Callable[[int], Path]) -> Path:


def _sync_visible_devices_env_vars():
"""Sync HIP/CUDA visibility env vars before spawning (ROCm only)."""
"""Reconcile env vars inherited by child processes (ROCm only).

Syncs HIP/CUDA visibility and clears ROCPROFILER_REGISTER_LIBRARY.
"""

if not current_platform.is_rocm():
return

from vllm.platforms.rocm import _sync_hip_cuda_env_vars
from vllm.platforms.rocm import (
_clear_rocprofiler_register_library,
_sync_hip_cuda_env_vars,
)

_sync_hip_cuda_env_vars()
_clear_rocprofiler_register_library()


def _maybe_force_spawn():
Expand Down
Loading