lmdeploy_server.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import os
  2. import sys
  3. from mineru.utils.models_download_utils import auto_download_and_get_model_root_path
  4. def main():
  5. args = sys.argv[1:]
  6. has_port_arg = False
  7. has_gpu_memory_utilization_arg = False
  8. has_log_level_arg = False
  9. has_device_arg = False
  10. # 检查现有参数
  11. for i, arg in enumerate(args):
  12. if arg == "--server-port" or arg.startswith("--server-port="):
  13. has_port_arg = True
  14. if arg == "--cache-max-entry-count" or arg.startswith("--cache-max-entry-count="):
  15. has_gpu_memory_utilization_arg = True
  16. if arg == "--log-level" or arg.startswith("--log-level="):
  17. has_log_level_arg = True
  18. if arg == "--device":
  19. if i + 1 < len(args):
  20. device_type = args[i + 1]
  21. elif arg.startswith("--device="):
  22. device_type = arg.split("=", 1)[1]
  23. # 添加默认参数
  24. if not has_port_arg:
  25. args.extend(["--server-port", "30000"])
  26. if not has_gpu_memory_utilization_arg:
  27. args.extend(["--cache-max-entry-count", "0.5"])
  28. if not has_log_level_arg:
  29. args.extend(["--log-level", "ERROR"])
  30. if has_device_arg:
  31. if device_type.lower() in ["ascend", "maca", "camb"]:
  32. args.extend(["--backend", "pytorch"])
  33. model_path = auto_download_and_get_model_root_path("/", "vlm")
  34. # 重构参数,将模型路径作为位置参数
  35. sys.argv = [sys.argv[0]] + ["serve", "api_server", model_path] + args
  36. if os.getenv('OMP_NUM_THREADS') is None:
  37. os.environ["OMP_NUM_THREADS"] = "1"
  38. # 启动vllm服务器
  39. print(f"start lmdeploy server: {sys.argv}")
  40. # 使用os.system调用启动lmdeploy服务器
  41. os.system("lmdeploy " + " ".join(sys.argv[1:]))
  42. if __name__ == "__main__":
  43. main()