Repository navigation
[Fix] qwen3_coder: Preserve structured values in qwen3_coder mixed unions - #44124
JustinTong0323 merged 8 commits into
Conversation
nvpohanh
left a comment
There was a problem hiding this comment.
[by Claude Code] Reviewed at ed4ff0111609cec3946c68e691c4c266cd4d7f72. 3 inline comments; no PR-level findings.
| schema = param_config[param_name] | ||
| if isinstance(schema, dict) and ("anyOf" in schema or "oneOf" in schema): | ||
| try: | ||
| value = json.loads(param_value) |
There was a problem hiding this comment.
Plain-text values of union and nullable string parameters now pay a failed json.loads, about 3 to 5 us each. How about decoding only when the stripped value starts with { or [?
There was a problem hiding this comment.
Yeah makes sense. added the prefix check before decoding in 7e233cd
| if isinstance(value, (dict, list)) and Draft202012Validator( | ||
| schema, registry=Registry() | ||
| ).is_valid(value): | ||
| return value |
There was a problem hiding this comment.
A decoded NaN or Infinity now reaches the arguments as non-standard JSON that strict parsers reject, where the string stayed valid. Would it make sense to reject those constants while decoding?
There was a problem hiding this comment.
877837b - Updated to check for finite numbers to catch nan, inf, and overflows, and keep the original string if parsing fails
|
/rerun-test test/registered/unit/function_call/test_function_call_parser.py test/registered/unit/entrypoints/openai/test_serving_responses_stream.py |
|
Signed-off-by: Ryan Stewart <[email protected]>
Signed-off-by: Ryan Stewart <[email protected]>
Signed-off-by: Ryan Stewart <[email protected]>
Signed-off-by: Ryan Stewart <[email protected]>
Signed-off-by: Ryan Stewart <[email protected]>
9a5321e to
c67585a
Compare
This comment has been minimized.
This comment has been minimized.
|
/tag-and-rerun-ci |
|
[by Claude Code] I've started babysitting the NVIDIA CI of this PR. I'll check it every 30 minutes until all NV pipelines pass. If a relevant job fails, I may rerun it, merge the latest Anyone can stop me at any time: just post a comment asking me to stop (for example, |
|
[by Claude Code] @rystewart-nvidia, the |
Picks up MIN_BASE_SHA c53b98d (sgl-project#45172), now required by the CI maintenance gate (sgl-project#21065) after PR Test Base run https://github.com/sgl-project/sglang/actions/runs/39361670383 was cancelled. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
[by Claude Code] All NV pipelines have passed. |
|
@JustinTong0323 Could you review this? Thanks! |
|
@JustinTong0323 could you review this? Thanks! |
…ions (sgl-project#44124) Port of merged upstream 9d45fdd. Union resolutions against local stack surface (all in qwen3_coder_detector.py): 1. _convert_param_value string branch: upstream hunk conflicted with our STRING_PARAM_TYPES module constant (stack entries 157/160 era refactor, value-identical to the upstream inline list). Kept the constant reference, took the PR union-decode block verbatim as the branch body. 2. Entry 159 (_strip_complete_tool_calls / _iter_tool_call_bodies linear scan) and entry 160 (_schema_allows_null + gated null handling): untouched by the PR's hunks; retained in full. 3. Extra call site the upstream PR cannot know about: our streaming string fast path (entry 109 + entry 160 null_as_json gate) calls _get_arguments_config before the tuple was returned; adapted to 'param_config, _ = ...'. Semantics unchanged (only the per-param schema is needed at that site). Union parity note: entry 109's streaming fast path opens only for exact type:"string" schemas, so string|object unions keep taking the buffered path through _convert_param_value; the one-shot and streaming union decode stay in parity. (cherry picked from commit 9d45fdd) (cherry picked from commit 01abd11cb2a645dd7d74abfe19011106d56f0fd5)
…5631/sgl-project#45855/sgl-project#46167 (entries 271-274) ONE docs commit: the logits trilogy is a CONTRACT UNIT -- recorded as 'never take 45631/45855 without 46167' per entry 274. Also on record: sgl-project#44124's STRING_PARAM_TYPES union + entry-159/160 retention + the streaming-fast-path call-site adaptation (141F before amend); sgl-project#45631's muse_spark hunk DROP with the sgl-project#44666-then re-check note; sgl-project#46167's wrapper-only softcap keep and the SILENT-AUTO-MERGE hazard fix (CUDA_ONLY -> local _CUDA, value-identical, kernels_namespace 76P proves). Battery EXACT: function_call 652P/1964sub on top of batch-1+2, numeric 4P/156sub, kernels_namespace 76P, spec dir 335P/11S/180sub (batch-1 pin survives all 14 picks). FLAGGED: sampling 223P/2S/43sub measured vs 263P predicted -- predicted number irreproducible on the worker's OWN tip with diff-0 across waves (prediction-vs-method gap, not landed code); logits 56P/7S unverifiable (pre-existing module-level get_device() CPU collect failure + all 4 GPUs busy with the live prod server) -- folded into the trilogy's GPU-debt block.
…k-274, wanted_stack LANDED marks, CAVEATS docs-only ledger items (A) Header: STACK line 260->274; three wave lines (+spec-mamba-2026-10-28 (pr45491+pr45435+pr45472+pr45670), +admission-2026-10-28(pr46272*+ pr43484*+pr46496*+pr46643*+pr45607*+pr45789*), +parsers-2026-10-28 (pr44124+pr45631+pr45855+pr46167)); tip line -> 2714457; updated 261-274 headline block (entry-119 SUPERSEDED by upstream sgl-project#45435/sgl-project#45472; classic-pool mamba admission gate w/ upstream ImportError CAUGHT; UNCONDITIONAL latch reset = TTFT watch; coder-parser union; logits trilogy as CONTRACT UNIT; 14 picks, 0 integrator conflicts). (B) wanted_stack.txt: FAM-A5 + FAM-B234 blocks deleted -> LANDED records (chain shas, interlock audit, supersession + behavior-change pointers into entries 261-270); SECTION-B sgl-project#44124/trilogy blocks -> LANDED; sgl-project#37958/sgl-project#45559 block -> DONE (verdict now in CAVEATS). (C) DOCS-ONLY LEDGER ITEMS: CAVEATS gains the sgl-project#37958/sgl-project#45559 VERIFIED- INERT bullet (two independent hard gates, coarse-barrier fallback, do-not-re-litigate-at-merge-sgl-project#5 line, revisit condition = dropping NEXTN or HiCache) and the dated C0b/C0c corrections (sgl-project#44030 obsolete rationale, sgl-project#44858 REVERSED by sgl-project#45289 [ported-pending wt-moe], sgl-project#44115 permanent N/A, 10-28 open-status re-verification list, no-pin-moves note: 0.7.2/0.4.9 floor unchanged) with the C0a tick (sgl-project#37625/sgl-project#37941/sgl-project#39727 still outstanding; only sgl-project#43927/sgl-project#44849 partially satisfied). C0b/C0c/C8 marked DONE in wanted_stack; C0a stays open.
Motivation
Closes #44120
When a tool parameter allows a string or an object,
qwen3_codertreats the model's object JSON as a string. After one decode offunction.arguments, callers get{"location": "{\"city\": \"Paris\"}"}instead of{"location": {"city": "Paris"}}. String/array unions have the same problem, including streamed responses.This can affect any model using
--tool-call-parser qwen3_coder. The string result is schema-valid, but it loses the structured value emitted by the model.Related work: #30832 added nullable-array support, and #36626 fixed top-level schema property lookup. This addresses a separate case: a known parameter whose own union allows both strings and structured values.
Modifications
In the detector's existing string conversion branch, check
anyOf/oneOfparameters for complete object or array JSON. Keep the decoded value only when it satisfies the parameter schema.Plain strings, scalar unions, malformed JSON, values that do not match the schema, and unresolved references keep their existing behavior. Schema validation does not fetch external references.
This intentionally prefers an allowed object or array when mixed-union text could also be read as a string. String-only parameters still keep JSON-looking text as strings.
The change is limited to the Qwen3-Coder detector and its existing registered tests. The shared inference helper, other detector implementations, public APIs, and dependency lists are unchanged.
step3p5andnanbeigealso use this detector and receive the same behavior. Type arrays and root-level reference resolution are outside this fix.Accuracy Tests
Does not change kernel or affect model forward code, but does affect structured output correctness.
Validation used
lmsysorg/sglang:v0.5.21(digestsha256:b1259f3ea3275f66237c498ea388919729018bc9f01c3d638391e06e2cf3f469). Baseline raw-output logging left conversion unchanged; the patched serving run installed only the exact candidate detector. The regression tests ran against the native runtime without adding compatibility modules.The full original detector and relevant type-inference function are byte-identical to main (
7dc2930585782c09630d617a510bec08c1724845), so I didn't run a separate test on main.These checks were only for parser correctness; no general model accuracy benchmark was run.
Speed Tests and Profiling
No speed benchmark was run. This adds JSON parsing for string-inferred
anyOf/oneOfparameters, followed by schema validation when the decoded value is an object or array. Model execution and decoding kernels are unchanged.Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ✅ Run #39374134476
Latest PR Test (Extra): ❌ Run #39374134442
Latest PR Test (AMD ROCm 10): ❌ Run #39374134512