vllm.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from ....utils.deps import is_genai_engine_plugin_available, require_genai_engine_plugin
  15. from ..configs.utils import (
  16. backend_config_to_args,
  17. set_config_defaults,
  18. update_backend_config,
  19. )
  20. from ..models import ALL_MODEL_NAMES, get_model_components
  21. def register_models():
  22. from vllm import ModelRegistry
  23. if is_genai_engine_plugin_available("vllm-server"):
  24. for model_name in ALL_MODEL_NAMES:
  25. if model_name not in ModelRegistry.get_supported_archs():
  26. net_cls, _ = get_model_components(model_name, "vllm")
  27. ModelRegistry.register_model(net_cls.__name__, net_cls)
  28. def run_vllm_server(host, port, model_name, model_dir, config, chat_template_path):
  29. require_genai_engine_plugin("vllm-server")
  30. import uvloop
  31. from vllm.entrypoints.openai.api_server import (
  32. FlexibleArgumentParser,
  33. cli_env_setup,
  34. make_arg_parser,
  35. run_server,
  36. validate_parsed_serve_args,
  37. )
  38. cli_env_setup()
  39. parser = FlexibleArgumentParser()
  40. parser = make_arg_parser(parser)
  41. set_config_defaults(config, {"served-model-name": model_name})
  42. if chat_template_path:
  43. set_config_defaults(config, {"chat-template": str(chat_template_path)})
  44. update_backend_config(
  45. config,
  46. {
  47. "model": model_dir,
  48. "host": host,
  49. "port": port,
  50. },
  51. )
  52. args = backend_config_to_args(config)
  53. args = parser.parse_args(args)
  54. validate_parsed_serve_args(args)
  55. uvloop.run(run_server(args))