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.
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
, andAttention
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
, andAttention
, 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.
Before introducing the vLLM Hardware Plugin, let's first look at two prerequisite RFCs:
- [RFC] vLLM Plugin System: This RFC introduces a plugin-based approach to support various customization requirements, allowing users to define custom models, executors, schedulers, etc.
- [RFC] Make vLLM Device-Agnostic for Diverse Hardware Support and (vllm-project/vllm#6080): This RFC introduces the platform submodule, which centralizes hardware-related implementations to reduce conditional logic in the main codebase and lays the foundation for modularization.
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.
This section will dive into integrating a New Backend via the Hardware Plugin in both developer and user perspective.
To integrate a new backend into vLLM using the Hardware Plugin, follow these steps:
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.
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.
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 ofPlatform
class defined in step 1.
Refer to setup.py
in vLLM Ascend for a practical example.
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
Moving forward, we will continue collaborating with developers in the vLLM community to enhance the following aspects:
- Continuous enhancements to the V1 Engine.
- Expanding plugin support for more modules and features, such as scheduler and custom operators.
- 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. 🚀