2025-02-02 14:58:18 -05:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2025-06-03 11:20:17 -07:00
|
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
2025-02-02 14:58:18 -05:00
|
|
|
|
2025-03-17 11:35:57 +08:00
|
|
|
import pytest
|
2025-01-15 18:14:15 +08:00
|
|
|
import torch
|
|
|
|
|
|
2025-06-20 09:44:56 -05:00
|
|
|
from vllm.plugins import load_general_plugins
|
2025-01-15 18:14:15 +08:00
|
|
|
|
|
|
|
|
|
2024-12-30 20:24:45 +08:00
|
|
|
def test_platform_plugins():
|
|
|
|
|
# simulate workload by running an example
|
|
|
|
|
import runpy
|
2025-10-05 15:06:22 +01:00
|
|
|
|
2024-12-30 20:24:45 +08:00
|
|
|
current_file = __file__
|
|
|
|
|
import os
|
2025-10-05 15:06:22 +01:00
|
|
|
|
2024-12-30 20:24:45 +08:00
|
|
|
example_file = os.path.join(
|
|
|
|
|
os.path.dirname(os.path.dirname(os.path.dirname(current_file))),
|
2025-02-20 12:53:51 +00:00
|
|
|
"examples",
|
|
|
|
|
"offline_inference/basic/basic.py",
|
|
|
|
|
)
|
2024-12-30 20:24:45 +08:00
|
|
|
runpy.run_path(example_file)
|
|
|
|
|
|
|
|
|
|
# check if the plugin is loaded correctly
|
|
|
|
|
from vllm.platforms import _init_trace, current_platform
|
2025-10-05 15:06:22 +01:00
|
|
|
|
2024-12-30 20:24:45 +08:00
|
|
|
assert current_platform.device_name == "DummyDevice", (
|
|
|
|
|
f"Expected DummyDevice, got {current_platform.device_name}, "
|
|
|
|
|
"possibly because current_platform is imported before the plugin"
|
|
|
|
|
f" is loaded. The first import:\n{_init_trace}"
|
|
|
|
|
)
|
2025-01-15 18:14:15 +08:00
|
|
|
|
|
|
|
|
|
2026-01-08 18:20:49 -05:00
|
|
|
def test_oot_custom_op(default_vllm_config, monkeypatch: pytest.MonkeyPatch):
|
2025-06-20 09:44:56 -05:00
|
|
|
# simulate workload by running an example
|
|
|
|
|
load_general_plugins()
|
|
|
|
|
from vllm.model_executor.layers.rotary_embedding import RotaryEmbedding
|
2025-10-05 15:06:22 +01:00
|
|
|
|
2025-06-20 09:44:56 -05:00
|
|
|
layer = RotaryEmbedding(16, 16, 16, 16, True, torch.float16)
|
|
|
|
|
assert layer.__class__.__name__ == "DummyRotaryEmbedding", (
|
|
|
|
|
f"Expected DummyRotaryEmbedding, got {layer.__class__.__name__}, "
|
|
|
|
|
"possibly because the custom op is not registered correctly."
|
|
|
|
|
)
|
|
|
|
|
assert hasattr(layer, "addition_config"), (
|
|
|
|
|
"Expected DummyRotaryEmbedding to have an 'addition_config' attribute, "
|
|
|
|
|
"which is set by the custom op."
|
|
|
|
|
)
|