GPT-6 Astra · Serving

S03 · TTFT

Valid

Online TTFT 1dev · Implementation Optimization

1.36×PERFORMANCE RATIO
248TOOL 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-6 Astra · 248 visible calls

InspectEditValidateExecuteBuildProfileRollbackOther
115Inspect
18Edit
7Build
55Validate
31Execute
9Profile
13Other

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 timeline206 groups · 248 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 file and log inspection related to task requirements.

    1 call · #0001–#0001

    <command> <args>cat <path>printf <val> <path>
  2. Inspect · Source & workspace

    Requested workspace inspection, environment setup or inspection and repository inspection related to source & workspace.

    1 call · #0002–#0002

    pwdprintenv <vars>git status --short
  3. Inspect · Benchmark & validation setup

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

    1 call · #0003–#0003

    cat <path> <path> <path> <path> <path> <path>
  4. Inspect · Task requirements

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

    1 call · #0004–#0004

    rg --files -g <val> -g <val> <path> <val>ls -l -a <val>cat <path>
  5. Validate · Task requirements

    1 tool error

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

    1 call · #0005–#0005

    ls -l -h <path>cat <path>python - <script>bash <script>
  6. Inspect · Benchmark & validation setup

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

    1 call · #0006–#0006

    rg -n <val> <path>head -n <n>printenv <vars>rg --files <path> <val>rg <val>
  7. Inspect · Task requirements

    Requested file and log inspection related to task requirements.

    1 call · #0007–#0007

    cat <path>cat <path> <path> <path> <path> <path>cat <path> <path>
  8. Inspect · Source & workspace

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

    1 call · #0008–#0008

    cat <path>rg --files <path>rg <val>
  9. Execute · Attention kernels

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

    1 call · #0009–#0009

    sed -n <val> <path>rg -n <val> <path>tail -n <n>python - <script>
  10. Other · Source & workspace

    Requested environment setup or inspection related to source & workspace.

    1 call · #0010–#0010

    env <vars> bash <script>
  11. Inspect · Source & workspace

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

    3 calls · #0011–#0013

    sed -n <val> <path>python - <script>cat <val>rg -n <val> <path>tail -n <n> <path>
  12. Inspect · Attention kernels

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

    3 calls · #0014–#0016

    sed -n <val> <path>rg -n <val> <path>cat <path>rg -n <val> <path> <path> <path>tail -n <n> <path>
  13. Inspect · Benchmark & validation setup

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

    1 call · #0017–#0017

    tail -n <n> <path>ls -l -h <path>sed -n <val> <path>
  14. Inspect · Batching & scheduling

    Requested file and log inspection and source searches related to batching & scheduling.

    1 call · #0018–#0018

    sed -n <val> <path>rg -n <val> <path>head -n <n>
  15. Inspect · Attention kernels

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

    2 calls · #0019–#0020

    ps <flag> <args>rg <val>head -n <n>tail -n <n> <path>sed -n <val> <path>rg -n <val> <path>
    1 more command sketches
    rg --files <path>
  16. Inspect · Batching & scheduling

    Requested file and log inspection and source searches related to batching & scheduling.

    1 call · #0021–#0021

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

    Requested file and log inspection related to device memory.

    1 call · #0022–#0022

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

    Requested file and log inspection related to attention kernels.

    1 call · #0023–#0023

    tail -n <n> <path>cut <flag>sed -n <val> <path>
  19. Inspect · Benchmark & validation setup

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

    1 call · #0024–#0024

    rg -n <val> <path>tail -n <n>tail -n <n> <path>cut <flag>sed -n <val> <path>
  20. Inspect · Attention kernels

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

    2 calls · #0025–#0026

    sed -n <val> <path>rg --files <path>rg <val>tail -n <n> <path>cut <flag>
  21. Validate · Benchmark & validation setup

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

    1 call · #0027–#0027

    tail -n <n> <path>cut <flag>ls -l <path> <n> > <path>sed -n <val> <path>cat <path>head -n <n>
  22. Inspect · Attention kernels

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

    1 call · #0028–#0028

    rg -n <val> <path>head -n <n>tail -n <n> <path>cut <flag>
  23. Execute · Attention kernels

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

    1 call · #0029–#0029

    python - <script>sed -n <val> <path>
  24. Profile · Benchmark & validation setup

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

    1 call · #0030–#0030

    cat > <path> <script>
  25. Profile · Task requirements

    Requested workspace file updates and environment setup or inspection related to task requirements.

    1 call · #0031–#0031

    mkdir -p <path>env <vars> python - <script>
  26. Inspect · Benchmark & validation setup

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

    1 call · #0032–#0032

    tail -n <n> <path>cut <flag>
  27. Inspect · Attention kernels

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

    1 call · #0033–#0033

    tail -n <n> <path>cut <flag>ls -l -h <path>rg -n <val> <path>sed -n <val> <path>
  28. Edit · Attention kernels

    Requested code edits related to attention kernels.

    1 call · #0034–#0034

    Apply patch <patch>
  29. Execute · Benchmark & validation setup

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

    1 call · #0035–#0035

    rg -n <val> <path> <path> <n> > <path>head -n <n>tail -n <n> <path>cut <flag>rg -n <val> <path>
  30. Inspect · Attention kernels

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

    1 call · #0036–#0036

    sed -n <val> <path>git status --short
  31. Execute · Attention kernels

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

    1 call · #0037–#0037

    cat > <path> <script>ls -l -h <path>tail -n <n>
  32. Inspect · Attention kernels

    Requested file and log inspection related to attention kernels.

    1 call · #0038–#0038

    sed -n <val> <path>
  33. Execute · Latency & request handling

    Requested script or workload execution related to latency & request handling.

    1 call · #0039–#0039

    python - <script>
  34. Execute · Benchmark & validation setup

    Requested script or workload execution and file and log inspection related to benchmark & validation setup.

    1 call · #0040–#0040

    python - <script>tail -n <n> <path>cut <flag>
  35. Inspect · Source & workspace

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

    1 call · #0041–#0041

    rg -n <val> <path>tail -n <n>sed -n <val> <path>
  36. Execute · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0042–#0042

    python - <script>
  37. Inspect · Device memory

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

    1 call · #0043–#0043

    sed -n <val> <path>rg -n <val> <path>
  38. Execute · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    2 calls · #0044–#0045

    python - <script>
  39. Validate · Task requirements

    1 tool error

    Requested workspace file updates and environment setup or inspection related to task requirements.

    1 call · #0046–#0046

    mkdir -p <path>env <vars> python <script> <val> > <path> <n> >& <path>
  40. Inspect · Benchmark & validation setup

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

    1 call · #0047–#0047

    tail -n <n> <path>cut <flag>rg -n <val> <path> <path> <path>
  41. Inspect · Source & workspace

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

    4 calls · #0048–#0051

    tail -n <n> <path>rg -n <val> <path> <path>head -n <n>sed -n <val> <path>rg -n <val> <path>
  42. Inspect · Runtime processes

    Requested source searches, file and log inspection and runtime inspection related to runtime processes.

    1 call · #0052–#0052

    rg -n <val> <path> <path> <path>head -n <n>pgrep <flag> <args>tail -n <n> <path>
  43. Validate · Benchmark & validation setup

    1 tool error

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0053–#0053

    python - <script>python <script> > <path> <n> >& <path>
  44. Other · Source & workspace

    1 tool error

    Requested process termination related to source & workspace.

    1 call · #0054–#0054

    kill <flag> <args>
  45. Edit · Attention kernels

    Requested code edits related to attention kernels.

    1 call · #0055–#0055

    Apply patch <patch>
  46. Inspect · Source & workspace

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

    1 call · #0056–#0056

    tail -n <n> <path>sed -n <val> <path>rg -n <val> <path>head -n <n>git status --short
  47. Inspect · Benchmark & validation setup

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

    1 call · #0057–#0057

    tail -n <n> <path>cut <flag>sed -n <val> <path>
  48. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0058–#0058

    cat > <path> <script>
  49. Inspect · Benchmark & validation setup

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

    1 call · #0059–#0059

    tail -n <n> <path>cut <flag>ls -l -h <path>
  50. Inspect · Attention kernels

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

    2 calls · #0060–#0061

    sed -n <val> <path>rg -n <val> <path>tail -n <n> <path>cut <flag>rg --files <val> <path>rg <val>
    1 more command sketches
    head -n <n>
  51. Profile · Benchmark & validation setup

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

    1 call · #0062–#0062

    tail -n <n> <path>cut <flag>rg --files <path> <n> > <path>head -n <n>
  52. Profile · Rollout generation

    Requested file and log inspection, workspace file updates and environment setup or inspection related to rollout generation.

    1 call · #0063–#0063

    cat > <path> <script>mkdir -p <path>env <vars> python <script> > <path> <n> >& <path>
  53. Profile · Source & workspace

    Requested script or workload execution related to source & workspace.

    1 call · #0064–#0064

    python - <script>
  54. Validate · Task requirements

    Requested workspace file updates and environment setup or inspection related to task requirements.

    1 call · #0065–#0065

    mkdir -p <path>env <vars> bash <script> > <path> <n> >& <path>
  55. Profile · Data movement

    Requested script or workload execution and file and log inspection related to data movement.

    1 call · #0066–#0066

    python - <script>tail -n <n> <path>cut <flag>
  56. Profile · Benchmark & validation setup

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

    1 call · #0067–#0067

    tail -n <n> <path>ls -l <path>rg -n <val> <path> <n> > <path>head -n <n>ls <path>
  57. Other · Source & workspace

    Requested script or workload execution related to source & workspace.

    1 call · #0068–#0068

    python <script> > <path> <n> >& <path>
  58. Inspect · Attention kernels

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

    1 call · #0069–#0069

    command -v <val>rg -n <val> <path> <path> <path>head -n <n>sed -n <val> <path>
  59. Profile · Batching & scheduling

    Requested script or workload execution related to batching & scheduling.

    1 call · #0070–#0070

    python - <script>
  60. Inspect · Source & workspace

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

    1 call · #0071–#0071

    cat <path>rg -n <val> <path>head -n <n>sed -n <val> <path>
  61. Inspect · Batching & scheduling

    Requested source searches and file and log inspection related to batching & scheduling.

    1 call · #0072–#0072

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

    Requested code edits related to attention kernels.

    1 call · #0073–#0073

    Apply patch <patch>
  63. Validate · Benchmark & validation setup

    Requested repository inspection, file and log inspection and script or workload execution related to benchmark & validation setup.

    1 call · #0074–#0074

    git diff --stattail -n <n> <path>cut <flag>cat <path>python -c <script>rg -n <val> <path>
    2 more command sketches
    head -n <n>sed -n <val> <path>
  64. Validate · Batching & scheduling

    Requested script or workload execution related to batching & scheduling.

    1 call · #0075–#0075

    python - <script>
  65. Validate · Attention kernels

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

    1 call · #0076–#0076

    git diff --checkpython - <script>mkdir -p <path>env <vars> python <script> <val> > <path> <n> >& <path>
  66. Edit · Attention kernels

    Requested code edits related to attention kernels.

    1 call · #0077–#0077

    Apply patch <patch>
  67. Validate · Benchmark & validation setup

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

    2 calls · #0078–#0079

    tail -n <n> <path>cut <flag>ls -l <path> <n> > <path>git diff --checkpython - <script>
  68. Inspect · Attention kernels

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

    2 calls · #0080–#0081

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

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

    1 call · #0082–#0082

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

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

    1 call · #0083–#0083

    rg -n <val> <path>sed -n <val> <path>
  71. Inspect · Batching & scheduling

    Requested file and log inspection and source searches related to batching & scheduling.

    1 call · #0084–#0084

    sed -n <val> <path>rg -n <val> <path>head -n <n>
  72. Inspect · Attention kernels

    Requested file and log inspection related to attention kernels.

    1 call · #0085–#0085

    sed -n <val> <path>
  73. Validate · Attention kernels

    Requested script or workload execution related to attention kernels.

    1 call · #0086–#0086

    python -m <module> -q <script> > <path> <n> >& <path>
  74. Edit · Attention kernels

    Requested code edits related to attention kernels.

    1 call · #0087–#0087

    Apply patch <patch>
  75. Inspect · Attention kernels

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

    2 calls · #0088–#0089

    cat > <path> <script>tail -n <n> <path>rg -n <val> <path>sed -n <val> <path>git diff --statgit diff --check
  76. Other · KV-cache management

    Requested script or workload execution related to kv-cache management.

    1 call · #0090–#0090

    python <script> > <path> <n> >& <path>
  77. Edit · Attention kernels

    Requested code edits related to attention kernels.

    1 call · #0091–#0091

    Apply patch <patch>
  78. Inspect · KV-cache management

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

    1 call · #0092–#0092

    tail -n <n> <path>git diff --check
  79. Inspect · Runtime processes

    1 tool error

    Requested script or workload execution related to runtime processes.

    1 call · #0093–#0093

    python - <script>
  80. Edit · Attention kernels

    Requested code edits related to attention kernels.

    1 call · #0094–#0094

    Apply patch <patch>
  81. Inspect · Benchmark & validation setup

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

    1 call · #0095–#0095

    sed -n <val> <path>ls -l -h <path>tail -n <n> <path>cut <flag>git diff --check
  82. Inspect · Source & workspace

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

    1 call · #0096–#0096

    rg -l -a -F <val> <path> <path> <n> > <path>head -n <n>
  83. Inspect · Attention kernels

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

    1 call · #0097–#0097

    cat <path>head -n <n>rg -n <val> <path>sed -n <val> <path>
  84. Inspect · Parallelism & communication

    Requested source searches, file and log inspection and script or workload execution related to parallelism & communication.

    1 call · #0098–#0098

    rg -L -l -a -F <val> <path> <path> <path> <n> > <path>head -n <n>python - <script>
  85. Validate · Benchmark & validation setup

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

    1 call · #0099–#0099

    <command> <args>rg -n -C <n> -e <val> -e <val>rg -n <val> <path>head -n <n>tail -n <n> <path>cut <flag>
  86. Inspect · Runtime processes

    Requested source searches, file and log inspection and script or workload execution related to runtime processes.

    1 call · #0100–#0100

    rg -L -l -a -e <val> -e <val> <path> <path> <path> <path> <args>head -n <n>python - <script>
  87. Inspect · Source & workspace

    1 tool error

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

    1 call · #0101–#0101

    <command> <args>rg -e <val> -e <val> -e <val>head -n <n>sed -n <val> <path>ls <path> <n> > <path>
  88. Inspect · Benchmark & validation setup

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

    1 call · #0102–#0102

    tail -n <n> <path>cut <flag>
  89. Validate · Task requirements

    Requested workspace file updates and environment setup or inspection related to task requirements.

    1 call · #0103–#0103

    mkdir -p <path>env <vars> python <script> <val> > <path> <n> >& <path>
  90. Validate · Benchmark & validation setup

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

    1 call · #0104–#0104

    tail -n <n> <path>ls -l <path> <n> > <path>
  91. Other · Runtime processes

    Requested script or workload execution related to runtime processes.

    1 call · #0105–#0105

    python - <script>
  92. Build · KV-cache management

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

    1 call · #0106–#0106

    <command> <args>rg -n -C <n> -e <val> -e <val> -e <path> -e <path>tail -n <n> <path>du <flag> <args>
  93. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0107–#0107

    Apply patch <patch>
  94. Inspect · KV-cache management

    Requested file and log inspection, repository inspection and workspace inspection related to kv-cache management.

    2 calls · #0108–#0109

    tail -n <n> <path>git diff --checkgit status --shortls -l -h <val>git diff --numstatsed -n <val> <path>
  95. Validate · Attention kernels

    1 tool error

    Requested environment setup or inspection related to attention kernels.

    1 call · #0110–#0110

    env <vars> python -m <module> -q <script> <script> > <path> <n> >& <path>
  96. Inspect · KV-cache management

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

    1 call · #0111–#0111

    tail -n <n> <path>
  97. Inspect · Attention kernels

    Requested file and log inspection related to attention kernels.

    1 call · #0112–#0112

    sed -n <val> <path>
  98. Edit · Attention kernels

    Requested code edits related to attention kernels.

    1 call · #0113–#0113

    Apply patch <patch>
  99. Inspect · Benchmark & validation setup

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

    1 call · #0114–#0114

    git diff --checkgit status --shorttail -n <n> <path>cut <flag>
  100. Build · Runtime processes

    Requested script or workload execution related to runtime processes.

    1 call · #0115–#0115

    python - <script>
  101. Inspect · Batching & scheduling

    Requested source searches and file and log inspection related to batching & scheduling.

    1 call · #0116–#0116

    rg -n <val> <path> <path> <path>head -n <n>sed -n <val> <path>rg -n <val> <path> -g <path>
  102. Other · Source & workspace

    Requested script or workload execution related to source & workspace.

    1 call · #0117–#0117

    python - <script>
  103. Inspect · Batching & scheduling

    Requested source searches and file and log inspection related to batching & scheduling.

    1 call · #0118–#0118

    rg -n <val> <path>head -n <n>sed -n <val> <path>tail -n <n> <path>cut <flag>
  104. Inspect · Attention kernels

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

    1 call · #0119–#0119

    tail -n <n> <path>cut <flag>sed -n <val> <path>rg -n <val> <path>head -n <n>git diff --check
  105. Execute · Benchmark & validation setup

    Requested script or workload execution and file and log inspection related to benchmark & validation setup.

    1 call · #0120–#0120

    python - <script>tail -n <n> <path>cut <flag>
  106. Execute · Task requirements

    Requested workspace file updates and environment setup or inspection related to task requirements.

    1 call · #0121–#0121

    mkdir -p <path>env <vars> bash <script> > <path> <n> >& <path>
  107. Execute · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0122–#0122

    python - <script>
  108. Inspect · Source & workspace

    Requested repository inspection related to source & workspace.

    1 call · #0123–#0123

    git status --short
  109. Inspect · Task requirements

    Requested file and log inspection related to task requirements.

    1 call · #0124–#0124

    sed -n <val> <path>cat <path>
  110. Execute · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0125–#0125

    python - <script>
  111. Inspect · Batching & scheduling

    1 tool error

    Requested file and log inspection and source searches related to batching & scheduling.

    1 call · #0126–#0126

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

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0127–#0127

    python - <script>
  113. Inspect · Attention kernels

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

    2 calls · #0128–#0129

    sed -n <val> <path>rg -n <val> <path>head -n <n>rg -n <val> <path> <path>
  114. Validate · Attention kernels

    Requested environment setup or inspection related to attention kernels.

    1 call · #0130–#0130

    env <vars> python -m <module> -q <script> <script> > <path> <n> >& <path>
  115. Inspect · Batching & scheduling

    Requested file and log inspection and source searches related to batching & scheduling.

    3 calls · #0131–#0133

    tail -n <n> <path>rg -n <val> <path>sed -n <val> <path>rg -n <val> <path> <val>head -n <n>
  116. Edit · Batching & scheduling

    Requested code edits related to batching & scheduling.

    1 call · #0134–#0134

    Apply patch <patch>
  117. Inspect · Attention kernels

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

    2 calls · #0135–#0136

    git diff --statsed -n <val> <path>git diff <flag> <args>rg -n <val> <path>
  118. Validate · Batching & scheduling

    Requested file and log inspection, source searches and script or workload execution related to batching & scheduling.

    1 call · #0137–#0137

    tail -n <n> <path>rg --files -g <val> -g <val> -g <path> -g <val>head -n <n>python - <script>
  119. Inspect · Attention kernels

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

    1 call · #0138–#0138

    sed -n <val> <path>rg -n <val> <path>tail -n <n>cat <path>
  120. Validate · Batching & scheduling

    Requested environment setup or inspection related to batching & scheduling.

    1 call · #0139–#0139

    env <vars> python -m <module> -q <script> <script> > <path> <n> >& <path>
  121. Inspect · Batching & scheduling

    Requested file and log inspection related to batching & scheduling.

    1 call · #0140–#0140

    tail -n <n> <path>
  122. Inspect · Speculative decoding

    Requested source searches and file and log inspection related to speculative decoding.

    1 call · #0141–#0141

    rg --files <path>head -n <n>rg -n <val> <path> <path> <path> <path>sed -n <val> <path>
  123. Inspect · Device memory

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

    1 call · #0142–#0142

    tail -n <n> <path>cat <path>rg -n <val> <path>tail -n <n>head -n <n>
  124. Inspect · Attention kernels

    Requested file and log inspection related to attention kernels.

    1 call · #0143–#0143

    sed -n <val> <path>
  125. Inspect · Device memory

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

    1 call · #0144–#0144

    tail -n <n> <path>sed -n <val> <path>rg -n <val> <path>
  126. Validate · Batching & scheduling

    Requested workspace file updates and environment setup or inspection related to batching & scheduling.

    1 call · #0145–#0145

    mkdir -p <path>env <vars> python <script> <val> > <path> <n> >& <path>
  127. Inspect · Batching & scheduling

    Requested source searches and file and log inspection related to batching & scheduling.

    1 call · #0146–#0146

    rg -n <val> <path>head -n <n>rg -n <val> <path> <path>sed -n <val> <path>tail -n <n> <path>
  128. Validate · Batching & scheduling

    Requested script or workload execution related to batching & scheduling.

    1 call · #0147–#0147

    python - <script>
  129. Inspect · Source & workspace

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

    1 call · #0148–#0148

    rg --files <val> -g <val> -g <val> -g <val> -g <val>head -n <n>sed -n <val> <path>
  130. Inspect · Batching & scheduling

    Requested file and log inspection and source searches related to batching & scheduling.

    1 call · #0149–#0149

    tail -n <n> <path>rg -n <val> <path> <path>head -n <n>
  131. Inspect · Runtime processes

    Requested repository inspection and script or workload execution related to runtime processes.

    1 call · #0150–#0150

    git diff --checkpython - <script>
  132. Execute · Batching & scheduling

    Requested script or workload execution related to batching & scheduling.

    2 calls · #0151–#0152

    python - <script>
  133. Inspect · Attention kernels

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

    1 call · #0153–#0153

    sed -n <val> <path>rg -n <val> <path> <path>head -n <n>
  134. Execute · Batching & scheduling

    Requested script or workload execution, workspace file updates and environment setup or inspection related to batching & scheduling.

    4 calls · #0154–#0157

    python - <script>mkdir -p <path>env <vars> bash <script> > <path> <n> >& <path>
  135. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0158–#0158

    Apply patch <patch>
  136. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0159–#0159

    sed -n <val> <path>
  137. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0160–#0160

    Apply patch <patch>
  138. Validate · Batching & scheduling

    Requested script or workload execution related to batching & scheduling.

    1 call · #0161–#0161

    python - <script>
  139. Inspect · Benchmark & validation setup

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

    1 call · #0162–#0162

    tail -n <n> <path>
  140. Inspect · Device memory

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

    1 call · #0163–#0163

    rg -n <val> <path> <path> <path>head -n <n>sed -n <val> <path>
  141. Validate · Benchmark & validation setup

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

    3 calls · #0164–#0166

    env <vars> python -m <module> -q <script> > <path> <n> >& <path>tail -n <n> <path>python - <script>
  142. Validate · Task requirements

    Requested workspace file updates and environment setup or inspection related to task requirements.

    1 call · #0167–#0167

    mkdir -p <path>env <vars> python <script> <val> > <path> <n> >& <path>
  143. Inspect · Batching & scheduling

    Requested source searches and file and log inspection related to batching & scheduling.

    1 call · #0168–#0168

    rg -n <val> <path>head -n <n>sed -n <val> <path>
  144. Validate · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0169–#0169

    python - <script>
  145. Inspect · Attention kernels

    Requested file and log inspection related to attention kernels.

    1 call · #0170–#0170

    sed -n <val> <path>
  146. Execute · Benchmark & validation setup

    Requested script or workload execution and file and log inspection related to benchmark & validation setup.

    3 calls · #0171–#0173

    python - <script>sed -n <val> <path>
  147. Validate · Task requirements

    Requested file and log inspection, workspace file updates and environment setup or inspection related to task requirements.

    1 call · #0174–#0174

    cat <path>mkdir -p <path>env <vars> bash <script> > <path> <n> >& <path>
  148. Execute · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0175–#0175

    python - <script>
  149. Inspect · Source & workspace

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

    1 call · #0176–#0176

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

    Requested code edits related to attention kernels.

    1 call · #0177–#0177

    Apply patch <patch>
  151. Inspect · Device memory

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

    2 calls · #0178–#0179

    rg -n <val> <path>sed -n <val> <path>tail -n <n>
  152. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0180–#0180

    Apply patch <patch>
  153. Inspect · Device memory

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

    1 call · #0181–#0181

    rg -n <val> <path>head -n <n>
  154. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0182–#0182

    Apply patch <patch>
  155. Validate · Benchmark & validation setup

    1 tool error

    Requested environment setup or inspection related to benchmark & validation setup.

    1 call · #0183–#0183

    env <vars> python -m <module> -q <script> > <path> <n> >& <path>
  156. Build · Attention kernels

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

    1 call · #0184–#0184

    python - <script>env <vars> bash <script> > <path> <n> >& <path>
  157. Inspect · Device memory

    Requested file and log inspection related to device memory.

    1 call · #0185–#0185

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

    Requested file and log inspection related to source & workspace.

    1 call · #0186–#0186

    sed -n <val> <path>
  159. Validate · Attention kernels

    Requested script or workload execution related to attention kernels.

    1 call · #0187–#0187

    python - <script>
  160. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    2 calls · #0188–#0189

    tail -n <n> <path>
  161. Validate · Attention kernels

    Requested environment setup or inspection related to attention kernels.

    1 call · #0190–#0190

    env <vars> python -m <module> -q <script> <script> <script> <script> > <path> <args>
  162. Inspect · KV-cache management

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

    1 call · #0191–#0191

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

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

    1 call · #0192–#0192

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

    Requested file and log inspection related to batching & scheduling.

    1 call · #0193–#0193

    sed -n <val> <path>
  165. Inspect · Device memory

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

    1 call · #0194–#0194

    sed -n <val> <path>rg -n <val> <path>head -n <n>rg -n <val> <path> <path>
  166. Validate · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0195–#0195

    python - <script>
  167. Validate · Task requirements

    Requested workspace file updates and environment setup or inspection related to task requirements.

    1 call · #0196–#0196

    mkdir -p <path>env <vars> python <script> <val> > <path> <n> >& <path>
  168. Edit · Device memory

    Requested code edits related to device memory.

    1 call · #0197–#0197

    Apply patch <patch>
  169. Validate · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0198–#0198

    python - <script>
  170. Inspect · KV-cache management

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

    1 call · #0199–#0199

    rg -n <val> <path> <val>head -n <n>rg -n <val> <path>sed -n <val> <path>
  171. Validate · Batching & scheduling

    Requested environment setup or inspection related to batching & scheduling.

    1 call · #0200–#0200

    env <vars> python -m <module> -q <script> <script> <script> <script> > <path> <args>
  172. Validate · Benchmark & validation setup

    Requested file and log inspection and script or workload execution related to benchmark & validation setup.

    1 call · #0201–#0201

    tail -n <n> <path>python - <script>
  173. Validate · Task requirements

    Requested workspace file updates and environment setup or inspection related to task requirements.

    1 call · #0202–#0202

    mkdir -p <path>env <vars> python <script> <val> > <path> <n> >& <path>
  174. Validate · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0203–#0203

    python - <script>
  175. Edit · Batching & scheduling

    Requested code edits related to batching & scheduling.

    1 call · #0204–#0204

    Apply patch <patch>
  176. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0205–#0205

    cat <path>
  177. Execute · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    4 calls · #0206–#0209

    python - <script>
  178. Execute · Task requirements

    Requested workspace file updates and environment setup or inspection related to task requirements.

    1 call · #0210–#0210

    mkdir -p <path>env <vars> bash <script> > <path> <n> >& <path>
  179. Execute · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0211–#0211

    python - <script>
  180. Inspect · Device memory

    Requested repository inspection and file and log inspection related to device memory.

    1 call · #0212–#0212

    git diff --statsed -n <val> <path>
  181. Validate · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0213–#0213

    python - <script>
  182. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0214–#0214

    Apply patch <patch>
  183. Profile · Benchmark & validation setup

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

    1 call · #0215–#0215

    cat > <path> <script>
  184. Validate · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0216–#0216

    python - <script>
  185. Validate · Task requirements

    Requested workspace file updates and environment setup or inspection related to task requirements.

    1 call · #0217–#0217

    mkdir -p <path>env <vars> python <script> <val> > <path> <n> >& <path>
  186. Execute · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0218–#0218

    python - <script>
  187. Build · Attention kernels

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

    1 call · #0219–#0219

    python - <script>env <vars> bash <script> > <path> <n> >& <path>
  188. Build · Runtime processes

    Requested repository inspection, script or workload execution and file and log inspection related to runtime processes.

    1 call · #0220–#0220

    git diff --checkpython - <script>tail -n <n> <path>
  189. Validate · Batching & scheduling

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

    3 calls · #0221–#0223

    python - <script>env <vars> python -m <module> -q <script> <script> > <path> <n> >& <path>tail -n <n> <path>
  190. Validate · Benchmark & validation setup

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

    2 calls · #0224–#0225

    mkdir -p <path>env -u <val> <vars> <val> <path> > <path> <n> >& <path>python - <script>
  191. Inspect · Benchmark & validation setup

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

    2 calls · #0226–#0227

    rg -n <val> <path>tail -n <n>sed -n <val> <path>head -n <n>
  192. Validate · Task requirements

    Requested workspace file updates and environment setup or inspection related to task requirements.

    1 call · #0228–#0228

    mkdir -p <path>env <vars> bash <script> > <path> <n> >& <path>
  193. Validate · Benchmark & validation setup

    1 tool error

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

    3 calls · #0229–#0231

    mkdir -p <path>env -u <val> <vars> <val> <path> > <path> <n> >& <path>python - <script>tail -n <n> <path>
  194. Other · Benchmark & validation setup

    Requested script or workload execution and repository inspection related to benchmark & validation setup.

    1 call · #0232–#0232

    python -B - <script>git status --short
  195. Validate · Benchmark & validation setup

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

    2 calls · #0233–#0234

    python - <script>mkdir -p <path>env -u <val> <vars> <val> <path> > <path> <n> >& <path>
  196. Inspect · Task requirements

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

    1 call · #0235–#0235

    python -B - <script>git diff --check
  197. Validate · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0236–#0236

    python -B - <script>
  198. Other · Source & workspace

    Requested script or workload execution related to source & workspace.

    1 call · #0237–#0237

    python -B - <script>
  199. Validate · Task requirements

    Requested environment setup or inspection related to task requirements.

    1 call · #0238–#0238

    env <vars> python <script> <val> > <path> <n> >& <path>
  200. Execute · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0239–#0239

    python -B - <script>
  201. Other · Source & workspace

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

    1 call · #0240–#0240

    bash <script> > <path> <n> >& <path>cat <path>
  202. Other · Runtime processes

    Requested repository inspection and script or workload execution related to runtime processes.

    1 call · #0241–#0241

    git <val> <val> <flag>python -B - <script>
  203. Other · Device memory

    1 tool error

    Requested runtime inspection and script or workload execution related to device memory.

    3 calls · #0242–#0244

    npu-smi info -t <val> -i <n>npu-smi info -t <val> -i <n> -c <n>python -B - <script>npu-smi info
  204. Inspect · Benchmark & validation setup

    Requested source searches and script or workload execution related to benchmark & validation setup.

    1 call · #0245–#0245

    rg --files --hidden --no-ignore -g <val> <path> <path> <val>python -B - <script>
  205. Build · Benchmark & validation setup

    1 tool error

    Requested script or workload execution related to benchmark & validation setup.

    2 calls · #0246–#0247

    python -B - <script>
  206. Validate · Benchmark & validation setup

    Requested script or workload execution and repository inspection related to benchmark & validation setup.

    1 call · #0248–#0248

    python -B - <script>git diff --checkgit status --short

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 · 14 changed files

