| name | vllm-hardware |
| description | Multi-hardware backend configuration (CUDA, ROCm, NPU, XPU, CPU) |
| triggers | ["When user wants to run vLLM on specific hardware","When user needs to configure AMD ROCm","When user wants Intel XPU/NPU support","When user needs CPU-only inference"] |
vllm-hardware
Overview
vLLM supports multiple hardware backends beyond NVIDIA CUDA, including AMD ROCm, Intel XPU/NPU, and CPU. This skill covers configuration for each backend.
Prerequisites
- Hardware-specific drivers installed
- vLLM built or installed for target hardware
- Sufficient system resources
Main Workflow
Step 1: NVIDIA CUDA (Default)
pip install vllm
pip install vllm --extra-index-url https://download.pytorch.org/whl/cu118
from vllm import LLM
llm = LLM(model="meta-llama/Llama-2-7b-chat-hf")
Step 2: AMD ROCm
Installation:
sudo apt install rocm-dev rocm-libs
pip install vllm --extra-index-url https://download.pytorch.org/whl/rocm6.1
Configuration:
rocm-smi
export HIP_VISIBLE_DEVICES=0,1
vllm serve meta-llama/Llama-2-7b-chat-hf
Step 3: Intel XPU
Installation:
pip install intel-extension-for-pytorch
export VLLM_TARGET_DEVICE=xpu
pip install vllm
Configuration:
from vllm import LLM
llm = LLM(
model="meta-llama/Llama-2-7b-chat-hf",
device="xpu"
)
Step 4: Intel CPU
Installation:
export VLLM_TARGET_DEVICE=cpu
pip install vllm --extra-index-url https://download.pytorch.org/whl/cpu
Optimization:
export OMP_NUM_THREADS=8
pip install openvino
export VLLM_OPENVINO_ENABLE=1
from vllm import LLM
llm = LLM(
model="meta-llama/Llama-2-7b-chat-hf",
device="cpu"
)
Step 5: Ascend NPU
Installation:
export VLLM_TARGET_DEVICE=npu
pip install vllm
Configuration:
export ASCEND_RT_VISIBLE_DEVICES=0
vllm serve meta-llama/Llama-2-7b-chat-hf
Common Patterns
Pattern 1: Multi-GPU Selection
export CUDA_VISIBLE_DEVICES=0,2,3
export HIP_VISIBLE_DEVICES=0,1
vllm serve model --tensor-parallel-size 3
Pattern 2: Mixed Precision by Hardware
from vllm import LLM
llm = LLM(model="model", dtype="bfloat16")
llm = LLM(model="model", dtype="float16")
llm = LLM(model="model", dtype="float32")
Pattern 3: Hardware Capability Detection
import torch
def get_optimal_config():
if torch.cuda.is_available():
capability = torch.cuda.get_device_capability()
if capability[0] >= 8:
return {"dtype": "bfloat16", "kv_cache_dtype": "fp8"}
else:
return {"dtype": "float16"}
elif torch.xpu.is_available():
return {"dtype": "bfloat16", "device": "xpu"}
else:
return {"dtype": "float32", "device": "cpu"}
config = get_optimal_config()
llm = LLM(model="model", **config)
Troubleshooting
Problem: ROCm device not found
Solution:
rocm-smi
python -c "import torch; print(torch.cuda.is_available())"
pip uninstall torch vllm -y
pip install torch --index-url https://download.pytorch.org/whl/rocm6.1
pip install vllm
Problem: XPU initialization error
Solution:
sycl-ls
export SYCL_CACHE_PERSISTENT=1
export VLLM_TARGET_DEVICE=xpu
python -c "import intel_extension_for_pytorch as ipex; print(ipex.__version__)"
Problem: CPU inference too slow
Solution:
llm = LLM(
model="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
device="cpu",
quantization="gptq"
)
Problem: NPU out of memory
Solution:
llm = LLM(
model="model",
device="npu",
max_model_len=2048,
gpu_memory_utilization=0.8
)
References