Skip to content

Hisparse Minor Fix - #22131

Merged
xiezhq-hermann merged 3 commits into
mainfrom
hisparse-fix
Apr 5, 2026
Merged

xiezhq-hermann merged 3 commits into
mainfrom
hisparse-fix

Conversation

@xiezhq-hermann

Copy link
Copy Markdown
Collaborator

Motivation

Modifications

Accuracy Tests

Speed Tests and Profiling

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

@xiezhq-hermann xiezhq-hermann self-assigned this Apr 5, 2026
@xiezhq-hermann xiezhq-hermann added the run-ci CI: run the baseline test suite on this PR label Apr 5, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request optimizes memory transfers in the hisparse JIT kernel by implementing 128-bit bulk transfers using paired 64-bit loads and stores, while also updating the scheduler to reset the batch_is_full flag and centralizing hisparse request retraction within the release_req method. Feedback was provided regarding the robustness of the transfer kernel, specifically suggesting that it should handle cases where the item size is not a multiple of 8 bytes to prevent data loss for smaller tail segments.

Comment on lines +42 to 50
const int tail_8B = (item_size_bytes - total_pairs * 16) / 8;
if (tail_8B > 0 && lane_id < tail_8B) {
const uint64_t* __restrict__ src8 =
reinterpret_cast<const uint64_t*>(static_cast<const char*>(src_addr) + total_pairs * 16);
uint64_t* __restrict__ dst8 = reinterpret_cast<uint64_t*>(static_cast<char*>(dst_addr) + total_pairs * 16);
uint64_t tmp;
asm volatile("ld.global.nc.b64 %0,[%1];" : "=l"(tmp) : "l"(src + j) : "memory");
asm volatile("st.global.cg.b64 [%0],%1;" ::"l"(dst + j), "l"(tmp) : "memory");
asm volatile("ld.global.nc.b64 %0,[%1];" : "=l"(tmp) : "l"(src8 + lane_id) : "memory");
asm volatile("st.global.cg.b64 [%0],%1;" ::"l"(dst8 + lane_id), "l"(tmp) : "memory");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This function assumes item_size_bytes is a multiple of 8. If not, the remaining 1-7 bytes won't be copied. While this might be a safe assumption for KV cache sizes, consider adding tail handling for the remaining bytes to improve robustness. This can be done using smaller integer transfers.

@xiezhq-hermann
xiezhq-hermann merged commit 30ba1f7 into main Apr 5, 2026
153 of 198 checks passed
@xiezhq-hermann
xiezhq-hermann deleted the hisparse-fix branch April 5, 2026 23:15
JustinTong0323 pushed a commit to JustinTong0323/sglang that referenced this pull request Apr 7, 2026
Co-authored-by: huangtingwei9988 <[email protected]>
Co-authored-by: hzh0425 <[email protected]>
caitengwei pushed a commit to caitengwei/sglang that referenced this pull request Jun 1, 2026
Co-authored-by: huangtingwei9988 <[email protected]>
Co-authored-by: hzh0425 <[email protected]>
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Co-authored-by: huangtingwei9988 <[email protected]>
Co-authored-by: hzh0425 <[email protected]>
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 29, 2026
…fill has not returned

Three boots of forensics land on one invariant. A request that has never
produced an output token has nothing to decode from, and decoding it anyway is
what has been killing this window's boots on their first short prompt.

The chain, measured end to end: get_next_batch_to_run makes a freshly built
PREFILL batch the running batch in the same breath. Upstream that holds --
without PP the prefill runs in the same round, so output_ids is non-empty by
the time update_running_batch sees it. The seam is stock, every commit
touching it is an upstream PR (sgl-project#29408, sgl-project#22131, sgl-project#20343, sgl-project#14320, sgl-project#17484,
sgl-project#14883), none of ours, so there is nothing to revert. PP=3 widens it: the
result comes back several passes later while membership was granted
immediately, and with one short request and no other traffic the next round
has nothing else to do and decodes it first. prepare_for_decode then leaves
the prefill input_ids in place -- there is no last token to embed -- and the
batch travels on labelled DECODE while carrying extend tokens.

Boot 67 read every link: rid e463acc5, prefix_lens=0 fill_lens=3 out_lens=0,
one ADMIT, no retraction, and no void at all (797_void=0, 798_void=0, so the
void explanation is excluded). It surfaced first as forward_mode=2 with
batch_size=1 and input_ids=3 through the sgl-project#1007 probe, then as
"causal_conv1d_update: conv_state_indices has 1 entr(ies) for a batch of 3".
Every short prompt does this, health checks included; long chunked prompts
under continuous load never reach the state, which is exactly why it stayed
latent behind every other defect this window.

So the hold sits where decode eligibility is decided, not on a consumer. The
requests are neither dropped nor reset: they stay in the running batch and
become eligible the moment their prefill result lands, and filter_batch's
keep_indices keeps the parallel tensors consistent rather than reseating reqs
by hand.

The counter is cumulative on purpose (INDIKATOR-GESETZ): a held_total that
never grows means the class no longer occurs, one that grows without bound
means results are not landing at all. Those are different diagnoses and a
per-call line could not tell them apart.

Evidence: desk, executed. py_compile; the condition sits inside
update_running_batch ahead of prepare_for_decode, and the counter is written
once and read twice. Belegstufe: DESK-BEWIESEN -- BOOT-BEWIESEN only once the
3-token probe returns tokens.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jit-kernel run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant