Convert formatting to use ruff instead of yapf + isort (#26247)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
@@ -8,7 +8,7 @@ import vllm.envs as envs
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_PLUGINS_GROUP = 'vllm.general_plugins'
|
||||
DEFAULT_PLUGINS_GROUP = "vllm.general_plugins"
|
||||
|
||||
# make sure one process only loads plugins once
|
||||
plugins_loaded = False
|
||||
@@ -16,6 +16,7 @@ plugins_loaded = False
|
||||
|
||||
def load_plugins_by_group(group: str) -> dict[str, Callable[[], Any]]:
|
||||
import sys
|
||||
|
||||
if sys.version_info < (3, 10):
|
||||
from importlib_metadata import entry_points
|
||||
else:
|
||||
@@ -29,7 +30,7 @@ def load_plugins_by_group(group: str) -> dict[str, Callable[[], Any]]:
|
||||
return {}
|
||||
|
||||
# Check if the only discovered plugin is the default one
|
||||
is_default_group = (group == DEFAULT_PLUGINS_GROUP)
|
||||
is_default_group = group == DEFAULT_PLUGINS_GROUP
|
||||
# Use INFO for non-default groups and DEBUG for the default group
|
||||
log_level = logger.debug if is_default_group else logger.info
|
||||
|
||||
@@ -38,8 +39,10 @@ def load_plugins_by_group(group: str) -> dict[str, Callable[[], Any]]:
|
||||
log_level("- %s -> %s", plugin.name, plugin.value)
|
||||
|
||||
if allowed_plugins is None:
|
||||
log_level("All plugins in this group will be loaded. "
|
||||
"Set `VLLM_PLUGINS` to control which plugins to load.")
|
||||
log_level(
|
||||
"All plugins in this group will be loaded. "
|
||||
"Set `VLLM_PLUGINS` to control which plugins to load."
|
||||
)
|
||||
|
||||
plugins = dict[str, Callable[[], Any]]()
|
||||
for plugin in discovered_plugins:
|
||||
|
||||
@@ -15,8 +15,8 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_io_processor(
|
||||
vllm_config: VllmConfig,
|
||||
plugin_from_init: Optional[str] = None) -> IOProcessor | None:
|
||||
vllm_config: VllmConfig, plugin_from_init: Optional[str] = None
|
||||
) -> IOProcessor | None:
|
||||
# Input.Output processors are loaded as plugins under the
|
||||
# 'vllm.io_processor_plugins' group. Similar to platform
|
||||
# plugins, these plugins register a function that returns the class
|
||||
@@ -39,8 +39,9 @@ def get_io_processor(
|
||||
logger.debug("IOProcessor plugin to be loaded %s", model_plugin)
|
||||
|
||||
# Load all installed plugin in the group
|
||||
multimodal_data_processor_plugins = \
|
||||
load_plugins_by_group('vllm.io_processor_plugins')
|
||||
multimodal_data_processor_plugins = load_plugins_by_group(
|
||||
"vllm.io_processor_plugins"
|
||||
)
|
||||
|
||||
loadable_plugins = {}
|
||||
for name, func in multimodal_data_processor_plugins.items():
|
||||
@@ -54,14 +55,16 @@ def get_io_processor(
|
||||
|
||||
num_available_plugins = len(loadable_plugins.keys())
|
||||
if num_available_plugins == 0:
|
||||
raise ValueError("No IOProcessor plugins installed"
|
||||
f" but one is required ({model_plugin}).")
|
||||
raise ValueError(
|
||||
f"No IOProcessor plugins installed but one is required ({model_plugin})."
|
||||
)
|
||||
|
||||
if model_plugin not in loadable_plugins:
|
||||
raise ValueError(
|
||||
f"The model requires the '{model_plugin}' IO Processor plugin "
|
||||
"but it is not installed. "
|
||||
f"Available plugins: {list(loadable_plugins.keys())}")
|
||||
f"Available plugins: {list(loadable_plugins.keys())}"
|
||||
)
|
||||
|
||||
activated_plugin_cls = loadable_plugins[model_plugin]
|
||||
|
||||
|
||||
@@ -10,12 +10,11 @@ from vllm.entrypoints.openai.protocol import IOProcessorResponse
|
||||
from vllm.inputs.data import PromptType
|
||||
from vllm.outputs import PoolingRequestOutput
|
||||
|
||||
IOProcessorInput = TypeVar('IOProcessorInput')
|
||||
IOProcessorOutput = TypeVar('IOProcessorOutput')
|
||||
IOProcessorInput = TypeVar("IOProcessorInput")
|
||||
IOProcessorOutput = TypeVar("IOProcessorOutput")
|
||||
|
||||
|
||||
class IOProcessor(ABC, Generic[IOProcessorInput, IOProcessorOutput]):
|
||||
|
||||
def __init__(self, vllm_config: VllmConfig):
|
||||
self.vllm_config = vllm_config
|
||||
|
||||
@@ -37,10 +36,12 @@ class IOProcessor(ABC, Generic[IOProcessorInput, IOProcessorOutput]):
|
||||
return self.pre_process(prompt, request_id, **kwargs)
|
||||
|
||||
@abstractmethod
|
||||
def post_process(self,
|
||||
model_output: Sequence[PoolingRequestOutput],
|
||||
request_id: Optional[str] = None,
|
||||
**kwargs) -> IOProcessorOutput:
|
||||
def post_process(
|
||||
self,
|
||||
model_output: Sequence[PoolingRequestOutput],
|
||||
request_id: Optional[str] = None,
|
||||
**kwargs,
|
||||
) -> IOProcessorOutput:
|
||||
raise NotImplementedError
|
||||
|
||||
async def post_process_async(
|
||||
@@ -52,8 +53,9 @@ class IOProcessor(ABC, Generic[IOProcessorInput, IOProcessorOutput]):
|
||||
# We cannot guarantee outputs are returned in the same order they were
|
||||
# fed to vLLM.
|
||||
# Let's sort them by id before post_processing
|
||||
sorted_output = sorted([(i, item) async for i, item in model_output],
|
||||
key=lambda output: output[0])
|
||||
sorted_output = sorted(
|
||||
[(i, item) async for i, item in model_output], key=lambda output: output[0]
|
||||
)
|
||||
collected_output = [output[1] for output in sorted_output]
|
||||
return self.post_process(collected_output, request_id, **kwargs)
|
||||
|
||||
@@ -63,5 +65,6 @@ class IOProcessor(ABC, Generic[IOProcessorInput, IOProcessorOutput]):
|
||||
|
||||
@abstractmethod
|
||||
def output_to_response(
|
||||
self, plugin_output: IOProcessorOutput) -> IOProcessorResponse:
|
||||
self, plugin_output: IOProcessorOutput
|
||||
) -> IOProcessorResponse:
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -10,25 +10,29 @@ from vllm.lora.resolver import LoRAResolver, LoRAResolverRegistry
|
||||
|
||||
|
||||
class FilesystemResolver(LoRAResolver):
|
||||
|
||||
def __init__(self, lora_cache_dir: str):
|
||||
self.lora_cache_dir = lora_cache_dir
|
||||
|
||||
async def resolve_lora(self, base_model_name: str,
|
||||
lora_name: str) -> Optional[LoRARequest]:
|
||||
async def resolve_lora(
|
||||
self, base_model_name: str, lora_name: str
|
||||
) -> Optional[LoRARequest]:
|
||||
lora_path = os.path.join(self.lora_cache_dir, lora_name)
|
||||
if os.path.exists(lora_path):
|
||||
adapter_config_path = os.path.join(self.lora_cache_dir, lora_name,
|
||||
"adapter_config.json")
|
||||
adapter_config_path = os.path.join(
|
||||
self.lora_cache_dir, lora_name, "adapter_config.json"
|
||||
)
|
||||
if os.path.exists(adapter_config_path):
|
||||
with open(adapter_config_path) as file:
|
||||
adapter_config = json.load(file)
|
||||
if adapter_config["peft_type"] == "LORA" and adapter_config[
|
||||
"base_model_name_or_path"] == base_model_name:
|
||||
lora_request = LoRARequest(lora_name=lora_name,
|
||||
lora_int_id=abs(
|
||||
hash(lora_name)),
|
||||
lora_path=lora_path)
|
||||
if (
|
||||
adapter_config["peft_type"] == "LORA"
|
||||
and adapter_config["base_model_name_or_path"] == base_model_name
|
||||
):
|
||||
lora_request = LoRARequest(
|
||||
lora_name=lora_name,
|
||||
lora_int_id=abs(hash(lora_name)),
|
||||
lora_path=lora_path,
|
||||
)
|
||||
return lora_request
|
||||
return None
|
||||
|
||||
@@ -38,13 +42,12 @@ def register_filesystem_resolver():
|
||||
|
||||
lora_cache_dir = envs.VLLM_LORA_RESOLVER_CACHE_DIR
|
||||
if lora_cache_dir:
|
||||
if not os.path.exists(lora_cache_dir) or not os.path.isdir(
|
||||
lora_cache_dir):
|
||||
if not os.path.exists(lora_cache_dir) or not os.path.isdir(lora_cache_dir):
|
||||
raise ValueError(
|
||||
"VLLM_LORA_RESOLVER_CACHE_DIR must be set to a valid directory \
|
||||
for Filesystem Resolver plugin to function")
|
||||
for Filesystem Resolver plugin to function"
|
||||
)
|
||||
fs_resolver = FilesystemResolver(lora_cache_dir)
|
||||
LoRAResolverRegistry.register_resolver("Filesystem Resolver",
|
||||
fs_resolver)
|
||||
LoRAResolverRegistry.register_resolver("Filesystem Resolver", fs_resolver)
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user