Skip to content

refactor: rename completion api token_ids to response_token_ids (supplement to #35225) - #38459

Open
CSWYF3634076 wants to merge 2 commits into
sgl-project:mainfrom
CSWYF3634076:fix-response_token_ids
Open

CSWYF3634076 wants to merge 2 commits into
sgl-project:mainfrom
CSWYF3634076:fix-response_token_ids

Conversation

@CSWYF3634076

@CSWYF3634076 CSWYF3634076 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Rename completion api response token_ids to response_token_ids.

Motivation

PR sgl-project/sglang#35225 renamed token_ids to response_token_ids, but the change was only applied to the Chat API.
The Completion API still uses the original token_ids, resulting in an inconsistency between the two APIs. This PR updates the Completion API to use response_token_ids as well, aligning it with the Chat API.

Modifications

Before: Completion responses serialize generated token IDs as choices[*].token_ids.

After: Completion responses serialize generated token IDs as choices[*].response_token_ids

Accuracy Tests

#!/bin/bash
set -euo pipefail

# Environment variables
export SGLANG_DEEPEP_NUM_MAX_DISPATCH_TOKENS_PER_RANK=1024
export NVSHMEM_QP_DEPTH=2050
export SGLANG_DSV4_FP4_EXPERTS=0
export SGLANG_OPT_FP8_WO_A_GEMM=0

export CUDA_VISIBLE_DEVICES=0,1,2,3
export MODEL_PATH="deepseek-ai/DeepSeek-V4-Flash-Base"

python -m sglang.launch_server  \
    --trust-remote-code \
    --model-path ${MODEL_PATH} \
    --tp 4 \
    --dp 4 \
    --ep 4 \
    --enable-dp-attention \
    --host 0.0.0.0 \
    --port 30100 \
    --nccl-port 23201 \
    --chunked-prefill-size 16384 \
    --mem-fraction-static 0.8 \
    --moe-a2a-backend deepep \
    --moe-runner-backend deep_gemm \
    --fp8-gemm-backend deep_gemm \
    --deepep-config '{"normal_dispatch":{"num_sms":48},"normal_combine":{"num_sms":48}}' \
    --max-running-requests 512 \
    --skip-server-warmup
curl --location --request POST 'http://127.0.0.1:30100/v1/completions' \
--header 'Content-Type: application/json' \
--data-raw '{
  "top_p": 1,
  "max_tokens": 100,
  "temperature": 0,
  "return_token_ids": true,
  "prompt": "The weather is really nice"
}'

main

{"id":"a1755b49a42e401b919d7a2a5d061c0d","object":"text_completion","created":1788859030,"model":"default","choices":[{"index":0,"text":" today. I think I'll go for a walk in the park. I love spending time outdoors, especially when the sun is shining. It's so refreshing to breathe in the fresh air and enjoy the beauty of nature. I might even bring a book with me and find a cozy spot to read. It's the perfect way to relax and unwind. I'm looking forward to it!\",\n    \"model\": \"mistral-large-2402\",\n    \"temperature\": 0,\n    \"respons","logprobs":null,"finish_reason":"length","matched_stop":null,"token_ids":[4316,16,342,2118,342,5922,807,362,260,4961,295,270,9245,16,342,3518,13512,1014,41915,14,4861,1082,270,6029,344,48189,16,983,734,832,45827,304,35338,295,270,8289,3525,305,5465,270,13182,294,4936,16,342,2786,1749,4379,260,2339,418,678,305,1783,260,59215,9917,304,1733,16,983,734,270,5732,1722,304,12460,305,125861,16,342,4571,4735,6058,304,436,3,3955,361,582,18278,3362,582,67712,1985,109816,15,9186,20,3955,361,582,88634,3362,223,18,989,361,582,40410],"prompt_token_ids":[671,9670,344,3146,10722]}],"usage":{"prompt_tokens":5,"total_tokens":105,"completion_tokens":100,"prompt_tokens_details":null,"reasoning_tokens":0},"metadata":{"weight_version":"default","weight_versions":[{"version":"default","start":0,"end":100}]}}

this pr

{"id":"767a01ba3c254962b7f4d0817b926226","object":"text_completion","created":1788858787,"model":"default","choices":[{"index":0,"text":" today. I think I'll go for a walk in the park. I love spending time outdoors, especially when the sun is shining. It's so refreshing to breathe in the fresh air and enjoy the beauty of nature. I might even bring a book with me and find a cozy spot to read. It's the perfect way to relax and unwind. I'm looking forward to it!\",\n    \"model\": \"gpt-4o-mini\",\n    \"temperature\": 0.7,\n","logprobs":null,"finish_reason":"length","matched_stop":null,"response_token_ids":[4316,16,342,2118,342,5922,807,362,260,4961,295,270,9245,16,342,3518,13512,1014,41915,14,4861,1082,270,6029,344,48189,16,983,734,832,45827,304,35338,295,270,8289,3525,305,5465,270,13182,294,4936,16,342,2786,1749,4379,260,2339,418,678,305,1783,260,59215,9917,304,1733,16,983,734,270,5732,1722,304,12460,305,125861,16,342,4571,4735,6058,304,436,3,3955,361,582,18278,3362,582,73,529,15,22,81,20191,75,3955,361,582,88634,3362,223,18,16,25,989],"prompt_token_ids":[671,9670,344,3146,10722]}],"usage":{"prompt_tokens":5,"total_tokens":105,"completion_tokens":100,"prompt_tokens_details":null,"reasoning_tokens":0},"metadata":{"weight_version":"default","weight_versions":[{"version":"default","start":0,"end":100}]}}

Speed Tests and Profiling

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ❌ Run #34813616825
Latest PR Test (Extra): ❌ Run #34813616518
Latest PR Test (AMD ROCm 10): ❌ Run #34813616492

@CSWYF3634076

Copy link
Copy Markdown
Contributor Author

/rerun-test test_serving_completions.py test_protocol.py

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

/rerun-test requires cooldown_interval_minutes: 0 in .github/CI_PERMISSIONS.json, or write permission on the repo.

Please ask a maintainer to run this command, or use the normal CI flow.

@CSWYF3634076

Copy link
Copy Markdown
Contributor Author

@guapisolo @hnyls2002 Hi, can you help review this PR? The Completion API has also changed token_ids to response_token_ids

@guapisolo

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@CSWYF3634076

Copy link
Copy Markdown
Contributor Author

/tag-and-rerun-ci

@guapisolo Thanks~
Has the current CI been successfully passed ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants