Skip to content

Allow more flexible assistant and system response - #1256

Merged
merrymercy merged 8 commits into
sgl-project:mainfrom
BabyChouSr:chris/fix-openai-vision
Aug 30, 2024
Merged

merrymercy merged 8 commits into
sgl-project:mainfrom
BabyChouSr:chris/fix-openai-vision

Conversation

@BabyChouSr

@BabyChouSr BabyChouSr commented Aug 29, 2024 •

Copy link
Copy Markdown
Contributor

Motivation

Right now system and assistant response are required to be in this format:

{'role': 'assistant', 'content': text}

where text is an instance of a string. We seek to add the additional flexibility of this format:

{'role': 'assistant', 'content':  ['type': 'text', 'text': text]}

Additionally, this PR also closes #1265.

Modifications

Checklist

  • Format your code according to the Contributor Guide.
  • Add unit tests as outlined in the Contributor Guide.
  • Update documentation as needed, including docstrings or example tutorials.

CI States

Latest PR Test (Base): ❌ Missing run-ci label -- add it to run CI tests.
Latest PR Test (Extra): ❌ Blocked -- run-ci is required first.

@zhyncs

zhyncs commented Aug 29, 2024

Copy link
Copy Markdown
Contributor
pip3 install pre-commit
cd sglang
pre-commit install
pre-commit run --all-files

@BabyChouSr

@BabyChouSr
BabyChouSr marked this pull request as draft August 29, 2024 05:55
@merrymercy
merrymercy marked this pull request as ready for review August 29, 2024 06:05
merrymercy
merrymercy previously approved these changes Aug 29, 2024
@BabyChouSr

Copy link
Copy Markdown
Contributor Author

Do not merge yet please. I'm hitting a bug that I will try to figure out tomorrow. Basically, when there are assistant messages in the prompt, the output content from tokenizer.generate_request includes a string-ified version of the ChatCompletionMessageContentTextPart. I'm not completely sure why.
image

@zhyncs

zhyncs commented Aug 30, 2024

Copy link
Copy Markdown
Contributor

Does this PR fix #1265?

@BabyChouSr

Copy link
Copy Markdown
Contributor Author

Does this PR fix #1265?

Yes. It is meant to close #1265.

The idea is we convert all pydantic models to dict and then make it openai compatible by only extracting out the text from it so that huggingface's chat template can appropriate apply the chat template.

@zhyncs

zhyncs commented Aug 30, 2024

Copy link
Copy Markdown
Contributor

Hi @BabyChouSr May you add a unit test for this and run a benchmark? Thanks.

@merrymercy

merrymercy commented Aug 30, 2024 •

Copy link
Copy Markdown
Collaborator

These are good fixes! For your issue, see my comments #1265 (comment). Your fixes are still useful for other cases so we would like to merge this.

Is this fully ready to be merged?

@BabyChouSr

Copy link
Copy Markdown
Contributor Author

These are good fixes! For your issue, see my comments #1265 (comment). Your fixes are still useful for other cases so we would like to merge this.

Is this fully ready to be merged?

Yes, I just added a unit test and after the tests pass, this is ready to be merged.

@BabyChouSr
BabyChouSr requested a review from merrymercy August 30, 2024 17:16
@merrymercy
merrymercy merged commit 51c554d into sgl-project:main Aug 30, 2024
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 11, 2026
…r acted upon

A bug in my own S2 wiring, of the exact class this slice exists to remove.
`_weg2_xchg_inject_from_peer` computed `wx.inject_mode()` and IGNORED `kw`,
while one of its two callers passes the mode explicitly:
`_weg2_xchg_shadow_compare` -- the step-6c grader -- calls
`_weg2_xchg_inject_weights(mode=wx.INJECT_SHADOW)`.

WHY IT WOULD HAVE STAYED INVISIBLE: on the S6I order's own argv the flag and
the call site AGREE (`inject=shadow`), so the dropped argument produced the
right answer. An argument published by a caller, read into `**kw`, and never
consulted -- sgl-project#1256's shape, one level in from where I had just removed four
instances of it. It would have surfaced only when the flag and the grader
disagree, which is exactly when a grade matters.

`mode = str(kw.get("mode") or "") or wx.inject_mode()`: the caller wins, the
flag is the fallback, resolved once and passed down.

AND THE CHAIN THAT MAKES ITEMS (a)/(c) REACHABLE IS NOW PINNED, because it is
the answer to "why did four boots grade nothing":
`_weg2_xchg_shadow_compare` fires under `exchange_armed() and inject_mode() ==
INJECT_SHADOW` -- the S6I argv -- and is itself called from this file. With S2's
delegation in place it reaches `run_bounce_leg`, where `comparing = mode ==
INJECT_SHADOW` produces the `InjectVerdict` whose line IS grading item (a), and
writes `bounce.bin` for item (c).