Base commit: 340db9201005fc64635bb25db1d2538f955761c3

diff --git a/python/sglang/srt/hardware_backend/npu/attention/ascend_backend.py b/python/sglang/srt/hardware_backend/npu/attention/ascend_backend.pyindex 89e9de06db1cb0350cb55b83dbaffc15c100fff9..490150ee2cc7a15765d43745fa26555f720e81cd 100644--- a/python/sglang/srt/hardware_backend/npu/attention/ascend_backend.py+++ b/python/sglang/srt/hardware_backend/npu/attention/ascend_backend.py@@ -380,6 +380,11 @@ class AscendAttnBackend(AttentionBackend):             self.dllm_block_size = self.dllm_config.block_size          self.attn_cp_size = model_runner.ps.attn_cp_size+        # The non-FIA MHA path reads K/V exclusively from the paged cache.+        # Models may therefore fuse the cache write into their QKV preparation.+        self.supports_fused_qkv_cache = (+            not self.use_fia and not self.use_mla and self.attn_cp_size == 1+        )      def _is_swa_layer(self, layer: RadixAttention) -> bool:         return (@@ -430,7 +435,9 @@ class AscendAttnBackend(AttentionBackend):     def init_forward_metadata(self, forward_batch: ForwardBatch):         """Init the metadata for a forward pass."""         self.forward_metadata = ForwardMetadata()-        seq_lens_max = forward_batch.seq_lens.max()+        # The scheduler already keeps sequence lengths on the host. Using a+        # device scalar as a slice bound would synchronize the forward stream.+        seq_lens_max = int(forward_batch.seq_lens_cpu.max())         if forward_batch.forward_mode.is_target_verify():             seq_lens_max += self.speculative_num_draft_tokens         elif (@@ -440,8 +447,8 @@ class AscendAttnBackend(AttentionBackend):             seq_lens_max += self.speculative_step_id + 1         self.forward_metadata.block_tables = (             self.req_to_token_pool.req_to_token[-                forward_batch.req_pool_indices, :seq_lens_max-            ][:, :: self.page_size]+                forward_batch.req_pool_indices, :seq_lens_max : self.page_size+            ]             // self.page_size         )         if self.is_hybrid_swa:@@ -449,9 +456,10 @@ class AscendAttnBackend(AttentionBackend):                 (                     self.full_to_swa_index_mapping[                         self.req_to_token_pool.req_to_token[-                            forward_batch.req_pool_indices, :seq_lens_max+                            forward_batch.req_pool_indices,+                            :seq_lens_max : self.page_size,                         ]-                    ][:, :: self.page_size]+                    ]                     // self.page_size                 )                 .to(torch.int32)@@ -460,7 +468,13 @@ class AscendAttnBackend(AttentionBackend):         if forward_batch.extend_seq_lens is not None:             self.forward_metadata.extend_seq_lens = forward_batch.extend_seq_lens             self.forward_metadata.extend_seq_lens_cpu_int = (-                forward_batch.extend_seq_lens.cpu().int()+                torch.tensor(+                    forward_batch.extend_seq_lens_cpu,+                    dtype=torch.int32,+                    device="cpu",+                )+                if forward_batch.extend_seq_lens_cpu is not None+                else forward_batch.extend_seq_lens.cpu().int()             )         if forward_batch.seq_lens is not None:             self.forward_metadata.seq_lens = forward_batch.seq_lens.int()diff --git a/python/sglang/srt/hardware_backend/npu/graph_runner/npu_cudagraph_backend.py b/python/sglang/srt/hardware_backend/npu/graph_runner/npu_cudagraph_backend.pyindex 105034c03c0fb36d35254f822b63908f5bd0a2a0..3d4cdf7ae5d750fe9a8b2c93df831fefeac8eb01 100644--- a/python/sglang/srt/hardware_backend/npu/graph_runner/npu_cudagraph_backend.py+++ b/python/sglang/srt/hardware_backend/npu/graph_runner/npu_cudagraph_backend.py@@ -12,7 +12,7 @@ non-NPU hosts.  from __future__ import annotations -import threading+from concurrent.futures import ThreadPoolExecutor from contextlib import AbstractContextManager, contextmanager from functools import partial from typing import TYPE_CHECKING, Any, Callable, Dict, Optional@@ -54,6 +54,7 @@ class NPUCudaGraphBackend(BaseCudaGraphBackend):         self._pool = None         self._device_module = cuda_graph_runner.device_module         self._device_id = self._device_module.current_device()+        self._update_executor: Optional[ThreadPoolExecutor] = None         self._tp_group = cuda_graph_runner.model_runner.tp_group         self._capture_stream = None         self._memory_saver_adapter: Optional[Any] = TorchMemorySaverAdapter.create(@@ -150,8 +151,8 @@ class NPUCudaGraphBackend(BaseCudaGraphBackend):         attr_type: Any = None,         cpu_update_input: list = None,     ) -> Any:-        """Rebind seq_lens on the recorded NPU graph in a background-        thread, then replay. Used when the model is not deepseek-nsa.+        """Rebind seq_lens on a background worker concurrently with replay.+        Used when the model is not deepseek-nsa.          Two calling conventions:         1. (legacy) seq_lens + attr_name + attr_type:@@ -166,17 +167,31 @@ class NPUCudaGraphBackend(BaseCudaGraphBackend):          graph = self._graphs[shape_key] -        def _update():-            self._device_module.set_device(self._device_id)-            graph.update(cpu_update_input=cpu_update_input)--        thread = threading.Thread(target=_update)-        thread.start()-        graph.replay()-        thread.join()+        # update and replay must run concurrently, but creating a device thread+        # for every decoded token adds host overhead. Keep one worker per+        # backend, with its device context initialized once.+        if self._update_executor is None:+            self._update_executor = ThreadPoolExecutor(+                max_workers=1,+                thread_name_prefix="npu-graph-update",+                initializer=self._device_module.set_device,+                initargs=(self._device_id,),+            )+        update = self._update_executor.submit(+            graph.update, cpu_update_input=cpu_update_input+        )+        try:+            graph.replay()+        finally:+            # Drain the update even when replay fails, and propagate worker+            # errors instead of silently losing exceptions in a raw thread.+            update.result()         return self._outputs[shape_key]      def cleanup(self) -> None:+        if self._update_executor is not None:+            self._update_executor.shutdown(wait=True)+            self._update_executor = None         self._graphs.clear()         self._outputs.clear()         self._pool = Nonediff --git a/python/sglang/srt/hardware_backend/npu/graph_runner/npu_graph_runner.py b/python/sglang/srt/hardware_backend/npu/graph_runner/npu_graph_runner.pyindex b82c973bc340c072ea79877ef4a0d183bd6af32d..59f7791d903810e9f2b5466379e0a682fac202f3 100644--- a/python/sglang/srt/hardware_backend/npu/graph_runner/npu_graph_runner.py+++ b/python/sglang/srt/hardware_backend/npu/graph_runner/npu_graph_runner.py@@ -239,16 +239,9 @@ class NPUGraphRunner(DecodeCudaGraphRunner):             is_deepseek_dsa(self.model_runner.model_config.hf_config)             or is_deepseek_v4(self.model_runner.model_config.hf_config)         ):-            if forward_batch.forward_mode.is_target_verify():-                seq_lens_cpu = forward_batch.seq_lens.cpu() + self.captured_req_width-                seq_lens = seq_lens_cpu.tolist() + [0] * (self.bs - self.raw_bs)-            else:-                seq_lens = forward_batch.seq_lens.cpu().tolist() + [0] * (-                    self.bs - self.raw_bs-                )             output = self.backend.replay_with_input_update(                 graph_key,-                seq_lens=seq_lens,+                seq_lens=self._get_replay_seq_lens(forward_batch),                 attr_name=self._get_update_attr_name(),                 attr_type=self._get_update_attr_type(),             )@@ -282,3 +275,20 @@ class NPUGraphRunner(DecodeCudaGraphRunner):         else:             assert isinstance(output, PPProxyTensors)             return PPProxyTensors({k: v[: self.bs] for k, v in output.tensors.items()})++    def _get_replay_seq_lens(self, forward_batch: ForwardBatch) -> list[int]:+        # Ordinary decode already maintains an exact host mirror. Reading it+        # avoids synchronizing all input copies just to copy lengths back from+        # the NPU. Speculative workers can update lengths on device, so retain+        # their device read and target-verification adjustment.+        if (+            forward_batch.forward_mode.is_decode()+            and self.model_runner.spec_algorithm.is_none()+            and forward_batch.seq_lens_cpu is not None+        ):+            seq_lens_cpu = forward_batch.seq_lens_cpu+        else:+            seq_lens_cpu = forward_batch.seq_lens.cpu()+        if forward_batch.forward_mode.is_target_verify():+            seq_lens_cpu = seq_lens_cpu + self.captured_req_width+        return seq_lens_cpu.tolist() + [0] * (self.bs - self.raw_bs)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..6042c1e12890ef93d9ebb5dc13b53f6218827ac4 100644--- a/python/sglang/srt/hardware_backend/npu/memory_pool_npu.py+++ b/python/sglang/srt/hardware_backend/npu/memory_pool_npu.py@@ -129,6 +129,27 @@ class NPUMHATokenToKVPool(MHATokenToKVPool):                     for i in range(self.layer_num)                 ] +            # Keep the public multi-layer tensors for Ascend host-cache+            # transfers, but retain their layer views for attention dispatch.+            # Repeated reads then avoid constructing a new tensor view.+            self._k_buffer_views = list(self.k_buffer)+            self._v_buffer_views = list(self.v_buffer)++    def _get_key_buffer(self, layer_id: int):+        if self.store_dtype != self.dtype or self.is_quantized_kv_cache:+            return super()._get_key_buffer(layer_id)+        return self._k_buffer_views[layer_id - self.start_layer]++    def _get_value_buffer(self, layer_id: int):+        if self.store_dtype != self.dtype or self.is_quantized_kv_cache:+            return super()._get_value_buffer(layer_id)+        return self._v_buffer_views[layer_id - self.start_layer]++    def _clear_buffers(self):+        self._k_buffer_views = None+        self._v_buffer_views = None+        super()._clear_buffers()+     def _init_kv_copy_and_warmup(self):         # implementation relies on self.data_strides / self.data_ptrs, which the         # NPU paged buffer layout never builds.diff --git a/python/sglang/srt/managers/scheduler.py b/python/sglang/srt/managers/scheduler.pyindex a9615a14c512345b2d63323ff3ebd2fe3d9a0dca..8deff02185eb7a11143f1695356c305bc3fdaca3 100644--- a/python/sglang/srt/managers/scheduler.py+++ b/python/sglang/srt/managers/scheduler.py@@ -1818,11 +1818,32 @@ class Scheduler(             and len(self.result_queue) > 0         ) +        # Eager NPU prefill can finish while the next batch is being prepared.+        # Publish its first token before submitting another forward if the CPU+        # copy is already complete. Querying the event preserves overlap when+        # the device is still busy. Use the queued snapshot because preparing a+        # decode batch can change last_batch.forward_mode in place.+        # A local readiness decision is only safe without collective ranks.+        prefill_ready = False+        if (+            _is_npu+            and self.is_generation+            and not self.require_mlp_sync+            and self.ps.tp_size == 1+            and self.ps.pp_size == 1+            and self.spec_algorithm.is_none()+            and len(self.result_queue) == 1+        ):+            pending_batch, pending_result = self.result_queue[0]+            if pending_batch.forward_mode.is_extend():+                copy_done = pending_result.copy_done+                prefill_ready = copy_done is not None and copy_done.query()+         # Algorithms that support grammar overlap advance the FSM inside verify()         # via the grammar barrier (overlapping the target forward), which resolves         # whatever result is still pending in the queue — including the         # extend->decode boundary — so no grammar-specific overlap disable is needed.-        return disable_overlap_for_batch or need_grammar_sync+        return disable_overlap_for_batch or need_grammar_sync or prefill_ready      def _advance_pending_grammar(self):         """Grammar barrier (spec-v2 overlap): advance the FSM over any not-yetdiff --git a/python/sglang/srt/models/qwen3.py b/python/sglang/srt/models/qwen3.pyindex 9fbd046709e6d2d557b005f22d8b8586727fcec4..aa3e71852bb8f235546d33ed3f0bb761a970befb 100644--- a/python/sglang/srt/models/qwen3.py+++ b/python/sglang/srt/models/qwen3.py@@ -25,7 +25,10 @@ from sglang.srt.model_executor.cuda_graph_config import (     check_cuda_graph_backend, ) from sglang.srt.model_executor.forward_batch_info import ForwardBatch, PPProxyTensors-from sglang.srt.model_executor.forward_context import get_token_to_kv_pool+from sglang.srt.model_executor.forward_context import (+    get_attn_backend,+    get_token_to_kv_pool,+) from sglang.srt.model_loader.weight_utils import (     default_weight_loader,     maybe_remap_kv_scale_name,@@ -58,6 +61,7 @@ if _is_npu:     from sgl_kernel_npu.norm.split_qkv_rmsnorm_rope import split_qkv_rmsnorm_rope      from sglang.srt.hardware_backend.npu.cmo import get_cmo_stream, wait_cmo_stream+    from sglang.srt.hardware_backend.npu.memory_pool_npu import NPUMHATokenToKVPool   class Qwen3Attention(nn.Module):@@ -188,6 +192,24 @@ class Qwen3Attention(nn.Module):          if self.attn.layer_id == self.start_layer:             self.rotary_emb.get_cos_sin_with_position(positions)++        cache_kwargs = {}+        backend = get_attn_backend()+        pool = backend.token_to_kv_pool+        if (+            getattr(backend, "supports_fused_qkv_cache", False)+            and isinstance(pool, NPUMHATokenToKVPool)+            and pool.dtype == pool.store_dtype == qkv.dtype+            and forward_batch.out_cache_loc is not None+            and forward_batch.out_cache_loc.numel() == qkv.shape[0]+            and get_exec().deterministic.rl_on_policy_target is None+            and not torch.compiler.is_compiling()+        ):+            cache_kwargs = dict(+                cache_loc=forward_batch.out_cache_loc,+                k_cache=pool.get_key_buffer(self.attn.layer_id),+                v_cache=pool.get_value_buffer(self.attn.layer_id),+            )         q, k, v = split_qkv_rmsnorm_rope(             qkv,             self.rotary_emb.position_sin,@@ -200,6 +222,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 +320,7 @@ class Qwen3Attention(nn.Module):                 hidden_states=hidden_states,                 forward_batch=forward_batch,             )+            save_kv_cache = k is not None          if get_exec().deterministic.rl_on_policy_target is not None:             q = q.to(torch.bfloat16)diff --git a/python/sglang/test/ascend/test_attention_metadata.py b/python/sglang/test/ascend/test_attention_metadata.pynew file mode 100644index 0000000000000000000000000000000000000000..e347bfadcc9437c897e4dfc30074ce0c33c2c54f--- /dev/null+++ b/python/sglang/test/ascend/test_attention_metadata.py@@ -0,0 +1,84 @@+"""Regression tests for the eager Ascend attention metadata path."""++from types import SimpleNamespace+from unittest.mock import Mock++import pytest+import torch++pytest.importorskip("torch_npu")+pytest.importorskip("sgl_kernel_npu")++from sglang.srt.hardware_backend.npu.attention.ascend_backend import AscendAttnBackend+from sglang.srt.model_executor.forward_batch_info import ForwardMode+++@pytest.mark.parametrize("device", ["cpu", "npu"])+@pytest.mark.parametrize("hybrid_swa", [False, True])+@pytest.mark.parametrize("mode", [ForwardMode.EXTEND, ForwardMode.TARGET_VERIFY])+def test_eager_metadata_uses_host_lengths(device, hybrid_swa, mode):+    if device == "npu" and not torch.npu.is_available():+        pytest.skip("NPU is unavailable")++    page_size = 128+    token_table = torch.arange(4 * 1024, dtype=torch.int32, device=device).view(+        4, 1024+    )+    indices = torch.tensor([2, 0, 3], device=device)+    seq_lens_cpu = torch.tensor([129, 511, 255], dtype=torch.int64)+    extend_lens = [17, 383, 127]+    batch = SimpleNamespace(+        forward_mode=mode,+        req_pool_indices=indices,+        seq_lens=seq_lens_cpu.to(device),+        seq_lens_cpu=seq_lens_cpu,+        extend_seq_lens=torch.tensor(extend_lens, device=device),+        extend_seq_lens_cpu=extend_lens,+        spec_info=None,+    )+    # Fail if the existing host metadata is replaced with a device reduction+    # or copy. Use a separate tensor even when testing on the CPU.+    batch.seq_lens = batch.seq_lens.clone()+    batch.seq_lens.max = Mock(side_effect=AssertionError("device reduction"))+    batch.extend_seq_lens.cpu = Mock(side_effect=AssertionError("device copy"))++    backend = AscendAttnBackend.__new__(AscendAttnBackend)+    backend.device = device+    backend.page_size = page_size+    backend.req_to_token_pool = SimpleNamespace(req_to_token=token_table)+    backend.is_hybrid_swa = hybrid_swa+    backend.use_sliding_window_kv_pool = False+    backend.use_mla = False+    backend.speculative_num_draft_tokens = 3+    if hybrid_swa:+        backend.full_to_swa_index_mapping = (+            torch.arange(4 * 1024, device=device, dtype=torch.int32) + 256+        )++    extra = backend.speculative_num_draft_tokens if mode.is_target_verify() else 0+    max_len = int(seq_lens_cpu.max()) + extra+    # The reference gathers the original full sequence table before taking+    # page starts; the optimized path must preserve request order and tails.+    selected = token_table[indices, :max_len]+    expected = selected[:, ::page_size] // page_size+    backend.init_forward_metadata(batch)+    metadata = backend.forward_metadata++    torch.testing.assert_close(metadata.block_tables, expected, rtol=0, atol=0)+    torch.testing.assert_close(+        metadata.extend_seq_lens_cpu_int,+        torch.tensor(extend_lens, dtype=torch.int32),+        rtol=0,+        atol=0,+    )+    torch.testing.assert_close(+        metadata.seq_lens_cpu_int, (seq_lens_cpu + extra).int(), rtol=0, atol=0+    )+    if hybrid_swa:+        expected_swa = (+            backend.full_to_swa_index_mapping[selected][:, ::page_size] // page_size+        )+        torch.testing.assert_close(+            metadata.block_tables_swa, expected_swa, rtol=0, atol=0+        )+    assert not backend.graph_modediff --git a/python/sglang/test/ascend/test_graph_replay_updates.py b/python/sglang/test/ascend/test_graph_replay_updates.pynew file mode 100644index 0000000000000000000000000000000000000000..47c9bcab76ff51f27683bb6afb330aa637324811--- /dev/null+++ b/python/sglang/test/ascend/test_graph_replay_updates.py@@ -0,0 +1,115 @@+"""Host-side NPU graph replay and update ordering, without NPU allocation."""++import threading+from types import SimpleNamespace+from unittest.mock import Mock++import pytest+import torch++from sglang.srt.hardware_backend.npu.graph_runner.npu_cudagraph_backend import (+    NPUCudaGraphBackend,+)+from sglang.srt.hardware_backend.npu.graph_runner.npu_graph_runner import NPUGraphRunner+from sglang.srt.model_executor.forward_batch_info import ForwardMode+++def make_backend(graph):+    device = SimpleNamespace(current_device=lambda: 3, set_device=Mock())+    runner = SimpleNamespace(+        device_module=device, model_runner=SimpleNamespace(tp_group=None)+    )+    backend = NPUCudaGraphBackend(runner)+    backend._graphs[1] = graph+    backend._outputs[1] = object()+    return backend, device+++def test_graph_updates_overlap_replay_and_reuse_worker():+    update_started = threading.Event()+    replay_started = threading.Event()+    workers = []+    updates = []++    def update(*, cpu_update_input):+        workers.append(threading.current_thread())+        updates.append(cpu_update_input)+        update_started.set()+        assert replay_started.wait(timeout=5)++    def replay():+        replay_started.set()+        assert update_started.wait(timeout=5)++    backend, device = make_backend(SimpleNamespace(update=update, replay=replay))+    try:+        for lengths in ([13], [17]):+            update_started.clear()+            replay_started.clear()+            result = backend.replay_with_input_update(+                1, lengths, attr_name="context_lens"+            )+            assert result is backend._outputs[1]+        assert updates == [[{"context_lens": [13]}], [{"context_lens": [17]}]]+        assert workers[0] is workers[1]+        device.set_device.assert_called_once_with(3)+    finally:+        backend.cleanup()+    assert all(not worker.is_alive() for worker in workers)+    assert not backend._graphs and not backend._outputs+++@pytest.mark.parametrize("failure", ["update", "replay"])+def test_graph_replay_drains_update_and_propagates_errors(failure):+    update_finished = threading.Event()++    def update(**kwargs):+        update_finished.set()+        if failure == "update":+            raise RuntimeError("update failed")++    def replay():+        if failure == "replay":+            raise RuntimeError("replay failed")++    backend, _ = make_backend(SimpleNamespace(update=update, replay=replay))+    try:+        with pytest.raises(RuntimeError, match=f"{failure} failed"):+            backend.replay_with_input_update(1, [5], attr_name="context_lens")+        assert update_finished.is_set()+    finally:+        backend.cleanup()+++@pytest.mark.parametrize(+    "mode,speculative,host_lengths,expected",+    [+        (ForwardMode.DECODE, False, [11, 19], [11, 19, 0, 0]),+        (ForwardMode.DECODE, False, None, [23, 31, 0, 0]),+        (ForwardMode.DECODE, True, [11, 19], [23, 31, 0, 0]),+        (ForwardMode.TARGET_VERIFY, True, [11, 19], [26, 34, 0, 0]),+    ],+)+def test_replay_lengths_use_host_mirror_only_for_ordinary_decode(+    mode, speculative, host_lengths, expected+):+    runner = SimpleNamespace(+        model_runner=SimpleNamespace(+            spec_algorithm=SimpleNamespace(is_none=lambda: not speculative)+        ),+        captured_req_width=3,+        bs=4,+        raw_bs=2,+    )+    device_lengths = Mock()+    device_lengths.cpu.return_value = torch.tensor([23, 31])+    batch = SimpleNamespace(+        forward_mode=mode,+        seq_lens_cpu=torch.tensor(host_lengths) if host_lengths is not None else None,+        seq_lens=device_lengths,+    )+    assert NPUGraphRunner._get_replay_seq_lens(runner, batch) == expected+    if mode.is_decode() and not speculative and host_lengths is not None:+        device_lengths.cpu.assert_not_called()+    else:+        device_lengths.cpu.assert_called_once_with()diff --git a/python/sglang/test/ascend/test_kv_buffer_views.py b/python/sglang/test/ascend/test_kv_buffer_views.pynew file mode 100644index 0000000000000000000000000000000000000000..4104504590446141102969986306b5c17a994d21--- /dev/null+++ b/python/sglang/test/ascend/test_kv_buffer_views.py@@ -0,0 +1,76 @@+"""Persistent layer views must preserve NPU KV storage and transfer layout."""++from contextlib import nullcontext+from types import SimpleNamespace+from weakref import ref++import pytest+import torch++from sglang.srt.hardware_backend.npu.memory_pool_npu import NPUMHATokenToKVPool+from sglang.srt.mem_cache.memory_pool import UnquantizedKVCacheMethod+++def make_pool(use_fia):+    pool = NPUMHATokenToKVPool.__new__(NPUMHATokenToKVPool)+    pool.layer_num = 3+    pool.start_layer = 4+    pool.size = 384+    pool.page_size = 128+    pool.head_num = 2+    pool.head_dim = 64+    pool.v_head_dim = 32+    pool.dtype = pool.store_dtype = torch.bfloat16+    pool.device = "cpu"+    pool.use_fia = use_fia+    pool.quant_method = UnquantizedKVCacheMethod()+    pool.layer_transfer_counter = None+    pool._post_capture_owner = None+    pool.memory_saver_adapter = SimpleNamespace(region=lambda _: nullcontext())+    pool._create_buffers()+    return pool+++@pytest.mark.parametrize("use_fia", [False, True])+def test_layer_views_preserve_contiguous_storage_and_transfer_sizes(use_fia):+    pool = make_pool(use_fia)++    assert len(pool.k_buffer) == len(pool.v_buffer) == pool.layer_num+    if not use_fia:+        assert isinstance(pool.k_buffer, torch.Tensor)+        assert isinstance(pool.v_buffer, torch.Tensor)+    for buffers, head_dim, getter in (+        (pool._k_buffer_views, pool.head_dim, pool.get_key_buffer),+        (pool._v_buffer_views, pool.v_head_dim, pool.get_value_buffer),+    ):+        page_shape = (4, pool.page_size, pool.head_num, head_dim)+        expected_shape = (512, 1, pool.head_num, head_dim) if use_fia else page_shape+        for i, buffer in enumerate(buffers):+            assert getter(pool.start_layer + i) is buffer+            assert getter(pool.start_layer + i) is getter(pool.start_layer + i)+            assert tuple(buffer.shape) == expected_shape+            assert buffer.is_contiguous()+            assert buffer.data_ptr() == buffers[0].data_ptr() + i * buffer.nbytes+        buffers[1].fill_(2)+        assert torch.count_nonzero(buffers[0]) == 0+        assert torch.count_nonzero(buffers[2]) == 0+        assert torch.all(getter(pool.start_layer + 1) == 2)++    pointers, lengths, item_lengths = pool.get_contiguous_buf_infos()+    buffers = pool._k_buffer_views + pool._v_buffer_views+    assert pointers == [buffer.data_ptr() for buffer in buffers]+    assert lengths == [buffer.nbytes for buffer in buffers]+    assert item_lengths == [buffer.nbytes // 4 for buffer in buffers]+    assert pool.get_kv_size_bytes() == (+        sum(buffer.nbytes for buffer in pool.k_buffer),+        sum(buffer.nbytes for buffer in pool.v_buffer),+    )+++@pytest.mark.parametrize("use_fia", [False, True])+def test_clear_buffers_releases_cached_layer_views(use_fia):+    pool = make_pool(use_fia)+    views = [ref(buffer) for buffer in pool._k_buffer_views + pool._v_buffer_views]+    pool._clear_buffers()+    assert all(view() is None for view in views)+    assert not hasattr(pool, "k_buffer") and not hasattr(pool, "v_buffer")diff --git a/python/sglang/test/ascend/test_prefill_result_overlap.py b/python/sglang/test/ascend/test_prefill_result_overlap.pynew file mode 100644index 0000000000000000000000000000000000000000..904eb7cffdd6847d19ffcff596f369d008f7be55--- /dev/null+++ b/python/sglang/test/ascend/test_prefill_result_overlap.py@@ -0,0 +1,116 @@+"""Ready prefill results should not wait for another NPU forward submission."""++from collections import deque+from types import SimpleNamespace+from unittest.mock import Mock++import pytest++from sglang.srt.environ import envs+from sglang.srt.managers import scheduler as scheduler_module+from sglang.srt.managers.scheduler import Scheduler+from sglang.srt.model_executor.forward_batch_info import ForwardMode+++def make_scheduler(ready=True, mode=ForwardMode.EXTEND):+    spec_algorithm = SimpleNamespace(is_none=lambda: True)+    pending_batch = SimpleNamespace(forward_mode=mode)+    event = Mock()+    event.query.return_value = ready+    scheduler = SimpleNamespace(+        is_generation=True,+        require_mlp_sync=False,+        ps=SimpleNamespace(tp_size=1, pp_size=1),+        spec_algorithm=spec_algorithm,+        result_queue=deque([(pending_batch, SimpleNamespace(copy_done=event))]),+    )+    # Planning can reuse the last prefill batch as the next decode batch. The+    # queued copy still identifies which forward produced the pending result.+    batch = SimpleNamespace(+        forward_mode=ForwardMode.DECODE,+        spec_algorithm=spec_algorithm,+        is_extend_in_batch=False,+    )+    return scheduler, batch, event+++@pytest.mark.parametrize("ready", [False, True])+def test_prefill_readiness_is_nonblocking(monkeypatch, ready):+    monkeypatch.setattr(scheduler_module, "_is_npu", True)+    scheduler, batch, event = make_scheduler(ready=ready)+    with envs.SGLANG_DISABLE_CONSECUTIVE_PREFILL_OVERLAP.override(False):+        disabled = Scheduler.is_disable_overlap_for_batch(scheduler, batch, batch)+        assert bool(disabled) == ready+    event.query.assert_called_once_with()+    event.synchronize.assert_not_called()+++@pytest.mark.parametrize(+    "excluded",+    [+        "cuda",+        "tp",+        "pp",+        "dp_sync",+        "embedding",+        "speculative",+        "decode",+        "no_event",+        "empty",+        "multiple",+    ],+)+def test_prefill_publication_keeps_other_overlap_paths(monkeypatch, excluded):+    monkeypatch.setattr(scheduler_module, "_is_npu", excluded != "cuda")+    scheduler, batch, event = make_scheduler()+    if excluded == "tp":+        scheduler.ps.tp_size = 2+    elif excluded == "pp":+        scheduler.ps.pp_size = 2+    elif excluded == "dp_sync":+        scheduler.require_mlp_sync = True+    elif excluded == "embedding":+        scheduler.is_generation = False+    elif excluded == "speculative":+        scheduler.spec_algorithm = SimpleNamespace(is_none=lambda: False)+    elif excluded == "decode":+        scheduler.result_queue[0][0].forward_mode = ForwardMode.DECODE+    elif excluded == "no_event":+        scheduler.result_queue[0][1].copy_done = None+    elif excluded == "empty":+        scheduler.result_queue.clear()+    elif excluded == "multiple":+        scheduler.result_queue.append(scheduler.result_queue[0])++    with envs.SGLANG_DISABLE_CONSECUTIVE_PREFILL_OVERLAP.override(False):+        assert not Scheduler.is_disable_overlap_for_batch(scheduler, batch, batch)+    event.query.assert_not_called()+    event.synchronize.assert_not_called()+++def test_ready_prefill_can_be_published_when_no_next_batch(monkeypatch):+    monkeypatch.setattr(scheduler_module, "_is_npu", True)+    scheduler, last_batch, event = make_scheduler()+    with envs.SGLANG_DISABLE_CONSECUTIVE_PREFILL_OVERLAP.override(False):+        assert Scheduler.is_disable_overlap_for_batch(scheduler, None, last_batch)+    event.query.assert_called_once_with()+++def test_explicit_consecutive_prefill_control_is_preserved(monkeypatch):+    monkeypatch.setattr(scheduler_module, "_is_npu", True)+    scheduler, batch, _ = make_scheduler(ready=False)+    batch.forward_mode = ForwardMode.EXTEND+    with envs.SGLANG_DISABLE_CONSECUTIVE_PREFILL_OVERLAP.override(True):+        assert Scheduler.is_disable_overlap_for_batch(scheduler, batch, batch)+++def test_grammar_barrier_is_preserved(monkeypatch):+    monkeypatch.setattr(scheduler_module, "_is_npu", True)+    scheduler, batch, event = make_scheduler(ready=False)+    batch.spec_algorithm = scheduler.spec_algorithm = SimpleNamespace(+        is_none=lambda: False+    )+    batch.grammar_needs_sync = lambda: True+    with envs.SGLANG_DISABLE_CONSECUTIVE_PREFILL_OVERLAP.override(False):+        assert Scheduler.is_disable_overlap_for_batch(scheduler, batch, batch)+    event.query.assert_not_called()diff --git a/sgl-kernel-npu/python/sgl_kernel_npu/sgl_kernel_npu/__init__.py b/sgl-kernel-npu/python/sgl_kernel_npu/sgl_kernel_npu/__init__.pyindex 9b43453aa322ae20dc6be66fdf522561e9252644..e20ae99955fb5e2fc1979feb657e489c84c8c3b1 100644--- a/sgl-kernel-npu/python/sgl_kernel_npu/sgl_kernel_npu/__init__.py+++ b/sgl-kernel-npu/python/sgl_kernel_npu/sgl_kernel_npu/__init__.py@@ -2,8 +2,33 @@ import os import pathlib from functools import lru_cache, wraps -import torch-import torch_npu++def _init_ascend_log_paths():+    # MKI checks both variables even when using CANN's default log directory.+    # Unset paths make library teardown print diagnostics to stdout, corrupting+    # the output of programs that import the operators and emit structured data.+    if "ASCEND_WORK_PATH" in os.environ and "ASCEND_PROCESS_LOG_PATH" in os.environ:+        return+    work_path = pathlib.Path(+        os.environ.get("ASCEND_WORK_PATH", pathlib.Path.home() / "ascend")+    )+    log_path = pathlib.Path(+        os.environ.get("ASCEND_PROCESS_LOG_PATH", work_path / "log")+    )+    try:+        work_path.mkdir(parents=True, exist_ok=True)+        log_path.mkdir(parents=True, exist_ok=True)+    except OSError:+        # Preserve the library's own fallback on hosts with a read-only home.+        return+    os.environ.setdefault("ASCEND_WORK_PATH", str(work_path))+    os.environ.setdefault("ASCEND_PROCESS_LOG_PATH", str(log_path))+++_init_ascend_log_paths()++import torch  # noqa: E402+import torch_npu  # noqa: E402   def _load_sgl_kernel_npu():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..c6fc8d59ec7a1e0302b1e306a620814f21cfc5a0 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@@ -32,6 +32,8 @@ def split_qkv_rmsnorm_rope_kernel(     PASS_DIM: tl.constexpr,     DO_PARTIAL: tl.constexpr,     DO_HALF: tl.constexpr,+    cache_loc_ptr=None,+    WRITE_CACHE: tl.constexpr = False, ):     row_pid = tl.program_id(0)     col_pid = tl.program_id(1)@@ -345,25 +347,45 @@ def split_qkv_rmsnorm_rope_kernel(         else:             normalized_values = roped_k -        # store-        tl.store(-            k_ptr + output_offset + col_indices,-            normalized_values.reshape(KV_BLOCK_SIZE).to(k_ptr.dtype.element_ty),-            mask=valid_mask,-        )+        # The paged NPU cache is contiguous in (slot, head, head_dim) order.+        # Writing the final values here avoids materializing K/V only to+        # copy them into that cache with a second operator.+        if WRITE_CACHE:+            slot = tl.load(cache_loc_ptr + row_idx).to(tl.int64)+            if slot >= 0:+                tl.store(+                    k_ptr + slot * kv_hidden_size + col_indices,+                    normalized_values.reshape(KV_BLOCK_SIZE).to(k_ptr.dtype.element_ty),+                    mask=valid_mask,+                )+        else:+            tl.store(+                k_ptr + output_offset + col_indices,+                normalized_values.reshape(KV_BLOCK_SIZE).to(k_ptr.dtype.element_ty),+                mask=valid_mask,+            )         input_offset += input_offset_step         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         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)+        if WRITE_CACHE:+            slot = tl.load(cache_loc_ptr + row_idx).to(tl.int64)+            if slot >= 0:+                tl.store(+                    v_ptr + slot * kv_hidden_size + col_indices,+                    input_values,+                    mask=valid_mask,+                )+        else:+            tl.store(v_ptr + output_offset + col_indices, input_values, mask=valid_mask)         input_offset += input_offset_step         output_offset += output_offset_step @@ -384,7 +406,18 @@ def split_qkv_rmsnorm_rope(     q_bias=None,     k_bias=None,     is_neox_style=True,+    *,+    cache_loc=None,+    k_cache=None,+    v_cache=None, ):+    """Split, normalize and rotate Q/K, optionally writing K/V to a slot cache.++    Cache tensors must use the input dtype and contiguous slot-major storage.+    When cache_loc is supplied, return (q, None, None): the attention backend+    must read K/V from the cache and skip its separate cache write. Negative+    locations are padding and leave the corresponding cache slots untouched.+    """     _, num_vectorcore = get_device_properties()      KV_BLOCK_SIZE = triton.next_power_of_2(head_dim)@@ -396,12 +429,26 @@ 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-    )+    write_cache = cache_loc is not None+    if write_cache:+        assert k_cache is not None and v_cache is not None+        assert k_cache.is_contiguous() and v_cache.is_contiguous()+        assert k_cache.numel() == v_cache.numel()+        assert k_cache.numel() % kv_hidden_size == 0+        assert k_cache.dtype == v_cache.dtype == input.dtype+        assert k_cache.device == v_cache.device == cache_loc.device == input.device+        assert cache_loc.ndim == 1 and cache_loc.numel() == batch_size+        assert cache_loc.is_contiguous()+        assert cache_loc.dtype in (torch.int32, torch.int64)+        k_output, v_output = k_cache, v_cache+    else:+        assert k_cache is None and v_cache is None+        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+        )     n_cols = kv_hidden_size // KV_BLOCK_SIZE     n_rows = (num_vectorcore + n_cols - 1) // n_cols     BIAS = q_bias is not None@@ -433,8 +480,12 @@ def split_qkv_rmsnorm_rope(         head_dim - rope_dim,         DO_PARTIAL=(head_dim != rope_dim),         DO_HALF=is_neox_style,+        cache_loc_ptr=cache_loc,+        WRITE_CACHE=write_cache,     ) +    if write_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..926eb4b7dbb2ce08a712f431267c78096cdc7e4d 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@@ -162,7 +162,7 @@ def test_split_qkv_rope():     # rope     _q = _q.reshape(bsz, 1, -1, head_dim).to(torch.float32).cpu().numpy()     _k = _k.reshape(bsz, 1, -1, head_dim).to(torch.float32).cpu().numpy()-    cus_q, cus_k = custom_rope(_q, _k, sin, cos)+    cus_q, cus_k = custom_rope(_q, _k, sin, cos, half_rope_dim=head_dim // 2)     cus_q = cus_q.reshape(bsz, -1)     cus_k = cus_k.reshape(bsz, -1) diff --git a/sgl-kernel-npu/tests/python/sgl_kernel_npu/test_split_qkv_rmsnorm_rope_cache.py b/sgl-kernel-npu/tests/python/sgl_kernel_npu/test_split_qkv_rmsnorm_rope_cache.pynew file mode 100644index 0000000000000000000000000000000000000000..0c997e31be1c8ff194c356ec7bf48f261652f0e0--- /dev/null+++ b/sgl-kernel-npu/tests/python/sgl_kernel_npu/test_split_qkv_rmsnorm_rope_cache.py@@ -0,0 +1,62 @@+import pytest+import torch+import torch_npu  # noqa: F401+from sgl_kernel_npu.norm.split_qkv_rmsnorm_rope import split_qkv_rmsnorm_rope+++@pytest.mark.parametrize("dtype", [torch.bfloat16, torch.float16])+@pytest.mark.parametrize(+    "tokens,q_heads,kv_heads,head_dim,rope_dim,neox,norm,bias",+    [+        (1, 8, 8, 64, 64, True, False, False),+        (7, 16, 8, 128, 128, True, True, False),+        (65, 12, 2, 128, 64, True, True, True),+        (131, 16, 8, 128, 128, False, True, True),+    ],+)+def test_fused_cache_matches_separate_outputs(+    dtype, tokens, q_heads, kv_heads, head_dim, rope_dim, neox, norm, bias+):+    torch.manual_seed(901)+    q_size, kv_size = q_heads * head_dim, kv_heads * head_dim+    qkv = torch.randn(tokens, q_size + 2 * kv_size, device="npu", dtype=dtype)+    sin = torch.randn(tokens, 1, 1, rope_dim, device="npu", dtype=dtype)+    cos = torch.randn_like(sin)+    kwargs = dict(+        eps=1e-6 if norm else None,+        q_weight=torch.randn(head_dim, device="npu", dtype=dtype) if norm else None,+        k_weight=torch.randn(head_dim, device="npu", dtype=dtype) if norm else None,+        q_bias=torch.randn(head_dim, device="npu", dtype=dtype) if bias else None,+        k_bias=torch.randn(head_dim, device="npu", dtype=dtype) if bias else None,+        is_neox_style=neox,+    )+    args = (qkv, sin, cos, q_size, kv_size, head_dim)+    q_ref, k_ref, v_ref = split_qkv_rmsnorm_rope(*args, **kwargs)++    page_size = 128+    pages = (2 * tokens + page_size - 1) // page_size+    slots = pages * page_size+    locations = torch.randperm(slots)[:tokens]+    if tokens > 1:+        locations[1::11] = -1+    locations = locations.to(+        device="npu", dtype=torch.int32 if neox else torch.int64+    )+    k_cache = torch.full(+        (pages, page_size, kv_heads, head_dim), 0.125, device="npu", dtype=dtype+    )+    v_cache = torch.full_like(k_cache, -0.25)+    k_expected, v_expected = k_cache.clone(), v_cache.clone()+    valid = locations >= 0+    k_expected.view(-1, kv_size)[locations[valid].long()] = k_ref[valid]+    v_expected.view(-1, kv_size)[locations[valid].long()] = v_ref[valid]++    q, k, v = split_qkv_rmsnorm_rope(+        *args, **kwargs, cache_loc=locations, k_cache=k_cache, v_cache=v_cache+    )+    assert k is None and v is None+    torch.testing.assert_close(q, q_ref, rtol=0, atol=0)+    # Comparing the entire cache also checks that padding and unused slots+    # retain their original values, including partial final pages.+    torch.testing.assert_close(k_cache, k_expected, rtol=0, atol=0)+    torch.testing.assert_close(v_cache, v_expected, rtol=0, atol=0)