GPT-5.6 Sol · Serving

S03 · TTFT

Valid

Online TTFT 1dev · Implementation Optimization

1.07×PERFORMANCE RATIO
110TOOL EVENTS
1TEXT PATCHES
0BINARY NAMES

01 / PROCESS MAP

Tool activity

Each row shows one agent’s tool events in its own recorded order. Colors show broad activities; bar widths do not represent duration.

Main agentGPT-5.6 Sol · 110 visible calls

InspectEditValidateExecuteBuildProfileRollbackOther
55Inspect
6Edit
9Build
12Validate
7Execute
1Profile
20Other

02 / EVENT SEQUENCE

Event timeline

Requests are grouped by agent, activity and topic. Delegations open into child branches. Summaries describe visible requests; tool errors and missing responses are flagged. A recorded response does not establish command success or a performance improvement.

Show event timelineHide event timeline80 groups · 110 calls

Scroll within this panel to view all events. Command sketches retain familiar programs and options. Values become <val> or <n>; paths, addresses and script bodies are hidden as <path>, <url> and <script>.

Main agent

  1. Inspect · Task requirements

    Requested workspace inspection, environment setup or inspection and source searches related to task requirements.

    2 calls · #0001–#0002

    pwdprintenv <vars>rg --files -g <val> -g <path> -g <path> <path>sed -n <val> <path>
  2. Validate · Task requirements

    Requested workspace inspection, file and log inspection and repository inspection related to task requirements.

    1 call · #0003–#0003

    find <path> -type <val> -maxdepth <n> <flag>sortsed -n <val> <path><command> <args>git status --short <flag> <args>
  3. Other · Source & workspace

    1 tool error

    Requested script or workload execution related to source & workspace.

    1 call · #0004–#0004

    bash <script>
  4. Inspect · Benchmark & validation setup

    Requested workspace inspection and file and log inspection related to benchmark & validation setup.

    1 call · #0005–#0005

    find <val> -type <val> <flag> <args>sortsed -n <val> <path>
  5. Other · Source & workspace

    Requested environment setup or inspection related to source & workspace.

    1 call · #0006–#0006

    env <vars> bash <script>
  6. Profile · Task requirements

    Requested environment setup or inspection, source searches and file and log inspection related to task requirements.

    1 call · #0007–#0007

    envrg <val>sortjq <val> <val>jq <val> <path>git status --short <flag> <args>
  7. Inspect · Task requirements

    Requested source searches and file and log inspection related to task requirements.

    1 call · #0008–#0008

    rg -n <val> <path>tail -n <n> <path>sed -n <val> <path>
  8. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0009–#0009

    sed -n <val> <path>
  9. Validate · Benchmark & validation setup

    Requested file and log inspection, runtime inspection and source searches related to benchmark & validation setup.

    3 calls · #0010–#0012

    tail -n <n> <path> <n> > <path>trueps <flag> <args>rg <val>rg -v <val>
  10. Validate · Task requirements

    Requested environment setup or inspection related to task requirements.

    1 call · #0013–#0013

    env <vars> bash <script>
  11. Validate · Benchmark & validation setup

    Requested workspace file updates, file and log inspection and repository inspection related to benchmark & validation setup.

    1 call · #0014–#0014

    cp <path> <path>sha256sum <path> <path>jq <path> <path>git status --short <flag> <args>
  12. Execute · Benchmark & validation setup

    Requested file and log inspection, runtime inspection and source searches related to benchmark & validation setup.

    1 call · #0015–#0015

    tail -n <n> <path> <n> > <path>trueps <flag> <args>rg <val>rg -v <val>
  13. Inspect · Source & workspace

    Requested file and log inspection and workspace inspection related to source & workspace.

    2 calls · #0016–#0017

    tail -n <n> <path> <n> > <path>truefind <val> -maxdepth <n> -type <val> -name <val> <flag> <args>sorttail -n <n>
  14. Inspect · Batching & scheduling

    Requested workspace inspection and file and log inspection related to batching & scheduling.

    2 calls · #0018–#0019

    find <val> -maxdepth <n> -type <val> <val> -name <val> -o -name <val> <args>sorttail -n <n>tail -n <n> <path>sed -n <path>
  15. Inspect · Source & workspace

    1 tool error

    Requested workspace inspection and file and log inspection related to source & workspace.

    3 calls · #0020–#0022

    find <val> -maxdepth <n> -type <val> <val> -name <val> -o -name <val> <args>sorttail -n <n><command> <args>jq <val> <val>printf <val> <val>
  16. Execute · Latency & request handling

    Requested workspace inspection, file and log inspection and runtime inspection related to latency & request handling.

    1 call · #0023–#0023

    find <val> -maxdepth <n> -type <val> <val> -name <val> -o -name <val> <args>sort<command> <args>printf <val> <val>jq <val> <val>ps <flag> <args>
    3 more command sketches
    rg <val>rg -v <val>true
  17. Other · Task requirements

    Requested environment setup or inspection related to task requirements.

    1 call · #0024–#0024

    env <vars> bash <script>
  18. Inspect · Batching & scheduling

    Requested workspace inspection and file and log inspection related to batching & scheduling.

    1 call · #0025–#0025

    find <val> -maxdepth <n> -type <val> <val> -name <val> -o -name <val> <args>sorttail -n <n> <path>sed -n <path>
  19. Inspect · Attention kernels

    Requested repository inspection, source searches and file and log inspection related to attention kernels.

    5 calls · #0026–#0030

    git log -n <n> --oneline <flag>rg -n <val> <path> <path>head -n <n>rg --files <path>rg <val>sed -n <val> <path>
    5 more command sketches
    <command> <args>sed -n <val>jq <val> <path>rg -n <val> <path> <path> <path> <path>rg -n <val> <path>
  20. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0031–#0031

    <command> <args>jq <val> <val>sed -n <val>
  21. Inspect · Attention kernels

    Requested source searches and file and log inspection related to attention kernels.

    2 calls · #0032–#0033

    rg -n <val> <path> <val>head -n <n>sed -n <val> <path><command> <args>sed -n <val>
  22. Inspect · Device memory

    Requested file and log inspection and source searches related to device memory.

    1 call · #0034–#0034

    <command> <args>sed -n <val>rg -n <val> <path> <path>head -n <n>
  23. Inspect · KV-cache management

    Requested source searches and file and log inspection related to kv-cache management.

    1 call · #0035–#0035

    rg -n <val> <path> -g <path>head -n <n><command> <args>sed -n <val>
  24. Inspect · Source & workspace

    Requested file and log inspection, source searches and environment setup or inspection related to source & workspace.

    2 calls · #0036–#0037

    jq <path> <val>sed -n <val>rg -n <val> <path>sed -n <val> <path>envrg <val>
    1 more command sketches
    sort
  25. Other · Source & workspace

    Requested script or workload execution related to source & workspace.

    1 call · #0038–#0038

    python3 -c <script>
  26. Inspect · Source & workspace

    Requested source searches and file and log inspection related to source & workspace.

    2 calls · #0039–#0040

    rg -n <val> <path>head -n <n>rg -n <val> <path> <path>
  27. Inspect · Batching & scheduling

    Requested file and log inspection related to batching & scheduling.

    1 call · #0041–#0041

    <command> <args>sed -n <val>
  28. Other · Source & workspace

    Requested script or workload execution related to source & workspace.

    3 calls · #0042–#0044

    python3 - <script>
  29. Other · Attention kernels

    Requested script or workload execution related to attention kernels.

    2 calls · #0045–#0046

    python3 - <script>
  30. Inspect · Attention kernels

    Requested source searches and file and log inspection related to attention kernels.

    3 calls · #0047–#0049

    rg -n <val> <path> <path> -g <path> -g <val> -g <val> -g <val>head -n <n>sed -n <val> <path>rg -n <val> <path> <path> -g <val> -g <val> -g <val> -g <val>
  31. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0050–#0050

    sed -n <val> <path>
  32. Inspect · Attention kernels

    2 tool errors

    Requested source searches, file and log inspection and script or workload execution related to attention kernels.

    3 calls · #0051–#0053

    rg -n <val> <path> <path> -g <val> -g <path> -g <val>head -n <n>python3 - <script>sed -n <val> <path>rg -n <val> <path> -g <path>rg -n <val> <path> <path>
  33. Other · Attention kernels

    Requested script or workload execution related to attention kernels.

    1 call · #0054–#0054

    python3 - <script>
  34. Inspect · Attention kernels

    Requested file and log inspection related to attention kernels.

    1 call · #0055–#0055

    sed -n <val> <path>
  35. Other · Attention kernels

    1 tool error

    Requested script or workload execution related to attention kernels.

    1 call · #0056–#0056

    python3 - <script>
  36. Execute · Attention kernels

    Requested workspace file updates, source searches and file and log inspection related to attention kernels.

    1 call · #0057–#0057

    cp <path> <path>rg -n <val> <path> <path> <path> <path>sed -n <val> <path>
  37. Inspect · Attention kernels

    Requested file and log inspection and source searches related to attention kernels.

    2 calls · #0058–#0059

    sed -n <val> <path>rg -n <val> <path>head -n <n>rg -n <val> <path> <path> <path> -g <path>
  38. Inspect · Device memory

    Requested file and log inspection and source searches related to device memory.

    3 calls · #0060–#0062

    sed -n <val> <path>rg -n <val> <path> -g <path>rg -n <val> <path>head -n <n>rg -n <val> <path> <path> -g <path>
  39. Edit · Attention kernels

    Requested code edits related to attention kernels.

    1 call · #0063–#0063

    Apply patch <patch>
  40. Inspect · Attention kernels

    Requested repository inspection and file and log inspection related to attention kernels.

    1 call · #0064–#0064

    git diff <flag> <args>sed -n <val> <path>
  41. Edit · Device memory

    Requested code edits related to device memory.

    1 call · #0065–#0065

    Apply patch <patch>
  42. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0066–#0066

    Apply patch <patch>
  43. Inspect · Attention kernels

    Requested repository inspection, script or workload execution and file and log inspection related to attention kernels.

    1 call · #0067–#0067

    git diff --checkgit status --shortpython3 -m <module> <script> <script> <script>sed -n <val> <path>
  44. Other · Attention kernels

    1 tool error

    Requested environment setup or inspection related to attention kernels.

    1 call · #0068–#0068

    env <vars> python3 - <script>
  45. Build · Attention kernels

    1 tool error

    Requested workspace inspection, file and log inspection and script or workload execution related to attention kernels.

    1 call · #0069–#0069

    find <val> -maxdepth <n> -type <val> -name <val> -o -name <path>head -n <n>python3 - <script>sed -n <val> <path>rg -n <val> <path> -g <path> -g <path>
  46. Other · Attention kernels

    Requested environment setup or inspection related to attention kernels.

    1 call · #0070–#0070

    env <vars> python3 - <script>
  47. Edit · Attention kernels

    Requested code edits related to attention kernels.

    1 call · #0071–#0071

    Apply patch <patch>
  48. Other · Source & workspace

    1 tool error

    Requested script or workload execution related to source & workspace.

    1 call · #0072–#0072

    bash <script>
  49. Build · Task requirements

    Requested environment setup or inspection, source searches and file and log inspection related to task requirements.

    1 call · #0073–#0073

    envsortrg <val>sed -n <val>python3 - <script>rg -n <val> <val> -g <val> -g <path> -g <path>
    1 more command sketches
    head -n <n>
  50. Inspect · Source & workspace

    Requested file and log inspection and source searches related to source & workspace.

    1 call · #0074–#0074

    sed -n <val> <path>rg -n <val> <path> -g <val> <n> > <path>head -n <n>
  51. Other · Attention kernels

    1 tool error

    Requested environment setup or inspection related to attention kernels.

    1 call · #0075–#0075

    env <vars> bash <script>
  52. Build · Source & workspace

    Requested file and log inspection, workspace inspection and source searches related to source & workspace.

    1 call · #0076–#0076

    sed -n <val> <path>find <path> -maxdepth <n> -type <val>sed -n <val>rg -n <val> <path> <path> <n> > <path>head -n <n>
  53. Validate · Attention kernels

    Requested environment setup or inspection related to attention kernels.

    1 call · #0077–#0077

    env <vars> python3 -m <module> -q <path>
  54. Validate · Task requirements

    Requested source searches and environment setup or inspection related to task requirements.

    2 calls · #0078–#0079

    rg -n <path> <path> <path> -g <path> -g <path>env <vars> bash <script>
  55. Validate · Benchmark & validation setup

    Requested workspace file updates and script or workload execution related to benchmark & validation setup.

    1 call · #0080–#0080

    cp <path> <path>sha256sum <path> <path>python3 - <script>
  56. Execute · Benchmark & validation setup

    Requested workspace inspection and file and log inspection related to benchmark & validation setup.

    1 call · #0081–#0081

    ls -l -t <val>sed -n <val><command> <args>tail -n <n> <val>
  57. Inspect · Source & workspace

    Requested file and log inspection and workspace inspection related to source & workspace.

    3 calls · #0082–#0084

    tail -n <n> <path>stat -c <val> <path> <path>date <flag>ls -l -t <val>sed -n <val>date <val>
    1 more command sketches
    ls -l -t <path> <path> <path> <n> > <path>
  58. Other · Source & workspace

    Requested script or workload execution related to source & workspace.

    1 call · #0085–#0085

    python3 - <script>
  59. Inspect · Source & workspace

    Requested workspace inspection and file and log inspection related to source & workspace.

    1 call · #0086–#0086

    date <val>ls -l -t <path> <path> <path> <n> > <path>sed -n <val>
  60. Other · Task requirements

    Requested environment setup or inspection related to task requirements.

    1 call · #0087–#0087

    env <vars> bash <script>
  61. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0088–#0088

    Apply patch <patch>
  62. Execute · Attention kernels

    Requested workspace file updates, script or workload execution and repository inspection related to attention kernels.

    1 call · #0089–#0089

    cp <path> <path>python3 -m <module> <script> <script> <script> <script>git diff --check<command> <args>python3 - <script>
  63. Inspect · Source & workspace

    Requested workspace inspection and file and log inspection related to source & workspace.

    1 call · #0090–#0090

    date <val>ls -l -t <path> <path> <path> <n> > <path>sed -n <val>
  64. Other · Source & workspace

    Requested workspace inspection and script or workload execution related to source & workspace.

    1 call · #0091–#0091

    date <val>stat -c <val> <path> <path>python3 - <script>
  65. Other · Task requirements

    Requested environment setup or inspection related to task requirements.

    1 call · #0092–#0092

    env <vars> bash <script>
  66. Edit · Attention kernels

    Requested code edits related to attention kernels.

    1 call · #0093–#0093

    Apply patch <patch>
  67. Execute · Attention kernels

    Requested workspace file updates and repository inspection related to attention kernels.

    1 call · #0094–#0094

    cp <path> <path>git diff --statgit diff --checkgit diff <flag> <args>
  68. Validate · Task requirements

    Requested environment setup or inspection related to task requirements.

    1 call · #0095–#0095

    env <vars> bash <script>
  69. Validate · Attention kernels

    Requested workspace file updates and environment setup or inspection related to attention kernels.

    1 call · #0096–#0096

    cp <path> <path>sha256sum <path> <path>env <vars> python3 -m <module> -q <path>
  70. Inspect · Task requirements

    Requested file and log inspection and script or workload execution related to task requirements.

    1 call · #0097–#0097

    sed -n <val> <path>python3 - <script>
  71. Execute · Attention kernels

    Requested script or workload execution and repository inspection related to attention kernels.

    1 call · #0098–#0098

    bash <script>git status --shortgit diff --checkpython3 -m <module> <script> <script> <script> <script>python3 - <script>
  72. Build · Source & workspace

    Requested file and log inspection and source searches related to source & workspace.

    1 call · #0099–#0099

    sed -n <val> <path><command> <args>rg -n -i <val>head -n <n>rg -n <val> <val> -g <val>
  73. Other · Source & workspace

    Requested environment setup or inspection related to source & workspace.

    1 call · #0100–#0100

    env <vars> python3 -c <script>
  74. Build · Source & workspace

    Requested environment setup or inspection related to source & workspace.

    1 call · #0101–#0101

    env <vars> python3 -c <script>
  75. Inspect · Source & workspace

    Requested source searches, file and log inspection and environment setup or inspection related to source & workspace.

    3 calls · #0102–#0104

    rg -a -l <val> <path> <path> <n> > <path>head -n <n><command> <args>rg -C <n> <val>sed -n <val>rg -i -C <n> <val>
    4 more command sketches
    envrg <val>sortls -l <path> <path> <n> > <path>
  76. Build · Source & workspace

    Requested environment setup or inspection related to source & workspace.

    1 call · #0105–#0105

    env <vars> python3 -c <script>
  77. Inspect · Source & workspace

    Requested script or workload execution, file and log inspection and environment setup or inspection related to source & workspace.

    1 call · #0106–#0106

    <command> <args>python3 -c <script> <n> >& <path>tail -n <n>env <vars> python3 -c <script> <n> >& <path>
  78. Build · Attention kernels

    Requested workspace file updates, environment setup or inspection and workspace inspection related to attention kernels.

    2 calls · #0107–#0108

    <command> <args>mv <path> <path>env <vars> bash <script>command -v <val>truesha256sum <path> <path>
    1 more command sketches
    find <val> -maxdepth <n> -type <val> -name <val> <flag>
  79. Build · Source & workspace

    Requested workspace inspection and repository inspection related to source & workspace.

    1 call · #0109–#0109

    find <path> <flag> <args>test <val> -e <path>find <val> -maxdepth <n> -type <val> -name <val> <flag>git status --shortgit diff --check
  80. Inspect · Source & workspace

    Requested workspace inspection and file and log inspection related to source & workspace.

    1 call · #0110–#0110

    find <path> <path> <path> <path> -type <val> -name <val> <flag> <args>sed -n <val>

