Skip to content

[bugfix]Add modelscope package to avoid docker image without modelscope#1520

Merged
merrymercy merged 3 commits into
sgl-project:mainfrom
KylinMountain:KylinMountain-patch-1-1
Sep 28, 2024
Merged

[bugfix]Add modelscope package to avoid docker image without modelscope#1520
merrymercy merged 3 commits into
sgl-project:mainfrom
KylinMountain:KylinMountain-patch-1-1

Conversation

@KylinMountain

@KylinMountain KylinMountain commented Sep 26, 2024

Copy link
Copy Markdown
Contributor

Motivation

When deploy sglang with docker or docker-compose and config env SGLANG_USE_MODELSCOPE=true, it will report No module modelscope found.

Here is the related compose file, you can reproduce it.

services:
  sglang:
    image: lmsysorg/sglang:latest
    container_name: sglang
    volumes:
      - ~/.cache/modelscope:/root/.cache/modelscope
      - ~/.cache/huggingface:/root/.cache/huggingface
    restart: always
    network_mode: host
    # Or you can only publish port 30000
    # ports:
    #   - 30000:30000
    environment:
      - 'SGLANG_USE_MODELSCOPE=true'
    entrypoint: python3 -m sglang.launch_server
    command:
      --model-path qwen/Qwen2.5-72B-Instruct-GPTQ-Int8
      --tp 4
      --mem-fraction-static 0.7
      --chunked-prefill-size 2048
      --host 0.0.0.0
      --port 30000
    ulimits:
      memlock: -1
      stack: 67108864
    ipc: host
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:30000/health || exit 1"]
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              capabilities: [gpu]

Modifications

Add modelscope to the default sgl pyproject.tom config.

Checklist

  • Format your code according to the Contributor Guide.
  • Add unit tests as outlined in the Contributor Guide.
  • Update documentation as needed, including docstrings or example tutorials.

@KylinMountain

Copy link
Copy Markdown
Contributor Author

I have tested this PR with my build docker image: kylinmountain/sglang:latest. It can use model-scope without reporting the modelscope package not found.

But the sglang in docker will report the following error:

RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/sgl-workspace/sglang/python/sglang/launch_server.py", line 16, in <module>
    raise e
  File "/sgl-workspace/sglang/python/sglang/launch_server.py", line 14, in <module>
    launch_server(server_args)
  File "/sgl-workspace/sglang/python/sglang/srt/server.py", line 373, in launch_server
    raise RuntimeError(
RuntimeError: Initialization failed. controller_init_state: Traceback (most recent call last):
  File "/sgl-workspace/sglang/python/sglang/srt/managers/controller_single.py", line 145, in start_controller_process
    controller = ControllerSingle(
  File "/sgl-workspace/sglang/python/sglang/srt/managers/controller_single.py", line 81, in __init__
    self.tp_server = ModelTpServer(
  File "/sgl-workspace/sglang/python/sglang/srt/managers/tp_worker.py", line 100, in __init__
    self.model_runner = ModelRunner(
  File "/sgl-workspace/sglang/python/sglang/srt/model_executor/model_runner.py", line 116, in __init__
    min_per_gpu_memory = self.init_torch_distributed()
  File "/sgl-workspace/sglang/python/sglang/srt/model_executor/model_runner.py", line 132, in init_torch_distributed
    torch.cuda.set_device(self.gpu_id)
  File "/usr/local/lib/python3.10/dist-packages/torch/cuda/__init__.py", line 420, in set_device
    torch._C._cuda_setDevice(device)
  File "/usr/local/lib/python3.10/dist-packages/torch/cuda/__init__.py", line 300, in _lazy_init
    raise RuntimeError(
RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method
, detoken_init_state: init ok

@zhyncs do you know this issue?

@merrymercy

Copy link
Copy Markdown
Contributor

Is there any difference between your image build and our image build?
Which docker file do you use?

BTW, let me merge this PR first. We can discuss here and send follow-up PRs.

@merrymercy
merrymercy merged commit f42e9bf into sgl-project:main Sep 28, 2024
@KylinMountain

Copy link
Copy Markdown
Contributor Author

Actually, the only difference is that I update docker repository to my repo which let me build docker image to test in [PR]😅(https://github.com/KylinMountain/sglang/pull/2/files).
image

The weird thing is that I can start sglang in the host ubuntu 20.04 with Nvidia A100x4, but start it in docker reporting the CUDA re-initialize.

@merrymercy

Copy link
Copy Markdown
Contributor

Both problems should be fixed now on the main

  1. We used spawn instead of fork, so the fork issue should be resolved.
  2. [bugfix]Add modelscope package to avoid docker image without modelscope #1520 modelscope has been added into the docker image.

timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants