sgl-project / sglang

SGLang is a fast serving framework for large language models and vision language models.
https://sgl-project.github.io/
Apache License 2.0
5.9k stars 477 forks source link

ImportError: cannot import name 'build_regex_from_object' from 'outlines.fsm.json_schema' #203

Closed nopepper closed 8 months ago

nopepper commented 8 months ago

Description

Running python -m sglang.launch_server yields this error. I was running it in a container, which I'll describe below.

outlines-server-1  | Traceback (most recent call last):
outlines-server-1  |   File "<frozen runpy>", line 198, in _run_module_as_main
outlines-server-1  |   File "<frozen runpy>", line 88, in _run_code
outlines-server-1  |   File "/usr/local/lib/python3.11/site-packages/sglang/launch_server.py", line 3, in <module>
outlines-server-1  |     from sglang.srt.server import ServerArgs, launch_server
outlines-server-1  |   File "/usr/local/lib/python3.11/site-packages/sglang/srt/server.py", line 25, in <module>
outlines-server-1  |     from sglang.srt.constrained import disable_cache
outlines-server-1  |   File "/usr/local/lib/python3.11/site-packages/sglang/srt/constrained/__init__.py", line 4, in <module>
outlines-server-1  |     from outlines.fsm.json_schema import build_regex_from_object
outlines-server-1  | ImportError: cannot import name 'build_regex_from_object' from 'outlines.fsm.json_schema' (/usr/local/lib/python3.11/site-packages/outlines/fsm/json_schema.py)
outlines-server-1 exited with code 1

Reproducing

Here's the dockerfile, super simple:

FROM python:3.11
RUN pip install sglang[all]
ENTRYPOINT [ "python", "-m", "sglang.launch_server" ]

Running:

docker build  --rm -t sglang-server .
docker run sglang-server --model-path mistralai/Mistral-7B-Instruct-v0.2

Notes

I also tried this with the python 3.10 image, same issue. It also didn't work outside of docker.

nopepper commented 8 months ago

Update: this seems to work again when installing from source, so the bug might be in the distribution.

nbbull commented 8 months ago

i meet the same problem

Xingxiangrui commented 8 months ago

+1 for this. I meet the same problem when I use llava-v1.6-mistral-7b

crissed53 commented 8 months ago

The error is caused by wrong outlines version (https://github.com/sgl-project/sglang/pull/196) in the latest release(0.1.12).

The workaround is to manually specify the version constraint of the outlines package by:

pip install "sglang[all]" "outlines<=0.0.30"

hnyls2002 commented 8 months ago

This is caused by the outlines API change, and we temporarily pin the outlines' version here https://github.com/sgl-project/sglang/pull/196.

Thanks @crissed53.

surak commented 8 months ago

Pinning the outlines breaks up everything around it.

MonadKai commented 8 months ago

Downgrade outlines to the project specified version, e.g.

# for sglang 0.1.12
pip install outlines==0.0.27