vllm.reasoning.granite_reasoning_parser
¶
Classes:
-
GraniteReasoningParser–Reasoning parser for IBM Granite.
GraniteReasoningParser
¶
Bases: ReasoningParser
Reasoning parser for IBM Granite.
IBM granite models currently use "Here is my thought process:" and "Here is my response:" to separate its thinking / response outputs.
Methods:
-
extract_reasoning–Extract the reasoning content & content sections, respectively.
-
extract_reasoning_streaming–Extract the reasoning content / content emitted by granite models;
_get_content_sections(current_text)
¶
Parse the text to extract the reasoning content / content if we have them.
Parameters:
Returns:
_get_delta_message_with_both_bounds(delta_text, reasoning, response_content, current_text, response_seq_len)
¶
Parse the delta message when the current text has both reasoning content and normal (response) content.
Parameters:
-
(delta_text¶str) –Text to consider and parse content from.
-
(reasoning¶str) –reasoning content from current_text.
-
(response_content¶str) –response content from current_text.
-
(current_text¶str) –The full previous + delta text.
-
(response_seq_len¶int) –Len of the complete response sequence used.
Returns:
-
DeltaMessage(DeltaMessage) –Message containing the parsed content.
_get_delta_message_with_no_reasoning_bounds(current_text, delta_text)
¶
Parse the delta message when the current text has not yet completed its start of reasoning sequence.
Parameters:
-
(current_text¶str) –The full previous + delta text.
-
(delta_text¶str) –Text to consider and parse content from.
Returns:
-
DeltaMessage(DeltaMessage) –Message containing the parsed content.
_get_delta_message_with_no_response_bounds(current_text, reasoning, delta_text)
¶
Parse the delta message when the current text has both reasoning content with no (response) content. NOTE that we may have overlapping tokens with the start of reasoning / start of response sequences on either side of the delta text.
Parameters:
-
(current_text¶str) –The full previous + delta text.
-
(reasoning¶str) –reasoning content from current_text.
-
(delta_text¶str) –Text to consider and parse content from.
Returns:
-
DeltaMessage(DeltaMessage) –Message containing the parsed content.
_is_reasoning_start_substr(text)
¶
_is_response_start_substr(text)
¶
extract_reasoning(model_output, request)
¶
Extract the reasoning content & content sections, respectively. If the sequence doesn't match what we expect, i.e., the model generates something else, all content is considered non-reasoning content.
Parameters:
-
(model_output¶str) –Output of the model to be parsed.
-
(request¶ChatCompletionRequest) –Request being processed.
Returns:
extract_reasoning_streaming(previous_text, current_text, delta_text, previous_token_ids, current_token_ids, delta_token_ids)
¶
Extract the reasoning content / content emitted by granite models; If the sequence doesn't match what we expect, i.e., the model generates something else, all content is considered non-reasoning content.
NOTE: Granite models do not use a special token to start their reasoning and response sections; instead they have token sequences, e.g.,
Here is my thought process: Foo Here is my response: Bar
This increases the complexity of correctly handling streams, since we need to watch for specific sequences and correctly parse them without dropping content that is potentially overlapping & spanning multiple delta messages.
Parameters:
-
(previous_text¶str) –Previous text outside of this delta message.
-
(current_text¶str) –Previous text + delta text.
-
(delta_text¶str) –Text to consider and parse content from.
-
(previous_token_ids¶Sequence[int]) –Token IDs of previous_text.
-
(current_token_ids¶Sequence[int]) –Token IDs of current_text.
-
(delta_token_ids¶Sequence[int]) –Token IDs of delta_text.
Returns:
-
DeltaMessage | None–Union[DeltaMessage, None] DeltaMessage with either reasoning content or content, or None.