Skip to content

Latest commit

 

History

History
115 lines (74 loc) · 6.84 KB

2025-03-12-hardware-plugin.md

File metadata and controls

115 lines (74 loc) · 6.84 KB
layout title author image
post
Introducing vLLM Hardware Plugin and Best Practice with Ascend NPU
vLLM Ascend Team
/assets/logos/vllm-logo-only-light.png

Since December 2024, through the joint efforts of the vLLM community and the vLLM Ascend team, we have completed the Hardware Pluggable RFC. This proposal allows hardware integration into vLLM in a decoupled manner, enabling rapid and modular support for different hardware platforms. The RFC has now taken initial shape. This proposal enables hardware integration into vLLM in a decoupled way, allowing for quick and modular support of various hardware platforms.


Why vLLM Hardware Plugin?

Currently, vLLM already supports multiple backends. However, as the number of vLLM backends continues to grow, several challenges have emerged:

  • Increased Code Complexity: Each hardware backend has its own Executor, Worker, Runner, and Attention components. This has increased the complexity of the vLLM codebase, with non-generic backend-specific code scattered throughout the project.
  • High Maintenance Costs: The cost of maintaining backends is high, not only for the backend developers but also for the vLLM community. The scarcity of community contributor resources makes efficiently adding new features difficult when backend maintainers are not present.
  • Lack of Extensibility: While vLLM follows a well-structured layered design by implementing backends through Executor, Worker, Runner, and Attention, supporting new hardware often requires invasive modifications or patching rather than dynamic registration. This makes adding new backends cumbersome.

Recognizing the need for a flexible and modular approach to integrating hardware backends, we identified hardware pluginization as a feasible solution:

  • Decoupled Codebase: The hardware backend plugin code remains independent, making the vLLM core code cleaner.
  • Reduced Maintenance Burden: vLLM developers can focus on generic features without being overwhelmed by the differences caused by backend-specific implementations.
  • Faster Integration & More Independent: New backends can be integrated quickly with less work to do and evolve independently.

What is the vLLM Hardware Plugin?

Before introducing the vLLM Hardware Plugin, let's first look at two prerequisite RFCs:

Based on these RFCs, we proposed [RFC] Hardware Pluggable, which integrates the Platform module into vLLM as a plugin. Additionally, we refactored Executor, Worker, ModelRunner, AttentionBackend, and Communicator to support hardware plugins more flexibly.

Currently, vLLM community has successfully implemented the Platform module introduced in the RFC. The functionality is validated through the vllm-project/vllm-ascend and vllm-project/vllm-spyre projects. Using this plugin mechanism, we successfully integrated vLLM with the Ascend NPU and IBM Spyre backends.


How to Integrate a New Backend via vLLM Hardware Plugin Mechanism

This section will dive into integrating a New Backend via the Hardware Plugin in both developer and user perspective.

Developer Perspective

To integrate a new backend into vLLM using the Hardware Plugin, follow these steps:

Step 1: Create a New Project and Initialize the Platform

Start by creating a Python project for the new backend and adding a platform.py file. Then, import the Platform class from vllm.platforms and implement the required attributes and methods.

You can refer to the platform.py in vLLM Ascend project for an example.

Step 2: Implement Custom Worker, Model Runner, Attention Backend, and Communicator Modules

Depending on the new backend's requirements, implement the following modules:

from vllm.worker.worker_base import WorkerBase
from vllm.worker.model_runner_base import ModelRunnerBase
from vllm.attention.backends.abstract import AttentionBackend
from vllm.distributed.device_communicators.base_communicator import CommunicatorBase

Each of these classes has a corresponding base class in vLLM. Again, you can refer to vLLM Ascend's implementation for an example.

Step 3: Register the Plugin

Register the plugin in setup.py using entrypoint mechanism of python:

setup(
    entry_points={'vllm.platform_plugins': ["{your_platform_name} = {code_path}:{register_function}"]}
)
  • {your_platform_name}: The name of the new backend (can be arbitrary).
  • {code_path}: The path to the main Python module.
  • {register_function}: The register function, which returns the path of Platform class defined in step 1.

Refer to setup.py in vLLM Ascend for a practical example.


User Perspective

Only need to install vllm and your plugin before running, taking vllm-ascend as an example:

pip install vllm vllm-ascend

On startup, you will observe the following logs, which means the backend plugin is working properly:

INFO 02-06 15:49:01 __init__.py:30] Available plugins for group vllm.platform_plugins:
INFO 02-06 15:49:01 __init__.py:32] name=ascend, value=vllm_ascend:register
… …
INFO 02-06 15:49:01 __init__.py:44] plugin ascend loaded.
INFO 02-06 15:49:01 __init__.py:181] Platform plugin ascend is activated

What's Next?

Moving forward, we will continue collaborating with developers in the vLLM community to enhance the following aspects:

  1. Continuous enhancements to the V1 Engine.
  2. Expanding plugin support for more modules and features, such as scheduler and custom operators.
  3. Better user experience and higher performance.

We encourage everyone to try out this new feature! If you have any questions, join the vLLM Slack and participate in the #sig-extensible-hardware channel for discussions. 🚀