Repository navigation
feat: Add warnings for invalid tool_choice and UTs - #6582
Merged
Merged
Conversation
- Add checks for invalid tool_choice when tool_choice is ToolChoice, e.g. function_name is not in tools - Add test_tool_choice.py to run_suite
CatherineSue
requested review from
ByronHsu,
Ying1123,
hnyls2002,
ispobock,
merrymercy and
zhyncs
as code owners
May 25, 2025 05:23
Collaborator
Author
- Replace class-level FLAKY_TESTS with setUpClass configuration for better inheritance handling - Remove warning system in favor of explicit flaky test marking - Mark `test_multi_tool_scenario_auto` and `test_multi_tool_scenario_required` as flaky - Increase max_tokens from 200 to 400 for better tool calling performance - Update `test_tool_choice_specific_function_non_streaming` to handle multiple weather calls for top 5 cities
Collaborator
Author
Layssy
pushed a commit
to Layssy/sglang-iaas
that referenced
this pull request
Jun 9, 2025
xwu-intel
pushed a commit
to xwu-intel/sglang
that referenced
this pull request
Jun 17, 2025
0826joyce
pushed a commit
to 0826joyce/sglang-perf-opt
that referenced
this pull request
May 19, 2026
yyihuang
pushed a commit
to yyihuang/sglang
that referenced
this pull request
Oct 16, 2026
…merge commit 5c5c44c314a6 (round 6) Move the FlashInfer contract pin from 36fd76859292 (PR sgl-project#6330 merge) to 5c5c44c314a6, the merge commit of PR sgl-project#6582 (round 6). python/sglang/kernels/cake_kernels/mamba.py: the contract paragraph now describes the round-6 programs: - Prescaled decay factor table and single-rounding FMA state update: the same algorithm, validated against an fp64 oracle, not bitwise the round-5 programs. - Batched programs issue the operand TMA before the metadata stage. - The FlashInfer host selects one of three exact-scan forms per call: fused single-launch (exactfused) inside the fused window for the cu_seqlens form, the batched form, and the triple form with a trusted caller cumsum; the round-6 two-kernel form (exactpre) from two chunks per work item on; the retained round-5 two-kernel programs (exact, byte for byte) for one-chunk items. - The _noring twin stays for the measured BF16/FP16 windows and is no longer selected for FP32 state. - The chunk-parallel family is a single-pass decoupled look-back program (chunkpar); the three-phase program is retained (chunkpar3, bitwise round 5). FLASHINFER_CAKE_SSD_CHUNK_PARALLEL forces or disables it. - It also states: any positive seqlen, graph-capturable prepared submission, BF16/FP16/FP32 state, token-major out, and varlen without initial_states. test/registered/kernels/ops/mamba/test_cake_ssd_combined.py: test_route_call_cu_seqlens_at_engine_chunk_size_matches_triple_and_stock asserted torch.equal(out_cu, out_tr) and torch.equal(final_cu, final_tr) between the cu_seqlens form and the triple form. Under the round-6 host route, the one-chunk geometries run different programs in the two forms. On the old pin with the round-6 FlashInfer tree, four parametrizations failed on B200 and GB300 (38 passed, 4 failed). The test now checks: (a) bitwise equality only with both forms pinned to the same two-kernel family: fused_selected is monkeypatched to return False, so the cu_seqlens form also takes two_kernel_family, which reads the same host quantities for both forms (same approach as the FlashInfer out-of-range test); (b) each form on its own within the fixed tolerance of the fp64 recurrence (_assert_within_fixed_tolerance, stock Triton(256) as the comparison arm); the cu_seqlens form already had this check, the triple form gains it; (c) a cross-form sanity check at the state-dtype tolerance for the production (unpinned) routes. The docstring says: bitwise where both forms run the same program; the one-chunk geometries run different programs under the round-6 host route and are compared under tolerance. Routing is unchanged. The public contract (supports_ssd_combined, ssd_combined_fwd, run, prepare) is unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]>
yyihuang
pushed a commit
to yyihuang/sglang
that referenced
this pull request
Oct 19, 2026
…merge commit f41bfa18fcee (rounds 7-8) Move the FlashInfer contract pin from 5c5c44c314a6 (PR sgl-project#6582 merge, round 6) to f41bfa18fcee, the merge commit of PR sgl-project#6746 (round 8), which includes PR sgl-project#6715 (2a2fa514203f, round 7). python/sglang/kernels/cake_kernels/mamba.py: the contract paragraph now describes the round-7 and round-8 host routes: - Round 7 (PR sgl-project#6715): inside the fused shape window the seq_idx triple form without a caller seq_chunk_cumsum is routed by compute capability -- sm_100a runs a light packed-varlen metadata kernel ahead of the fused main kernel (two launches, exactmeta), sm_103a runs the fused main kernel deriving its private sequence table in a CTA prologue (one launch, exactone) unless the table must be published into the caller's buffer, which keeps the two-kernel program. Two-kernel calls of at least 16 chunks per item with more (sequence, head) items than SMs, a balanced persistent grid that leaves a tail wave and a shorter pair makespan run the 2-CTA pair programs (exactpre_*_tail, bitwise the same outputs). The device programs release the auxiliary ring's empty barrier per reader (racecheck-clean; no routing or numerics change). - Round 8 (PR sgl-project#6746): sm_107a (Rubin) programs in the FlashInfer loader -- the triple form routed as on sm_103a, Rubin-calibrated chunk-parallel cost constants and a Rubin three-phase rule. This adapter keeps admitting sm_100a / sm_103a only (ARCHS unchanged); sm_107a is listed with the architectures the adapter leaves to the existing SGLang path. test/registered/kernels/ops/mamba/test_cake_ssd_combined.py: unchanged. The pinned-family bitwise clause still closes the fused window through fused_selected; the pair program needs 16 chunks per item and more items than SMs, which none of the test geometries reach, so both forms keep taking the two-kernel family from the same host quantities. Tests against FlashInfer f41bfa18fcee: - test/registered/unit/kernels/test_cake_mamba_sp_routes.py: 47 passed (CPU, on x86_64 and on aarch64). - test/registered/kernels/ops/mamba/test_cake_ssd_combined.py: 42 passed on B200 (sm_100a) and 42 passed on GB300 (sm_103a); no skips, no xfails. Routing of this adapter and its public contract (supports_ssd_combined, ssd_combined_fwd, run, prepare) are unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]>
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.


Motivation
This PR improves error handling and user experience for invalid tool choices in SGLang's function calling system. Previously, when users specified a tool_choice with a function name that doesn't exist in the available tools, the system would silently fail with
Skip invalid EBNF strings. This change adds proper validation and logging.NOTE: the correct way is to add this kind of validation in the ChatCompletionRequest protocol and returns a 400. However, our adapter.py or protocol.py doesn't have this kind of check. And it is better to fix all similar issues in refactor. So right now we use a logging.warning to mitigate it.
The changes also introduce comprehensive unit tests for tool choice functionality across different models and scenarios, ensuring robust validation of the function calling system.
Modifications
get_ebnf()method to check if the requested function exists in available toolsChecklist