Files
vllm/tests/cuda/scripts/check_platform_no_cuda_init.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

21 lines
618 B
Python
Raw Normal View History

#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Check that vllm.platforms import does not initialize CUDA."""
import os
for key in ["CUDA_VISIBLE_DEVICES", "HIP_VISIBLE_DEVICES", "ROCR_VISIBLE_DEVICES"]:
os.environ.pop(key, None)
import torch # noqa: E402
assert not torch.cuda.is_initialized(), "CUDA initialized before import"
from vllm.platforms import current_platform # noqa: E402
assert not torch.cuda.is_initialized(), (
f"CUDA was initialized during vllm.platforms import on {current_platform}"
)
print("OK")