Skip to content

[Bug] Internal Server Error with Chat Template and n > 1 #910

Closed

Description

@jordan-benjamin

Checklist

  • 1. I have searched related issues but cannot get the expected help.
  • 2. The bug has not been fixed in the latest version.
  • 3. Please note that if the bug-related issue you submitted lacks corresponding environment info and a minimal reproducible demo, it will be challenging for us to reproduce and resolve the issue, reducing the likelihood of receiving feedback.

Describe the bug

Hi there! I've found that the sglang server crashes when I use the OpenAI client and pass a list of messages with n > 1.

The server returns a 500 and the console shows the error message:

  File ".../envs/sg/lib/python3.11/site-packages/sglang/srt/server.py", line 158, in openai_v1_chat_completions
    return await v1_chat_completions(tokenizer_manager, raw_request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../envs/sg/lib/python3.11/site-packages/sglang/srt/openai_api/adapter.py", line 828, in v1_chat_completions
    ret = await tokenizer_manager.generate_request(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../envs/sg/lib/python3.11/site-packages/sglang/srt/managers/tokenizer_manager.py", line 150, in generate_request
    async for response in self._handle_batch_request(obj, request):
  File ".../envs/sg/lib/python3.11/site-packages/sglang/srt/managers/tokenizer_manager.py", line 238, in _handle_batch_request
    async for input_id in self._handle_single_request(
  File ".../envs/sg/lib/python3.11/site-packages/sglang/srt/managers/tokenizer_manager.py", line 192, in _handle_single_request
    input_ids = self.tokenizer.encode(input_text)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../envs/sg/lib/python3.11/site-packages/transformers/tokenization_utils_base.py", line 2843, in encode
    encoded_inputs = self.encode_plus(
                     ^^^^^^^^^^^^^^^^^
  File ".../envs/sg/lib/python3.11/site-packages/transformers/tokenization_utils_base.py", line 3255, in encode_plus
    return self._encode_plus(
           ^^^^^^^^^^^^^^^^^^
  File ".../envs/sg/lib/python3.11/site-packages/transformers/tokenization_utils_fast.py", line 601, in _encode_plus
    batched_output = self._batch_encode_plus(
                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../envs/sg/lib/python3.11/site-packages/transformers/tokenization_utils_fast.py", line 528, in _batch_encode_plus
    encodings = self._tokenizer.encode_batch(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: TextEncodeInput must be Union[TextInputSequence, Tuple[InputSequence, InputSequence]]

Thanks for the help!

Reproduction

Start a server with:

python -m sglang.launch_server --model-path meta-llama/Meta-Llama-3-8B-Instruct --mem-fraction-static 0.85

and use the client snippet:

from openai import OpenAI
client = OpenAI(
    api_key='fake-key',
    base_url="http://0.0.0.0:30000/v1"
)
response = client.chat.completions.create(
  model="default",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What's up?"},
  ],
  temperature=1.0,
  n=2,
  max_tokens=100,
)

This request works with n = 1. Also, if I downgrade to sglang==0.2.8, I can make successful requests with n=1 and n=2.

Environment

Python: 3.11.9 (main, Apr 19 2024, 16:48:06) [GCC 11.2.0]
CUDA available: True
GPU 0,1,2,3,4,5,6,7: NVIDIA H100 80GB HBM3
CUDA_HOME: /usr
NVCC: Cuda compilation tools, release 12.2, V12.2.140
CUDA Driver Version: 535.129.03
535.129.03
535.129.03
535.129.03
535.129.03
535.129.03
535.129.03
535.129.03
PyTorch: 2.3.1+cu121
sglang: 0.2.9.post1
flashinfer: 0.1.3+cu121torch2.3
requests: 2.32.3
tqdm: 4.66.5
numpy: 1.26.4
aiohttp: 3.10.0
fastapi: 0.112.0
hf_transfer: 0.1.8
huggingface_hub: 0.24.5
interegular: 0.3.3
packaging: 24.1
PIL: 10.4.0
psutil: 6.0.0
pydantic: 2.8.2
uvicorn: 0.30.5
uvloop: 0.19.0
zmq: 26.0.3
vllm: 0.5.3.post1
multipart: 0.0.9
openai: 1.38.0
anthropic: 0.32.0
NVIDIA Topology: 
	GPU0	GPU1	GPU2	GPU3	GPU4	GPU5	GPU6	GPU7	NIC0	CPU Affinity	NUMA Affinity	GPU NUMA ID
GPU0	 X 	NV18	NV18	NV18	NV18	NV18	NV18	NV18	SYS	0-103	0		N/A
GPU1	NV18	 X 	NV18	NV18	NV18	NV18	NV18	NV18	SYS	0-103	0		N/A
GPU2	NV18	NV18	 X 	NV18	NV18	NV18	NV18	NV18	SYS	0-103	0		N/A
GPU3	NV18	NV18	NV18	 X 	NV18	NV18	NV18	NV18	SYS	0-103	0		N/A
GPU4	NV18	NV18	NV18	NV18	 X 	NV18	NV18	NV18	SYS	104-207	1		N/A
GPU5	NV18	NV18	NV18	NV18	NV18	 X 	NV18	NV18	SYS	104-207	1		N/A
GPU6	NV18	NV18	NV18	NV18	NV18	NV18	 X 	NV18	SYS	104-207	1		N/A
GPU7	NV18	NV18	NV18	NV18	NV18	NV18	NV18	 X 	SYS	104-207	1		N/A
NIC0	SYS	SYS	SYS	SYS	SYS	SYS	SYS	SYS	 X 				

Legend:

  X    = Self
  SYS  = Connection traversing PCIe as well as the SMP interconnect between NUMA nodes (e.g., QPI/UPI)
  NODE = Connection traversing PCIe as well as the interconnect between PCIe Host Bridges within a NUMA node
  PHB  = Connection traversing PCIe as well as a PCIe Host Bridge (typically the CPU)
  PXB  = Connection traversing multiple PCIe bridges (without traversing the PCIe Host Bridge)
  PIX  = Connection traversing at most a single PCIe bridge
  NV#  = Connection traversing a bonded set of # NVLinks

NIC Legend:

  NIC0: mlx5_0


ulimit soft: 1024

Activity

  1. self-assigned this
    on Aug 4, 2024
  2. Ying1123 commented on Aug 4, 2024

    @Ying1123
    Contributor

    This should be fixed by #916

  3. Ying1123 commented on Aug 5, 2024

    @Ying1123
    Contributor

    Try main or v0.2.10

  4. merrymercy commented on Aug 5, 2024

    @merrymercy
    Collaborator

    @jordan-benjamin
    I just noticed that you worked on https://github.com/ScalingIntelligence/hydragen. It is a great project. I am interested in knowing how the current SGLang compares with Hydragen on your workloads. Do you have any sharable performance results? It would be great to see how they perform on different workloads and learn from each other.

    SGLang also integrates torch.compile from gpt-fast. You can enable it with --enable-torch-compile. On batch size 1, it is even faster than gpt-fast because of better attention kernels.

  5. added a commit that references this issue on Aug 26, 2026
  6. added a commit that references this issue on Sep 12, 2026
  7. added a commit that references this issue on Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions