lm-sys / lm-sys/FastChat

serve.openai_api_server.generate_completion_stream fails on long (~4000+ token) responses

Open
#2,148 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
39.5k
Forks
4.8k
PR merge metrics
No merged PRs in 30d

Description

[This code](https://github.com/lm-sys/FastChat/blob/main/fastchat/serve/openai_api_server.py#L579) assumes that each chunk received from the worker will consist of one or more complete dicts.

With default settings, this stops being the case for long responses, leading to a crash as `data = json.loads(chunk.decode())` tries to load a non-dict byte-string.

See [this](https://chat.openai.com/share/ac3c6ec7-0f6f-4fef-938d-04fd755e788f) explanation. Not the part about increasing BUFFER_SIZE, that's just kicking the can down the road, but rather the part about accumulating data into a buffer until a `delimiter` is reached.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in fastchat/serve/openai_api_server.py at generate_completion_stream around line 579, and reproduce the failure with a response longer than about 4,000 tokens. Trace how worker chunks are decoded and split, then verify that data is accumulated until the delimiter so split dictionaries no longer crash JSON parsing.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.