03 / CANDIDATE ARTIFACT

Text patches & binary names

Read code changes as Git diffs. Identifying strings are masked; binary files are listed by their full relative names.

sglang · 4 changed files

Base commit: 340db9201005fc64635bb25db1d2538f955761c3

diff --git a/python/sglang/srt/hardware_backend/npu/memory_pool_npu.py b/python/sglang/srt/hardware_backend/npu/memory_pool_npu.pyindex a685406f2bffff4efddd8bc093558322e8b45b74..b88debf59f06382dadb5d9ae19b2067580bc639c 100644--- a/python/sglang/srt/hardware_backend/npu/memory_pool_npu.py+++ b/python/sglang/srt/hardware_backend/npu/memory_pool_npu.py@@ -170,6 +170,27 @@ class NPUMHATokenToKVPool(MHATokenToKVPool):             ]         return kv_data_ptrs, kv_data_lens, kv_item_lens +    def get_direct_write_kv_buffers(self, layer_id: int):+        """Return cache storage suitable for a fused per-token NHD write.++        This deliberately excludes FIA and quantized/bitcast cache variants,+        whose physical layouts or write conversions differ from a dense row+        indexed by ``out_cache_loc``.+        """+        if (+            self.use_fia+            or self.kv_cache_layout != "nhd"+            or self.store_dtype != self.dtype+            or self.is_quantized_kv_cache+            or self.head_dim != self.v_head_dim+        ):+            return None++        if self.layer_transfer_counter is not None:+            self.layer_transfer_counter.wait_until(layer_id - self.start_layer)+        local_layer_id = layer_id - self.start_layer+        return self.k_buffer[local_layer_id], self.v_buffer[local_layer_id]+     def set_kv_buffer(         self,         layer: "RadixAttention",diff --git a/python/sglang/srt/models/qwen3.py b/python/sglang/srt/models/qwen3.pyindex 9fbd046709e6d2d557b005f22d8b8586727fcec4..dbbed9fcb3e6df88d3e40d18c68021b0bde66a72 100644--- a/python/sglang/srt/models/qwen3.py+++ b/python/sglang/srt/models/qwen3.py@@ -24,7 +24,11 @@ from sglang.srt.model_executor.cuda_graph_config import (     Phase,     check_cuda_graph_backend, )-from sglang.srt.model_executor.forward_batch_info import ForwardBatch, PPProxyTensors+from sglang.srt.model_executor.forward_batch_info import (+    ForwardBatch,+    ForwardMode,+    PPProxyTensors,+) from sglang.srt.model_executor.forward_context import get_token_to_kv_pool from sglang.srt.model_loader.weight_utils import (     default_weight_loader,@@ -188,6 +192,51 @@ class Qwen3Attention(nn.Module):          if self.attn.layer_id == self.start_layer:             self.rotary_emb.get_cos_sin_with_position(positions)++        cache_kwargs = {}+        if (+            forward_batch.forward_mode == ForwardMode.EXTEND+            and forward_batch.dcp_kv_mask is None+            and get_exec().deterministic.rl_on_policy_target is None+        ):+            token_to_kv_pool = get_token_to_kv_pool()+            get_direct_buffers = getattr(+                token_to_kv_pool, "get_direct_write_kv_buffers", None+            )+            if get_direct_buffers is not None:+                buffers = get_direct_buffers(self.attn.layer_id)+                cache_loc = forward_batch.out_cache_loc+                if buffers is not None:+                    k_cache, v_cache = buffers+                    cache_row_size_matches = (+                        k_cache.shape[-2] * k_cache.shape[-1] == self.kv_size+                        and v_cache.shape[-2] * v_cache.shape[-1] == self.kv_size+                    )+                    cache_storage_matches = (+                        k_cache.dtype == qkv.dtype+                        and v_cache.dtype == qkv.dtype+                        and k_cache.device == qkv.device+                        and v_cache.device == qkv.device+                        and k_cache.is_contiguous()+                        and v_cache.is_contiguous()+                    )+                    cache_loc_matches = (+                        cache_loc.device == qkv.device+                        and cache_loc.dtype in (torch.int32, torch.int64)+                        and cache_loc.is_contiguous()+                        and cache_loc.numel() == qkv.shape[0]+                    )+                    if (+                        cache_row_size_matches+                        and cache_storage_matches+                        and cache_loc_matches+                    ):+                        cache_kwargs = {+                            "k_cache": k_cache,+                            "v_cache": v_cache,+                            "cache_loc": cache_loc,+                        }+         q, k, v = split_qkv_rmsnorm_rope(             qkv,             self.rotary_emb.position_sin,@@ -200,6 +249,7 @@ class Qwen3Attention(nn.Module):             k_weight=self.k_norm.weight,             q_bias=getattr(self.q_norm, "bias", None),             k_bias=getattr(self.k_norm, "bias", None),+            **cache_kwargs,         )         return q, k, v @@ -297,6 +347,9 @@ class Qwen3Attention(nn.Module):                 hidden_states=hidden_states,                 forward_batch=forward_batch,             )+            if k is None:+                assert v is None+                save_kv_cache = False          if get_exec().deterministic.rl_on_policy_target is not None:             q = q.to(torch.bfloat16)diff --git a/sgl-kernel-npu/python/sgl_kernel_npu/sgl_kernel_npu/norm/split_qkv_rmsnorm_rope.py b/sgl-kernel-npu/python/sgl_kernel_npu/sgl_kernel_npu/norm/split_qkv_rmsnorm_rope.pyindex 2b41121ef1893a48688206a8b7594792477e35cc..79adbff279d49221d7c0a6a9d3bcb80c0a44521b 100644--- a/sgl-kernel-npu/python/sgl_kernel_npu/sgl_kernel_npu/norm/split_qkv_rmsnorm_rope.py+++ b/sgl-kernel-npu/python/sgl_kernel_npu/sgl_kernel_npu/norm/split_qkv_rmsnorm_rope.py@@ -13,6 +13,7 @@ def split_qkv_rmsnorm_rope_kernel(     q_ptr,     k_ptr,     v_ptr,+    cache_loc_ptr,     q_weight_ptr,     q_bias_ptr,     k_weight_ptr,@@ -32,6 +33,7 @@ def split_qkv_rmsnorm_rope_kernel(     PASS_DIM: tl.constexpr,     DO_PARTIAL: tl.constexpr,     DO_HALF: tl.constexpr,+    WRITE_KV_CACHE: tl.constexpr, ):     row_pid = tl.program_id(0)     col_pid = tl.program_id(1)@@ -205,6 +207,10 @@ def split_qkv_rmsnorm_rope_kernel(     for row_idx in tl.range(row_pid, batch_size, row_step):         col_indices = col_pid * KV_BLOCK_SIZE + tl.arange(0, KV_BLOCK_SIZE)         valid_mask = col_indices < kv_hidden_size+        if WRITE_KV_CACHE:+            cache_loc = tl.load(cache_loc_ptr + row_idx).to(tl.int32)+            output_offset = cache_loc * kv_hidden_size+            valid_mask = valid_mask & (cache_loc >= 0)         input_values = (             tl.load(input_ptr + input_offset + col_indices, mask=valid_mask, other=0.0)             .to(tl.float32)@@ -352,20 +358,26 @@ def split_qkv_rmsnorm_rope_kernel(             mask=valid_mask,         )         input_offset += input_offset_step-        output_offset += output_offset_step+        if not WRITE_KV_CACHE:+            output_offset += output_offset_step      # v     input_offset = row_pid * total_hidden_size + q_hidden_size + kv_hidden_size     output_offset = row_pid * kv_hidden_size-    for _ in tl.range(row_pid, batch_size, row_step):+    for row_idx in tl.range(row_pid, batch_size, row_step):         col_indices = col_pid * KV_BLOCK_SIZE + tl.arange(0, KV_BLOCK_SIZE)         valid_mask = col_indices < kv_hidden_size+        if WRITE_KV_CACHE:+            cache_loc = tl.load(cache_loc_ptr + row_idx).to(tl.int32)+            output_offset = cache_loc * kv_hidden_size+            valid_mask = valid_mask & (cache_loc >= 0)         input_values = tl.load(             input_ptr + input_offset + col_indices, mask=valid_mask, other=0.0         )         tl.store(v_ptr + output_offset + col_indices, input_values, mask=valid_mask)         input_offset += input_offset_step-        output_offset += output_offset_step+        if not WRITE_KV_CACHE:+            output_offset += output_offset_step   kernels = {}@@ -384,7 +396,17 @@ def split_qkv_rmsnorm_rope(     q_bias=None,     k_bias=None,     is_neox_style=True,+    k_cache=None,+    v_cache=None,+    cache_loc=None, ):+    """Split QKV, normalize Q/K, and apply rotary embeddings.++    When ``k_cache``, ``v_cache``, and ``cache_loc`` are supplied, the kernel+    writes K/V directly to cache rows selected by ``cache_loc``. In that mode+    it returns ``(q, None, None)`` and avoids both temporary K/V tensors and a+    subsequent cache-scatter kernel launch.+    """     _, num_vectorcore = get_device_properties()      KV_BLOCK_SIZE = triton.next_power_of_2(head_dim)@@ -396,12 +418,39 @@ def split_qkv_rmsnorm_rope(     q_output = torch.empty(         batch_size, q_hidden_size, device=input.device, dtype=input.dtype     )-    k_output = torch.empty(-        batch_size, kv_hidden_size, device=input.device, dtype=input.dtype-    )-    v_output = torch.empty(-        batch_size, kv_hidden_size, device=input.device, dtype=input.dtype-    )+    cache_args = (k_cache, v_cache, cache_loc)+    write_kv_cache = all(arg is not None for arg in cache_args)+    if any(arg is not None for arg in cache_args) and not write_kv_cache:+        raise ValueError("k_cache, v_cache, and cache_loc must be provided together")++    if write_kv_cache:+        if not k_cache.is_contiguous() or not v_cache.is_contiguous():+            raise ValueError("K/V cache tensors must be contiguous")+        if k_cache.dtype != input.dtype or v_cache.dtype != input.dtype:+            raise ValueError("K/V cache and input dtypes must match")+        if k_cache.device != input.device or v_cache.device != input.device:+            raise ValueError("K/V cache and input devices must match")+        if cache_loc.device != input.device:+            raise ValueError("cache_loc and input devices must match")+        if cache_loc.dtype not in (torch.int32, torch.int64):+            raise ValueError("cache_loc must have int32 or int64 dtype")+        if not cache_loc.is_contiguous() or cache_loc.numel() != batch_size:+            raise ValueError("cache_loc must be contiguous with one entry per token")+        if k_cache.numel() % kv_hidden_size != 0:+            raise ValueError("K cache rows must have kv_hidden_size elements")+        if v_cache.numel() % kv_hidden_size != 0:+            raise ValueError("V cache rows must have kv_hidden_size elements")+        k_output = k_cache+        v_output = v_cache+    else:+        k_output = torch.empty(+            batch_size, kv_hidden_size, device=input.device, dtype=input.dtype+        )+        v_output = torch.empty(+            batch_size, kv_hidden_size, device=input.device, dtype=input.dtype+        )+        # The pointer is unused in the compile-time-disabled branch.+        cache_loc = input     n_cols = kv_hidden_size // KV_BLOCK_SIZE     n_rows = (num_vectorcore + n_cols - 1) // n_cols     BIAS = q_bias is not None@@ -414,6 +463,7 @@ def split_qkv_rmsnorm_rope(         q_output,         k_output,         v_output,+        cache_loc,         q_weight,         q_bias,         k_weight,@@ -433,8 +483,11 @@ def split_qkv_rmsnorm_rope(         head_dim - rope_dim,         DO_PARTIAL=(head_dim != rope_dim),         DO_HALF=is_neox_style,+        WRITE_KV_CACHE=write_kv_cache,     ) +    if write_kv_cache:+        return q_output, None, None     return q_output, k_output, v_output  diff --git a/sgl-kernel-npu/tests/python/sgl_kernel_npu/test_split_qkv_rmsnorm_rope.py b/sgl-kernel-npu/tests/python/sgl_kernel_npu/test_split_qkv_rmsnorm_rope.pyindex f923d4e339442e6dae44b715c6db9cee3a08386a..ca51fc986c89f89bf9fa0eb19776094cc33ea1ae 100644--- a/sgl-kernel-npu/tests/python/sgl_kernel_npu/test_split_qkv_rmsnorm_rope.py+++ b/sgl-kernel-npu/tests/python/sgl_kernel_npu/test_split_qkv_rmsnorm_rope.py@@ -135,6 +135,67 @@ def test_split_qkv_rmsnorm_rope():     )  +def test_split_qkv_rmsnorm_rope_direct_cache_write():+    q_hidden_size = 2048+    kv_hidden_size = 1024+    head_dim = 128+    bsz = 7+    eps = 1e-6++    qkv = torch.randn(+        bsz, q_hidden_size + kv_hidden_size * 2, dtype=torch.bfloat16, device="npu"+    )+    q_weight = torch.randn(head_dim, dtype=torch.bfloat16, device="npu")+    k_weight = torch.randn(head_dim, dtype=torch.bfloat16, device="npu")+    sin = torch.randn(bsz, 1, 1, head_dim, dtype=torch.bfloat16, device="npu")+    cos = torch.randn(bsz, 1, 1, head_dim, dtype=torch.bfloat16, device="npu")++    expected_q, expected_k, expected_v = split_qkv_rmsnorm_rope(+        qkv,+        sin,+        cos,+        q_hidden_size,+        kv_hidden_size,+        head_dim,+        eps=eps,+        q_weight=q_weight,+        k_weight=k_weight,+    )++    cache_rows = 32+    cache_loc = torch.tensor(+        [17, 2, 31, 8, 5, 22, 1], dtype=torch.int64, device="npu"+    )+    k_cache = torch.full(+        (cache_rows, kv_hidden_size), 11, dtype=torch.bfloat16, device="npu"+    )+    v_cache = torch.full(+        (cache_rows, kv_hidden_size), 13, dtype=torch.bfloat16, device="npu"+    )+    q, k, v = split_qkv_rmsnorm_rope(+        qkv,+        sin,+        cos,+        q_hidden_size,+        kv_hidden_size,+        head_dim,+        eps=eps,+        q_weight=q_weight,+        k_weight=k_weight,+        k_cache=k_cache,+        v_cache=v_cache,+        cache_loc=cache_loc,+    )++    assert k is None+    assert v is None+    assert torch.equal(q, expected_q)+    assert torch.equal(k_cache[cache_loc], expected_k)+    assert torch.equal(v_cache[cache_loc], expected_v)+    assert torch.all(k_cache[0] == 11)+    assert torch.all(v_cache[0] == 13)++ def test_split_qkv_rope():     q_hidden_size = 6144     kv_hidden_size = 1024