Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ dynamo-parsers = { version = "=10.2.2" }
# Published on crates.io. To see all available versions:
# web: https://crates.io/crates/dynamo-parsers-v2/versions
# sparse index: curl https://index.crates.io/dy/na/dynamo-parsers-v2 (one JSON line per release; read the "vers" field)
dynamo-parsers-v2 = { version = "=0.8.9" }
dynamo-parsers-v2 = { version = "=0.9.6" }
dynamo-backend-common = { path = "lib/backend-common", version = "1.7.0" }
dynamo-sidecar-common = { path = "lib/sidecar/common", version = "1.7.0" }

Expand Down
4 changes: 2 additions & 2 deletions lib/bindings/kvbm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/bindings/python/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

172 changes: 84 additions & 88 deletions lib/llm/src/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ fn compact_gpt_oss_prefill(prefix: &str) -> &str {
};
if header.contains("to=") || body.contains("<|") {
// Recipient-owned bodies may contain a partially consumed JSON argument.
// TODO: Use parser-owned continuation snapshots to bound retained seeds;
// replay still encodes request-sized input and retains parser state per choice.
// TODO: Validate argument prefixes incrementally so released bytes no longer
// need to remain in the shared per-request continuation body.
return prefix;
}
&prefix[..header.len() + MESSAGE.len()]
Expand Down Expand Up @@ -5790,61 +5790,56 @@ impl OpenAIPreprocessor {
None,
Some(family),
);
// TODO: Resolve model-specific prefill and guidance through the parser adapter's
// UnifiedRequestPolicy and parser capabilities; migrate equivalent batch/stream
// branches together while preserving legacy/v2 behavior.
let bare_guidance = *family == "gpt_oss"
&& (tool_choice::has_explicit_guided_decoding(request)
|| guided_tool_constraint.installs_guided_json()
&& !(self.runtime_config.structural_tag.is_some()
&& structural_tag::uses_gpt_oss_required_array(
(
self.tool_call_parser.as_deref(),
self.runtime_config.reasoning_parser.as_deref(),
),
&tool_choice::convert_tool_choice(
request
.inner
.tool_choice
.as_ref()
.unwrap_or(&ChatCompletionToolChoiceOption::Auto),
),
request.inner.parallel_tool_calls,
)));
// TODO: Replace family-specific guidance decisions with parser capabilities;
// migrate equivalent batch/stream branches together while preserving legacy/v2 behavior.
let policy = unified_parser::UnifiedRequestPolicy {
reasoning_disabled,
structured_response: Self::has_structured_response_format(request),
multiple_choices: request.inner.n.unwrap_or(1) > 1,
};
let prefill = policy.resolve_stream_prefill(
family,
unified_parser::StreamPrefill {
starting_state: if *family == unified_parser::BEAM_UNIFIED_FAMILY
&& (prompt_prefill.response || self.beam_output_is_bare_guidance(request))
{
dynamo_parsers_v2::UnifiedParserStartingState::Response
} else {
prompt_prefill.unified_starting_state.unwrap_or_else(|| {
unified_parser::stream_prefill(family, prompt_injected_reasoning)
})
},
prefix: prompt_prefill.prefix.clone(),
},
&guided_tool_constraint,
tool_choice::has_explicit_guided_decoding(request),
|| {
self.runtime_config.structural_tag.is_some()
&& structural_tag::uses_gpt_oss_required_array(
(
self.tool_call_parser.as_deref(),
self.runtime_config.reasoning_parser.as_deref(),
),
&tool_choice::convert_tool_choice(
request
.inner
.tool_choice
.as_ref()
.unwrap_or(&ChatCompletionToolChoiceOption::Auto),
),
request.inner.parallel_tool_calls,
)
},
);
let unified: Pin<Box<dyn Stream<Item = _> + Send>> =
Box::pin(unified_parser::apply_stream_with_policy(
stream,
tool_definitions,
guided_tool_constraint,
unified_parser::StreamPrefill {
starting_state: if bare_guidance
|| (*family == unified_parser::BEAM_UNIFIED_FAMILY
&& (prompt_prefill.response
|| self.beam_output_is_bare_guidance(request)))
{
// Assistant prefill inside Beam's final channel, or bare text
// an explicit `guided_*` constraint owns (no turn grammar, so
// no channel framing): the reply is visible text from its
// first byte and ends on `<|return|>` or at the end of the
// stream.
dynamo_parsers_v2::UnifiedParserStartingState::Response
} else {
prompt_prefill.unified_starting_state.unwrap_or_else(|| {
unified_parser::stream_prefill(family, prompt_injected_reasoning)
})
},
prefix: if bare_guidance {
None
} else {
prompt_prefill.prefix.clone()
},
},
prefill,
family,
guided_tool_streaming,
unified_parser::UnifiedRequestPolicy {
reasoning_disabled,
structured_response: Self::has_structured_response_format(request),
},
policy,
));
return Ok(Self::apply_unified_response_policies(
unified,
Expand Down Expand Up @@ -9603,17 +9598,19 @@ mod tests {
"plain message body is irrelevant to the parser seed"
);

let structural_prompt = format!("{header}quoted marker <|ghissue|> remains structural");
let structural_prefill = OpenAIPreprocessor::prompt_reasoning_prefill_for_parsers(
None,
Some("gpt_oss"),
Some(&structural_prompt),
);
assert_eq!(
structural_prefill.prefix.as_deref().map(str::len),
Some(structural_prompt.len()),
"marker-bearing bodies must retain their parser state"
);
for body in ["quoted marker <|ghissue|> remains structural", "partial <|"] {
let structural_prompt = format!("{header}{body}");
let structural_prefill = OpenAIPreprocessor::prompt_reasoning_prefill_for_parsers(
None,
Some("gpt_oss"),
Some(&structural_prompt),
);
assert_eq!(
structural_prefill.prefix.as_deref().map(str::len),
Some(structural_prompt.len()),
"marker-bearing bodies must retain their parser state"
);
}

let incomplete_header = "<|start|>assistant to=";
let incomplete_prefill = OpenAIPreprocessor::prompt_reasoning_prefill_for_parsers(
Expand Down Expand Up @@ -9941,33 +9938,32 @@ mod tests {
" to=python<|channel|>analysis",
"<|channel|>analysis to=python",
] {
for body in ["Hello", "quoted <|ghissue|>", "partial <|"] {
let prompt = format!(
"<|start|>assistant<|channel|>analysis<|message|>earlier<|end|><|start|>{role}{metadata}<|message|>{body}"
);
let prefill = OpenAIPreprocessor::prompt_reasoning_prefill_for_parsers(
None,
Some("gpt_oss"),
Some(&prompt),
);
assert_eq!(
prefill.prefix.is_some(),
role == "assistant",
"role={role} metadata={metadata} body={body}"
);
assert_eq!(
prefill.unified_starting_state,
(role != "assistant")
.then_some(dynamo_parsers_v2::UnifiedParserStartingState::Response),
"role={role} metadata={metadata}"
);
let reasoning = role == "assistant" && metadata.contains("<|channel|>analysis");
assert_eq!(
prefill.unified, reasoning,
"role={role} metadata={metadata}"
);
assert_eq!(prefill.legacy, reasoning, "role={role} metadata={metadata}");
}
let body = "Hello";
Comment thread
luckyq marked this conversation as resolved.
Resolved
let prompt = format!(
"<|start|>assistant<|channel|>analysis<|message|>earlier<|end|><|start|>{role}{metadata}<|message|>{body}"
);
let prefill = OpenAIPreprocessor::prompt_reasoning_prefill_for_parsers(
None,
Some("gpt_oss"),
Some(&prompt),
);
assert_eq!(
prefill.prefix.is_some(),
role == "assistant",
"role={role} metadata={metadata} body={body}"
);
assert_eq!(
prefill.unified_starting_state,
(role != "assistant")
.then_some(dynamo_parsers_v2::UnifiedParserStartingState::Response),
"role={role} metadata={metadata}"
);
let reasoning = role == "assistant" && metadata.contains("<|channel|>analysis");
assert_eq!(
prefill.unified, reasoning,
"role={role} metadata={metadata}"
);
assert_eq!(prefill.legacy, reasoning, "role={role} metadata={metadata}");
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions lib/llm/src/protocols/common/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,34 @@ mod tests {
}
}

#[test]
fn worker_extension_numbers_remain_native_for_independent_receivers() {
use dynamo_runtime::pipeline::network::RequestPlanePayloadCodec;
#[derive(Deserialize)]
struct BackendSettings {
temperature: f64,
ranks: Vec<u64>,
}
#[derive(Deserialize)]
struct BackendRequest {
extra_args: BackendSettings,
}
let request: PreprocessedRequest = serde_json::from_value(serde_json::json!({
"model": "m", "token_ids": [1, 2, 3], "stop_conditions": {},
"sampling_options": {}, "output_options": {},
"extra_args": {"temperature": 0.7, "ranks": [0, 5]}
}))
.unwrap();
for codec in [
RequestPlanePayloadCodec::Json,
RequestPlanePayloadCodec::Msgpack,
] {
let received: BackendRequest = codec.decode(&codec.encode(&request).unwrap()).unwrap();
assert_eq!(received.extra_args.temperature, 0.7);
assert_eq!(received.extra_args.ranks, vec![0, 5]);
}
}

#[test]
fn packed_token_ids_deserialize_from_msgpack_bytes() {
let ids = vec![0u32, 1, 128_000, i32::MAX as u32];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ impl DeltaAggregator {
super::unified_parser::UnifiedRequestPolicy {
reasoning_disabled: parsing_options.reasoning_disabled,
structured_response: parsing_options.structured_response,
..Default::default()
},
) {
Ok(parsed) => {
Expand Down
Loading
Loading