server: add timings block to OpenAI-compatible responses (#342)#572
Open
Mike014 wants to merge 1 commit into
Open
server: add timings block to OpenAI-compatible responses (#342)#572Mike014 wants to merge 1 commit into
Mike014 wants to merge 1 commit into
Conversation
Expose prompt/decode timing stats in a top-level 'timings' object, sibling to 'usage', matching the llama.cpp-style format requested in prompt_per_second, predicted_n, predicted_ms, predicted_per_token_ms, predicted_per_second. Covers both blocking and streaming (stream_include_usage-gated) responses. Note: append_openai_timings_json is also exercised by the legacy /v1/completions path via final_response, not only /v1/chat/completions as literally scoped in antirez#342 -- matches llama.cpp behavior, flagging for visibility. Testing: - make cpu: clean build, -Wall -Wextra, zero warnings - ./ds4_test --server: pass, including two new tests (test_openai_stream_usage_reports_cache_details extended, test_openai_timings_zero_division added) - No model/GPU available on this machine (CPU-only dev environment); production backend (Metal/CUDA) not exercised, flagging for maintainer verification - Speed track (ds4-bench) not applicable: no inference-path or kernel code touched, only response serialization and two now_sec() calls outside the decode loop Signed-off-by: mike014 <mikgrimaldi7@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Exposes prompt/decode timing stats in a top-level
timingsobject,sibling to
usage, matching the llama.cpp-style format requested in #342:cache_n,prompt_n,prompt_ms,prompt_per_token_ms,prompt_per_second,predicted_n,predicted_ms,predicted_per_token_ms,predicted_per_second.Covers both blocking and streaming (
stream_include_usage-gated)OpenAI-compatible responses.
Scope note
append_openai_timings_jsonis also exercised by the legacy/v1/completionspath viafinal_response, not only/v1/chat/completionsas literally scoped in #342 — this matchesllama.cpp's behavior, flagging it here for visibility in case that's
not the intended scope.
Testing
make cpu: clean build,-Wall -Wextra, zero warnings./ds4_test --server: pass, including two new tests(
test_openai_stream_usage_reports_cache_detailsextended,test_openai_timings_zero_divisionadded — verifies no NaN/Inf/malformedJSON when
completion_tokens=0orcache_read_tokens=0)backend (Metal/CUDA) not exercised — flagging for maintainer
verification before merge
ds4-bench) not applicable: no inference-path or kernelcode touched, only response serialization plus two
now_sec()callsoutside the decode loop
AI assistance disclosure
Development assisted by Claude (Anthropic) and Fable 5 — I reviewed and
verified every changed line, ran the tests above myself, and traced the
call chain by hand before implementing. Happy to walk through any part
of the diff in more detail.
Closes #342