sgl-project / sglang

SGLang is a structured generation language designed for large language models (LLMs). It makes your interaction with models faster and more controllable.
Apache License 2.0
2.75k stars 177 forks source link

Chinese Regex BUG in req.jump_forward_map.jump_forward_byte #549

Closed wellhowtosay closed 2 weeks ago

wellhowtosay commented 2 weeks ago

reproduce code:

@sgl.function
def fabric_gen(s):
    s+=sgl.user("用JSON数组列出一种衣服领形")
    r= '\\["(娃娃领|高领|海军领|斜领|连帽|翻领|一字领)"\\]'
    s += sgl.assistant(sgl.gen("json_output", max_tokens=256, regex=r))

if __name__ == "__main__":
    set_runtime() 
    print(fabric_gen.run().text())

Here is full error information

Traceback (most recent call last):
  File "/root/luka/sglang/python/sglang/srt/managers/controller/tp_worker.py", line 199, in exposed_step
    self.forward_step()
  File "/root/anaconda3/envs/sglang/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/luka/sglang/python/sglang/srt/managers/controller/tp_worker.py", line 229, in forward_step
    self.forward_decode_batch(self.running_batch)
  File "/root/luka/sglang/python/sglang/srt/managers/controller/tp_worker.py", line 562, in forward_decode_batch
    jump_forward_reqs = batch.check_for_jump_forward(self.model_runner)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/luka/sglang/python/sglang/srt/managers/controller/infer_batch.py", line 468, in check_for_jump_forward
    jump_forward_bytes = req.jump_forward_map.jump_forward_byte(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/luka/sglang/python/sglang/srt/constrained/jump_forward.py", line 123, in jump_forward_byte
    assert e.byte is not None and e.byte_next_state is not None
AssertionError

Exception in ControllerSingle:
Traceback (most recent call last):
  File "/root/luka/sglang/python/sglang/srt/managers/controller/manager_single.py", line 96, in start_controller_process
    loop.run_until_complete(controller.loop_for_forward())
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "/root/luka/sglang/python/sglang/srt/managers/controller/manager_single.py", line 45, in loop_for_forward
    out_pyobjs = await self.model_client.step(next_step_input)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/luka/sglang/python/sglang/srt/managers/controller/tp_worker.py", line 765, in _func
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/root/luka/sglang/python/sglang/srt/managers/controller/tp_worker.py", line 199, in exposed_step
    self.forward_step()
  File "/root/anaconda3/envs/sglang/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/luka/sglang/python/sglang/srt/managers/controller/tp_worker.py", line 229, in forward_step
    self.forward_decode_batch(self.running_batch)
  File "/root/luka/sglang/python/sglang/srt/managers/controller/tp_worker.py", line 562, in forward_decode_batch
    jump_forward_reqs = batch.check_for_jump_forward(self.model_runner)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/luka/sglang/python/sglang/srt/managers/controller/infer_batch.py", line 468, in check_for_jump_forward
    jump_forward_bytes = req.jump_forward_map.jump_forward_byte(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/luka/sglang/python/sglang/srt/constrained/jump_forward.py", line 123, in jump_forward_byte
    assert e.byte is not None and e.byte_next_state is not None
AssertionError

/root/luka/sglang/python/sglang/lang/interpreter.py:328: UserWarning: Error in stream_executor: Traceback (most recent call last):
  File "/root/luka/sglang/python/sglang/lang/interpreter.py", line 326, in _thread_worker_func
    self._execute(expr)
  File "/root/luka/sglang/python/sglang/lang/interpreter.py", line 369, in _execute
    self._execute(x)
  File "/root/luka/sglang/python/sglang/lang/interpreter.py", line 364, in _execute
    self._execute_gen(other)
  File "/root/luka/sglang/python/sglang/lang/interpreter.py", line 494, in _execute_gen
    comp, meta_info = self.backend.generate(
                      ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/luka/sglang/python/sglang/backend/runtime_endpoint.py", line 130, in generate
    res = http_request(
          ^^^^^^^^^^^^^
  File "/root/luka/sglang/python/sglang/utils.py", line 101, in http_request
    resp = urllib.request.urlopen(req, data=data, cafile=verify)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/anaconda3/envs/sglang/lib/python3.11/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/anaconda3/envs/sglang/lib/python3.11/urllib/request.py", line 519, in open
    response = self._open(req, data)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/root/anaconda3/envs/sglang/lib/python3.11/urllib/request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/anaconda3/envs/sglang/lib/python3.11/urllib/request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "/root/anaconda3/envs/sglang/lib/python3.11/urllib/request.py", line 1377, in http_open
    return self.do_open(http.client.HTTPConnection, req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/anaconda3/envs/sglang/lib/python3.11/urllib/request.py", line 1352, in do_open
    r = h.getresponse()
        ^^^^^^^^^^^^^^^
  File "/root/anaconda3/envs/sglang/lib/python3.11/http/client.py", line 1374, in getresponse
    response.begin()
  File "/root/anaconda3/envs/sglang/lib/python3.11/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
                              ^^^^^^^^^^^^^^^^^^^
  File "/root/anaconda3/envs/sglang/lib/python3.11/http/client.py", line 287, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

build sglang from main branch with lastest commit 40e53d65cbb8b609a6ff8e977d2318044d0f0ee0 outlines 0.0.44

hnyls2002 commented 2 weeks ago

@wellhowtosay It has now been fixed.

[INST] 用JSON数组列出一种衣服领形 [/INST]["高领"] </s><s>

Thanks for reporting this!