feat: Add token metrics and OpenAI-compatible response format to text generation#445
feat: Add token metrics and OpenAI-compatible response format to text generation#445nyo16 wants to merge 1 commit intoelixir-nx:mainfrom
Conversation
Add timing metrics and opt-in OpenAI-compatible response formats to text generation serving. New options for `Bumblebee.Text.generation/4`: - `:include_timing` - when true, includes `generation_time_us` and `tokens_per_second` in results. For streaming with `:stream_done`, also adds `time_to_first_token_us` - `:output_format` - supports `:bumblebee` (default), `:openai` (text completions), and `:openai_chat` (chat completions) - `:model_name` - model identifier for OpenAI format responses Also tracks finish reason (EOS token vs max length) in generation, exposed as `finish_reason` in streaming done events and as "stop"/"length" in OpenAI format responses.
|
Thanks for the PR. To be honest, I am hesitant to add this. If we have completions compatible output, we should likely support completions input, otherwise it's incomplete. But the input is higher level than the current serving (e.g. agent/user chunks, instead of formatted prompt). Similarly, if a model supports tool calling, one may expect that we would emit tool chunks, which we don't. Other than that, the text serving is already a bit of complex because of streaming, and adding multiple formats feels like unnecessary complexity. Finally, while Chat Completions API are widely used, there is already Responses API, and that's only OpenAI. If we add one, it's fair to expect we may support others, and maintaining many formats doesn't seem like a good direction to me. |
Summary
This PR adds timing metrics and opt-in OpenAI-compatible response formats to Bumblebee's text generation serving, making it easier to integrate with
existing OpenAI-compatible tooling and monitor generation performance.
This will help bumblebee to integrated easier with other libs without writing custom middlewares .
New Options
Three new options for
Bumblebee.Text.generation/4::include_timing- Whentrue, includes performance metrics in results:output_format- Supports:bumblebee(default),:openai, and:openai_chat:model_name- Model identifier for OpenAI format responsesFeatures
Timing Metrics
When
include_timing: true:generation_time_us- Total generation time in microsecondstokens_per_second- Generation throughputtime_to_first_token_us- Time to first token (streaming only)Finish Reason Tracking
Tracks why generation stopped:
"stop"- EOS token reached"length"- Max length reachedOpenAI-Compatible Formats
Text Completions (
:openai):