[Feature] Expose `max_model_len` (session_len) in `/v1/models` model card

Aperta Adatta ai principianti
#5,063 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@FOWEPJF255 ci sta già lavorando.

Dal 27/10/2026.

  • #5072 di @FOWEPJF255 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
85/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
api

Direzione di ricerca

L'issue nomma entrambi i file: aggiungi un campo opzionale max_model_len a ModelCard in serve/openai/protocol.py, poi popolalo da server_config.session_len dove le card vengono costruite in serve/openai/endpoints/models.py. Inizia leggendo questi due file e come il contesto del server espone la config. Fatto significa che GET /v1/models restituisce max_model_len corrispondente alla session_len di avvio restando però absent-compatible per gli altri client; i test esistenti dell'endpoint sono il posto dove verificare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Motivation

Problem

GET /v1/models currently returns the bare OpenAI-compatible model card
(id / object / created / owned_by / root / parent / permission). It carries
no information about the served model's context window, so clients that rely
on the models endpoint for capability discovery (agentic clients, context
compaction logic, LLM gateways doing auto-discovery) cannot learn the engine's
real serving limit and have to hardcode it.

The limit is known to the server — it is exactly ServerConfig.session_len
passed at startup — but it is not surfaced on any HTTP endpoint today
(session_len only appears internally, e.g. when constructing the Prometheus
stat logger in serve/core/async_engine.py).

Prior art (de-facto standard)

  • vLLM already emits "max_model_len": <int> as an extra field on the
    /v1/models card (e.g. {"id": "...", "owned_by": "vllm", "max_model_len": 262144, ...}).
    Many gateway/proxy integrations (e.g. LiteLLM's model-info discovery since
    v1.103, which reads max_model_len / context_length off upstream cards)
    have converged on reading these fields from OpenAI-compatible backends.
  • SGLang likewise reports context length metadata.

Because LMDeploy's card omits it, an LMDeploy backend looks "limitless"
(unknown) through such gateways even though the server knows the number.

Proposed change

Small and additive (no behavior change for existing clients):

  1. serve/openai/protocol.py: add max_model_len: int | None = None to
    ModelCard (optional field → absent from serialization when unset, cards
    stay OpenAI-clean otherwise).
  2. serve/openai/endpoints/models.py: populate it from the server context's
    server_config.session_len when building each card.

Happy to send a PR if the field name/placement is agreed (max_model_len
recommended for wire-compat with vLLM; context_length as an alias if
preferred).

Environment

  • LMDeploy 0.18.0 (also checked current main: endpoints/models.py
    unchanged, still 7-field card).
  • Observed response (TurboMind backend):
{
  "object": "list",
  "data": [
    {
      "id": "...", "object": "model", "created": ..., "owned_by": "lmdeploy",
      "root": "...", "parent": null,
      "permission": [ { "id": "modelperm-...", "...": "..." } ]
    }
  ]
}
Related resources

No response

Additional context

No response

Lingua principale
Python
Stelle
8.2k
Fork
797
Merge medio
3g 15h
PR unite (30g)
52

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di InternLM/lmdeploy

Tutte le issue di InternLM/lmdeploy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.