Skip to content

feat(gemma4): serve requests through the engine contract - #890

Merged
FeathBow merged 1 commit into
pegainfer-project:mainfrom
FeathBow:feat/gemma4-http-engine-slice
Aug 16, 2026
Merged

feat(gemma4): serve requests through the engine contract#890
FeathBow merged 1 commit into
pegainfer-project:mainfrom
FeathBow:feat/gemma4-http-engine-slice

Conversation

@FeathBow

Copy link
Copy Markdown
Collaborator

Description

Closes #889.

One owned thread serves Gemma 4 requests serially through the KV-backed forward. Admission runs per step, and a request whose prompt plus requested output exceeds the serving ceiling is refused at this boundary; next-token selection and per-token logprobs go through pegainfer-sample on device logits; EOS and length finish reasons are real from the first request. Cancellation is the sink refusing an event: the request retires mid-stream, its KV returns by drop, and the engine serves the next one.

The stop token retires a request without being emitted, which is the protocol the frontend documents: it appends its own sentinel for the terminal Stop and unconditionally drops the last id, so an engine that emits EOS costs the client its final visible token. The ids the checkpoint lists under suppress_tokens are dropped out of contention before anything reads the logits row, so sampling and the logprob normalization see the same distribution and a placeholder id can neither reach the client nor return as the next step's input. Both sets are read from generation_config.json rather than assumed for the family: 12B declares the end-of-image and end-of-audio ids, 26B and 31B declare none.

At the Gemma engine boundary, everything this stage does not implement is refused loudly rather than downgraded. At load: CUDA graph capture, multi-device ordinals, parallel topologies. Per request: a resolved KV prefix, kv_transfer_params, a nonzero data_parallel_rank, a LoRA adapter, prompt echo.

The model line stops being registration only. --cuda-graph defaults to true for every line, so an explicit --cuda-graph=true is refused in ModelLine::validate before the weight load, and everything else launches eagerly. The handle publishes an 8192-token serving ceiling, which is what lets the frontend reject an over-length prompt with its own message; without it the frontend advertises the checkpoint's 262144 max_position_embeddings and forwards a request the engine can only fail mid-stream.

That ceiling is what bounds the rope tables and the pool budget: each KV pool is sized for one full-context request plus its padding page, since a prompt is prefilled in one step and both families hold every position of it before the window releases anything. The 262k the checkpoint declares needs a table and KV budget design of its own.

Test Env

Single GPU (sm_89, x86_64), CUDA 12.9, pinned 12B checkpoint.

Verification

  • fmt; clippy -D warnings over all gemma4 targets with and without the feature; the CI package set with --locked; the pegainfer-kernels hd256 smoke; gemma4 lib tests; pegainfer-server builds with --features gemma4.
  • Checkpoint gates (--ignored --test-threads=1): 8 passed, including all three certified generate fixture prompts matching token for token.
  • Live server: /v1/models reports max_model_len 8192. All three certified fixture prompts, sent as /v1/completions text at temperature 0, return text byte-identical to the fixture continuations (3/3), with prompt token counts matching the fixture (18/13/16).
  • Live server, routes: completions and chat each return identical text streaming and non-streaming ('111.1.' over 8 chunks, and Paris respectively); the chat turn ends with finish_reason=stop and no stop token in the text; per-token logprobs come back with the picked token's logprob equal to its top entry; dropping a stream mid-decode aborts the request and the next one is served normally.
  • Live server, length limits: a 9001-token prompt is refused in 0.1 s with HTTP 400 and this model's maximum context length is 8192 tokens, but the prompt contains 9001 input tokens. A one-token prompt asking for 9000 output tokens is not refused: the frontend clamps it to the remaining budget and the request completes with finish_reason=length at 8191 completion tokens.
  • Live server, CLI: --cuda-graph=true exits with Gemma 4 serves eagerly; --cuda-graph=true is not supported and no weight-load line in its output; --cuda-graph=false serves.

Type of Change

  • New feature (non-breaking change which adds functionality)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eaf3e5bf24

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread pegainfer-gemma4/src/engine.rs
@FeathBow

Copy link
Copy Markdown
Collaborator Author

@codex review please

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eaf3e5bf24

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread pegainfer-gemma4/src/engine.rs Outdated
Comment thread pegainfer-gemma4/src/model_line.rs
Signed-off-by: Feathbow <feathbow@gmail.com>
@FeathBow
FeathBow force-pushed the feat/gemma4-http-engine-slice branch from eaf3e5b to a0a55cc Compare August 16, 2026 09:58
@FeathBow

Copy link
Copy Markdown
Collaborator Author

@codex review again please

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: a0a55cc908

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@FeathBow
FeathBow merged commit 4ea6f01 into pegainfer-project:main Aug 16, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gemma4: serve 12B requests through the engine contract

1 participant