Checklist
Describe the bug
I tried to use OpenAI models with the frontend language, and installed sglang by using pip install "sglang[openai]".
This correctly installed sglang-v0.4.4.post3 and its dependencies on my machine. However, when I tried to run the openai_example_chat.py example, I got the following error:
File "/usr/local/opt/miniconda/envs/sglang/lib/python3.12/site-packages/sglang/__init__.py", line 4, in <module>
from sglang.api import (
File "/usr/local/opt/miniconda/envs/sglang/lib/python3.12/site-packages/sglang/api.py", line 7, in <module>
from sglang.lang.backend.base_backend import BaseBackend
File "/usr/local/opt/miniconda/envs/sglang/lib/python3.12/site-packages/sglang/lang/backend/base_backend.py", line 5, in <module>
from sglang.lang.interpreter import StreamExecutor
File "/usr/local/opt/miniconda/envs/sglang/lib/python3.12/site-packages/sglang/lang/interpreter.py", line 34, in <module>
from sglang.utils import (
File "/usr/local/opt/miniconda/envs/sglang/lib/python3.12/site-packages/sglang/utils.py", line 28, in <module>
from sglang.srt.utils import kill_process_tree
File "/usr/local/opt/miniconda/envs/sglang/lib/python3.12/site-packages/sglang/srt/utils.py", line 48, in <module>
import torch
ModuleNotFoundError: No module named 'torch'
I found that this was due to the import statement in sglang/utils.py:
from sglang.srt.utils import kill_process_tree
It wrongly introduced a dependency on sglang.srt.utils and further introduced a dependency on torch.
I checked the usage of kill_process_tree in sglang/utils.py and found that it was only used once in the terminate_process function. Then I further checked the change history of sglang/utils.py and found that this commit moved the above import statement from inside the terminate_process function to the beginning of the file.
This change was committed between v0.4.3.post2 and v0.4.3.post3. v0.4.3.post2 can run openai_example_chat.py correctly, while v0.4.3.post3 reported the same error.
Putting the above import statement back inside the terminate_process function can solve this problem.
Reproduction
Just start from a new virtual environment and run pip install "sglang[openai]".
python3 openai_example_chat.py will raise ModuleNotFoundError: No module named 'torch'.
Environment
This script is not really runnable because it imports torch without checking for its existence. For the same reason as #3874.
Checklist
Describe the bug
I tried to use OpenAI models with the frontend language, and installed sglang by using
pip install "sglang[openai]".This correctly installed
sglang-v0.4.4.post3and its dependencies on my machine. However, when I tried to run theopenai_example_chat.pyexample, I got the following error:I found that this was due to the
importstatement insglang/utils.py:It wrongly introduced a dependency on
sglang.srt.utilsand further introduced a dependency ontorch.I checked the usage of
kill_process_treeinsglang/utils.pyand found that it was only used once in theterminate_processfunction. Then I further checked the change history ofsglang/utils.pyand found that this commit moved the aboveimportstatement from inside theterminate_processfunction to the beginning of the file.This change was committed between
v0.4.3.post2andv0.4.3.post3.v0.4.3.post2can runopenai_example_chat.pycorrectly, whilev0.4.3.post3reported the same error.Putting the above
importstatement back inside theterminate_processfunction can solve this problem.Reproduction
Just start from a new virtual environment and run
pip install "sglang[openai]".python3 openai_example_chat.pywill raiseModuleNotFoundError: No module named 'torch'.Environment
This script is not really runnable because it imports torch without checking for its existence. For the same reason as #3874.