[Feature] Return actual prompt token IDs in opt-in Anthropic non-stream responses

オープン
#5,234 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
1/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
api, backend

調査の方向性

Implementation PR #5232 is linked and already provides the requested behavior. Review that PR and the named regression tests, test_messages_non_stream_with_output_ids_and_routed_experts and test_messages_non_stream_does_not_add_prompt_ids_without_opt_in, to see how the response includes prompt IDs only when requested. Done means the PR is merged or its changes are otherwise present.

索引モデルが issue の本文から書いたものです。

説明

Motivation

Please expose the actual inference prompt token IDs in Anthropic non-streaming /v1/messages responses when the existing LMDeploy extension return_token_ids=true is requested.

The endpoint currently exposes output_ids under this flag, but does not include prompt_token_ids. For agentic RL trajectory recording, we need both the actual prompt IDs and generated IDs to align the recorded actions with the backend sequence. Re-tokenizing rendered messages is not a reliable substitute, especially with tool messages, chat templates, and image expansion.

This is a request for an opt-in LMDeploy extension, not a requirement of the standard Anthropic API.

Reproduction and expected behavior

Against an LMDeploy server with a supported model loaded:

curl http://localhost:23333/v1/messages \
  -H 'Content-Type: application/json' \
  -H 'anthropic-version: 2023-06-01' \
  -d '{
    "model": "<served-model-name>",
    "max_tokens": 16,
    "stream": false,
    "messages": [{"role": "user", "content": "Hi"}],
    "return_token_ids": true
  }'

Actual: the response includes output_ids, but omits prompt_token_ids.

Expected: also include prompt_token_ids from chat_runner.prompt_token_ids, preserving the backend's actual prompt sequence. When the flag is omitted or false, keep the current response shape and omit this extra field.

Related resources

Implementation PR: #5232, head b828647add4711a703b2d1a9a9c96dce79e140a3.

The PR reuses IDs already available on the chat runner; it adds a response field and conditional serialization rather than introducing another tokenizer path. Endpoint regression tests cover opt-in prompt IDs and default omission:

  • test_messages_non_stream_with_output_ids_and_routed_experts
  • test_messages_non_stream_does_not_add_prompt_ids_without_opt_in

Scope is non-streaming responses. Our current OpenAI-compatible rollout path is unaffected; this request is for the Anthropic trajectory-recording path.

主要言語
Python
スター
8.2k
フォーク
797
平均マージ
3日 15時間
マージ済み PR(30日)
52

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

InternLM/lmdeploy のほかの issue

InternLM/lmdeploy の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。