MUTANT M10 (drop the caller's mode) fails `test_an_explicit_mode_from_the_caller_wins`
by name. The test arms `authoritative` so the flag and the caller DISAGREE --
the only configuration that can tell "honoured the caller" from "recomputed and
got lucky".

Recorded because the first M10 attempt had a quote-escaping error in its own
mutation script and reported SURVIVED against unmutated source: a mutant whose
application is not verified is not a mutant. Same shape caught earlier on M4.
gjsheu pushed a commit to gjsheu/sglang that referenced this pull request Sep 24, 2026
* support k3 on a5

Signed-off-by: zhaozx-cn <[email protected]>

* refractor

Signed-off-by: zhaozx-cn <[email protected]>

* Run the shared-expert MLP on the alternate stream while keeping attention-TP all-gather and reduce-scatter on the current stream.

* run fused_qkvg_proj with Kimi-K3-W4A8 quanted with modelslim

* fix(npu): skip KDA autotune during first request (#2)

* skip qkv_proj (#4)

* fix spec acc

Signed-off-by: zhaozx-cn <[email protected]>

* k3 use fias v2 (sgl-project#6)

* feat: support Kimi-K3 DSPARK PD decode radix cache (sgl-project#7)

Co-authored-by: qyb233 <{"message":"Not Found","documentation_url":"https://docs.github.com/rest/users/emails#list-email-addresses-for-the-authenticated-user","status":"404"}>

* fix(npu): use DeepEP MXFP8 dispatch for W4A8 MXFP MoE (sgl-project#11)

* A5 k3 fp8 fused (sgl-project#13)

* fix(npu): use DeepEP MXFP8 dispatch for W4A8 MXFP MoE

* feat(npu): fuse K3 SiTU MXFP8 quantization

---------

Co-authored-by: zhaozx-cn <[email protected]>

* perf(npu): reuse graph update worker

* fix(npu): use NPU chain rejection sampling for DSPARK

* feat(npu): add fine-grained Kimi-K3 shared expert overlap

* [NPU] Skip DSpark Mamba tracking when no boundary can be crossed

* feat(npu): switch Ascend KDA extend to fused chunk_kda_fwd (sgl-project#30)

Replace the multi-kernel Ascend KDA extend path (chunk_local_cumsum,
chunk_kda_scaled_dot_kkt_fwd, solve_tril_npu, recompute_w_u_fwd_npu,
chunk_gated_delta_rule_fwd_h_npu, chunk_gla_fwd_o_gk_npu) with a single
torch.ops.npu.chunk_kda_fwd call.

The fused op takes one initial state per logical sequence in contiguous
[N, H, V, K] layout, while SGLang owns a slot-indexed persistent pool, so
the wrapper gathers the active slots before the call and scatters
final_state back afterwards. chunk_states comes back in the layout the
tracker already expects, which drops the transpose on the
intermediate-state path.

Forward metadata uses -1 in cache_indices for a padded request. The gather
would turn that into a read of the last cache slot, and index_copy_ would
then write the padded row's final_state back over that same slot,
corrupting the state of whichever live sequence owned it. Clamp the gather
indices to 0 so a padded row reads a harmless placeholder, and filter
padded rows out of the writeback entirely.

Drop the speculative-decoding-only NPU transpose of temporal_state in
MambaPool. It presented the pool as a transposed view so the stride-aware
verify kernel and state movers saw the canonical [pool, HV, V, K] logical
shape; the fused extend path consumes the pool directly in that layout, so
every consumer now agrees on one contiguous representation. The adjacent
shape comment described the swapped layout and is corrected with it.

Also rewrite the conv_states copy for non-tracked entries as a no-op
self-copy, so it no longer runs bool-mask indexing (aten::nonzero) or a
host numel check on every step.

* nz

Signed-off-by: zhaozx-cn <[email protected]>

* fix(npu): restore logical MLA prefix pages from NZ cache

Unpack PA-NZ latent and RoPE cache pages before prefix projection and attention concatenation. Ordinary MLA writes can use NZ independently of MLAPO, so raw page gathers otherwise mix token and feature dimensions.

Add CPU regression coverage for ND/NZ layouts, latent/RoPE dimensions, reordered and repeated pages, empty selections, and partial-page writes. Validated test bodies and forward_extend inputs in an isolated CPU PyTorch harness, including a legacy-path negative control; syntax and targeted Ruff checks passed. A5 GSM8K and NPU execution remain to be validated.

* [Kimi-K3] Allow shared-expert TP subgroups below attention TP

* revert kda triton kernel modification

Signed-off-by: zhaozx-cn <[email protected]>

* Revert "feat: support Kimi-K3 DSPARK PD decode radix cache (sgl-project#7)"

This reverts commit e83efb3.

* fix

Signed-off-by: zhaozx-cn <[email protected]>

* fix lint

Signed-off-by: zhaozx-cn <[email protected]>

* fix shares expert tp

Signed-off-by: zhaozx-cn <[email protected]>

* fix lint

Signed-off-by: zhaozx-cn <[email protected]>

* fix dispatch

Signed-off-by: zhaozx-cn <[email protected]>

* fix lint

Signed-off-by: zhaozx-cn <[email protected]>

* remove unused code

Signed-off-by: zhaozx-cn <[email protected]>

* fia v2 for mtp

Signed-off-by: zhaozx-cn <[email protected]>

* fia v2

Signed-off-by: zhaozx-cn <[email protected]>

* fix kimi k3 pd acc on npu

Signed-off-by: zhaozx-cn <[email protected]>

* fix pd kimi k3 acc on npu

Signed-off-by: zhaozx-cn <[email protected]>

* fix ci

Signed-off-by: zhaozx-cn <[email protected]>

* fix

Signed-off-by: zhaozx-cn <[email protected]>

* fix ci

Signed-off-by: zhaozx-cn <[email protected]>

* fix

Signed-off-by: zhaozx-cn <[email protected]>

---------

Signed-off-by: zhaozx-cn <[email protected]>
Co-authored-by: hanwlax <[email protected]>
Co-authored-by: McZyWu <[email protected]>
Co-authored-by: qyb233 <[email protected]>
Co-authored-by: Hexq0210 <[email protected]>
Co-authored-by: sherdavincl9 <[email protected]>
Co-authored-by: sglang-npu-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] OpenAI Compatible Prompt Template Error

3 participants