diff --git a/vllm/platforms/rocm.py b/vllm/platforms/rocm.py index 6e62a194761c..7f695347d18f 100644 --- a/vllm/platforms/rocm.py +++ b/vllm/platforms/rocm.py @@ -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.""" diff --git a/vllm/utils/system_utils.py b/vllm/utils/system_utils.py index 7f56f972a4fa..d39834f30b15 100644 --- a/vllm/utils/system_utils.py +++ b/vllm/utils/system_utils.py @@ -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():