Inspect · Task requirements
Requested workspace inspection and file and log inspection related to task requirements.
1 call · #0001–#0001
pwdprintf <val> <val>cat <path>GPT-6 Astra · Serving
Repeated context 1dev · Implementation Optimization
01 / PROCESS MAP
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 · 237 visible calls
02 / EVENT SEQUENCE
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.
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>.
Requested workspace inspection and file and log inspection related to task requirements.
1 call · #0001–#0001
pwdprintf <val> <val>cat <path>Requested source searches related to task requirements.
1 call · #0002–#0002
rg --files -g <val> -g <val> -g <val> <path> <n> > <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0003–#0003
cat <path> <path> <path> <path> <path> <path>Requested file and log inspection, repository inspection and workspace inspection related to task requirements.
2 calls · #0004–#0005
cat <path> <path> <path> <path>git status --shortls -l -arg --files <path> <val> -g <val> -g <val> -g <val> -g <val>Requested source searches related to benchmark & validation setup.
1 call · #0006–#0006
rg -n <val> <path>Requested file and log inspection related to attention kernels.
1 call · #0007–#0007
cat <path>sed -n <val> <path>Requested tool activity related to task requirements.
1 call · #0008–#0008
<command> <args>Requested script or workload execution related to source & workspace.
1 call · #0009–#0009
bash <script>Requested source searches and file and log inspection related to attention kernels.
1 call · #0010–#0010
rg -n <val> <path>sed -n <val> <path>Requested file and log inspection related to source & workspace.
1 call · #0011–#0011
sed -n <val> <path>Requested environment setup or inspection related to source & workspace.
1 call · #0012–#0012
env <vars> bash <script>Requested file and log inspection related to attention kernels.
1 call · #0013–#0013
sed -n <val> <path>printf <val> <val> <val>Requested file and log inspection and source searches related to source & workspace.
1 call · #0014–#0014
sed -n <val> <path>rg -n <val> <path>cat <path>Requested workspace inspection, file and log inspection and runtime inspection related to device memory.
1 call · #0015–#0015
ls -l <path>tail -n <n> <path>npu-smi infoRequested file and log inspection related to attention kernels.
1 call · #0016–#0016
sed -n <val> <path>Requested file and log inspection related to source & workspace.
1 call · #0017–#0017
sed -n <val> <path>Requested source searches and file and log inspection related to runtime processes.
1 call · #0018–#0018
rg -n <val> <path> <path> <path> -g <path>head -n <n>Requested workspace inspection, runtime inspection and source searches related to device memory.
1 call · #0019–#0019
ls -l <path>npu-smi infops <flag> <args>rg <val>Requested file and log inspection and source searches related to attention kernels.
2 calls · #0020–#0021
cat <path>sed -n <val> <path>rg -n <val> <path> <path>rg -n <val> <path> <path> <path> -g <path>Requested workspace inspection, file and log inspection and script or workload execution related to task requirements.
1 call · #0022–#0022
ls -l <path>tail -n <n> <path>python3 - <script>Requested file and log inspection related to attention kernels.
1 call · #0023–#0023
sed -n <val> <path>Requested file and log inspection and source searches related to batching & scheduling.
1 call · #0024–#0024
sed -n <val> <path>rg -n <val> <path> <path> <path>Requested file and log inspection and source searches related to attention kernels.
2 calls · #0025–#0026
tail -n <n> <path>rg --files <val> <path> -g <val> -g <val> -g <val> -g <val>sed -n <val> <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0027–#0027
tail -n <n> <path>wc -l <path>Requested file and log inspection related to attention kernels.
1 call · #0028–#0028
sed -n <val> <path>Requested file and log inspection related to batching & scheduling.
1 call · #0029–#0029
sed -n <val> <path>Requested source searches and file and log inspection related to attention kernels.
1 call · #0030–#0030
rg -n <val> <path> <path> <path>head -n <n>sed -n <val> <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0031–#0031
tail -n <n> <path>wc -l <path>Requested source searches, file and log inspection and runtime inspection related to batching & scheduling.
1 call · #0032–#0032
rg -n <val> <path>tail -n <n>wc -l <path>ps <flag> <args>Requested source searches and file and log inspection related to source & workspace.
1 call · #0033–#0033
rg -n <val> <path> <path> <path> <path>head -n <n>sed -n <val> <path>Requested file and log inspection and source searches related to batching & scheduling.
2 calls · #0034–#0035
sed -n <val> <path>rg -n <val> <path>rg -n --max-columns <n> <val> <path>tail -n <n>wc -l <path>Requested file and log inspection related to prefix caching.
1 call · #0036–#0036
sed -n <val> <path>Requested file and log inspection related to device memory.
1 call · #0037–#0037
sed -n <val> <path>Requested source searches and file and log inspection related to batching & scheduling.
2 calls · #0038–#0039
rg -n <val> <path> <path> <path> <path>sed -n <val> <path>rg -n --max-columns <n> <val> <path>tail -n <n>wc -l <path>Requested file and log inspection related to source & workspace.
1 call · #0040–#0040
sed -n <val> <path>Requested file and log inspection related to attention kernels.
1 call · #0041–#0041
sed -n <val> <path>Requested file and log inspection and workspace inspection related to benchmark & validation setup.
1 call · #0042–#0042
tail -n <n> <path>wc -l <path>ls <path>Requested source searches and file and log inspection related to attention kernels.
1 call · #0043–#0043
rg -n <val> <path> <path> <path>sed -n <val> <path>Requested file and log inspection and source searches related to source & workspace.
1 call · #0044–#0044
sed -n <val> <path>rg -n <val> <path> <path>Requested file and log inspection, workspace inspection and repository inspection related to benchmark & validation setup.
1 call · #0045–#0045
wc -l <path>tail -n <n> <path>ls -l <path>git log <flag> <args>Requested source searches and file and log inspection related to device memory.
1 call · #0046–#0046
rg -n <val> <path> -g <path>sed -n <val> <path>Requested source searches and file and log inspection related to source & workspace.
1 call · #0047–#0047
rg --files <path>rg <val>sed -n <val> <path>Requested source searches and file and log inspection related to batching & scheduling.
1 call · #0048–#0048
rg -n --max-columns <n> <val> <path>tail -n <n>wc -l <path>du <flag> <args>Requested source searches and file and log inspection related to source & workspace.
2 calls · #0049–#0050
rg -n <val> <path> <path>sed -n <val> <path>Requested file and log inspection related to attention kernels.
1 call · #0051–#0051
sed -n <val> <path>Requested source searches and file and log inspection related to batching & scheduling.
1 call · #0052–#0052
rg -n --max-columns <n> <val> <path>tail -n <n>wc -l <path>Requested file and log inspection related to device memory.
1 call · #0053–#0053
sed -n <val> <path>Requested script or workload execution, source searches and file and log inspection related to benchmark & validation setup.
1 call · #0054–#0054
python3 - <script>rg -n --max-columns <n> <val> <path>tail -n <n>Requested file and log inspection, workspace file updates and environment setup or inspection related to prefix caching.
1 call · #0055–#0055
cat > <path> <script>mkdir -p <path>env <vars> python3 <script> > <path> <n> >& <path>Requested source searches and file and log inspection related to batching & scheduling.
1 call · #0056–#0056
rg -n --max-columns <n> <val> <path>tail -n <n>wc -l <path>Requested file and log inspection related to prefix caching.
1 call · #0057–#0057
sed -n <val> <path>Requested source searches and file and log inspection related to device memory.
1 call · #0058–#0058
rg -n <val> <path> <path>sed -n <val> <path>Requested script or workload execution related to benchmark & validation setup.
1 call · #0059–#0059
python3 - <script>Requested workspace inspection and file and log inspection related to benchmark & validation setup.
1 call · #0060–#0060
ls -l <path>tail -n <n> <path>Requested source searches related to speculative decoding.
1 call · #0061–#0061
rg -n <val> <path> -g <path>rg -n <val> <path>Requested script or workload execution related to benchmark & validation setup.
1 call · #0062–#0062
python3 - <script>Requested source searches and file and log inspection related to benchmark & validation setup.
1 call · #0063–#0063
rg -n --max-columns <n> <val> <path>tail -n <n>Requested file and log inspection and source searches related to speculative decoding.
1 call · #0064–#0064
sed -n <val> <path>rg -n <val> <path>tail -n <n>Requested file and log inspection related to attention kernels.
2 calls · #0065–#0066
sed -n <val> <path>Requested source searches, file and log inspection and repository inspection related to benchmark & validation setup.
2 calls · #0067–#0068
rg -n --max-columns <n> <val> <path>tail -n <n>tail -n <n> <path>git status --shortls -l <path>ps <flag> <args>Requested source searches and file and log inspection related to source & workspace.
1 call · #0069–#0069
rg -n <val> <path>sed -n <val> <path>Requested code edits related to source & workspace.
1 call · #0070–#0070
Apply patch <patch>Requested source searches, file and log inspection and workspace inspection related to batching & scheduling.
1 call · #0071–#0071
rg -n --max-columns <n> <val> <path>tail -n <n>ls -l <path>command -v <val>Requested file and log inspection related to speculative decoding.
1 call · #0072–#0072
sed -n <val> <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0073–#0073
cat <path>tail -n <n> <path>Requested source searches and file and log inspection related to batching & scheduling.
1 call · #0074–#0074
rg -n <val> <path> -g <path>head -n <n>rg -n <val> <path> <path> <path>Requested file and log inspection, workspace inspection and source searches related to attention kernels.
1 call · #0075–#0075
cat > <path> <script>ls <path>tail -n <n>rg <val> <path>Requested file and log inspection related to attention kernels.
1 call · #0076–#0076
cat > <path> <script>Requested file and log inspection and source searches related to source & workspace.
1 call · #0077–#0077
sed -n <val> <path>rg -n <val> <path>tail -n <n>Requested source searches, file and log inspection and script or workload execution related to attention kernels.
1 call · #0078–#0078
rg -n <val> <path>sed -n <val> <path>python3 - <script>Requested script or workload execution and workspace inspection related to benchmark & validation setup.
1 call · #0079–#0079
python3 - <script>ls <path>Requested file and log inspection and script or workload execution related to attention kernels.
1 call · #0080–#0080
cat > <path> <script>python3 - <script>Requested file and log inspection and source searches related to attention kernels.
1 call · #0081–#0081
sed -n <val> <path>rg -n --max-columns <n> <val> <path>tail -n <n>Requested script or workload execution and file and log inspection related to attention kernels.
1 call · #0082–#0082
python3 - <script>sed -n <val> <path>Requested file and log inspection related to latency & request handling.
1 call · #0083–#0083
cat > <path> <script>Requested code edits related to source & workspace.
1 call · #0084–#0084
Apply patch <patch>Requested repository inspection and source searches related to batching & scheduling.
1 call · #0085–#0085
git diff --checkgit status --shortrg --files <path>rg <val>Requested script or workload execution, source searches and file and log inspection related to benchmark & validation setup.
1 call · #0086–#0086
python3 - <script>rg -n --max-columns <n> <val> <path>tail -n <n>Requested file and log inspection and workspace inspection related to benchmark & validation setup.
1 call · #0087–#0087
sed -n <val> <path>ls -l <path>Requested script or workload execution and source searches related to benchmark & validation setup.
1 call · #0088–#0088
python3 - <script>rg -n <val> <path>Requested file and log inspection and source searches related to device memory.
1 call · #0089–#0089
sed -n <val> <path>rg -n <val> <path>head -n <n>Requested script or workload execution related to benchmark & validation setup.
1 call · #0090–#0090
python3 - <script>Requested script or workload execution, source searches and file and log inspection related to attention kernels.
1 call · #0091–#0091
python3 - <script>rg -n --max-columns <n> <val> <path>tail -n <n>ls <path>Requested script or workload execution related to benchmark & validation setup.
1 call · #0092–#0092
python3 - <script>Requested code edits related to attention kernels.
1 call · #0093–#0093
Apply patch <patch>Requested script or workload execution related to attention kernels.
1 call · #0094–#0094
python3 - <script>Requested code edits related to attention kernels.
1 call · #0095–#0095
Apply patch <patch>Requested script or workload execution related to benchmark & validation setup.
1 call · #0096–#0096
python3 - <script>Requested workspace file updates and script or workload execution related to benchmark & validation setup.
1 call · #0097–#0097
mkdir -p <path><command> <args>python3 - <script>Requested script or workload execution related to benchmark & validation setup.
1 call · #0098–#0098
python3 - <script>Requested code edits related to attention kernels.
1 call · #0099–#0099
Apply patch <patch>Requested repository inspection and file and log inspection related to source & workspace.
1 call · #0100–#0100
git diff --checktail -n <n> <path>Requested script or workload execution related to benchmark & validation setup.
1 call · #0101–#0101
<command> <args>python3 - <script>python3 <script> > <path> <n> >& <path>Requested file and log inspection related to source & workspace.
1 call · #0102–#0102
sed -n <val> <path>Requested file and log inspection, workspace inspection and repository inspection related to benchmark & validation setup.
1 call · #0103–#0103
tail -n <n> <path>ls -l <path>git diff --statRequested script or workload execution related to batching & scheduling.
1 call · #0104–#0104
python3 - <script>Requested script or workload execution related to source & workspace.
1 call · #0105–#0105
python3 -m <module> <val> -v > <path> <n> >& <path>Requested file and log inspection, source searches and runtime inspection related to benchmark & validation setup.
1 call · #0106–#0106
tail -n <n> <path>rg -n --max-columns <n> <val> <path>tail -n <n>ps <flag> <args>rg <val>cut <flag>Requested script or workload execution, file and log inspection and repository inspection related to attention kernels.
1 call · #0107–#0107
python3 - <script>sed -n <val> <path>git diff --checkRequested file and log inspection, source searches and repository inspection related to device memory.
1 call · #0108–#0108
tail -n <n> <path>wc -l <path>rg -n <val> <path>git diff --numstatRequested workspace inspection, source searches and file and log inspection related to benchmark & validation setup.
3 calls · #0109–#0111
ls -l <path>rg -n --max-columns <n> <val> <path>tail -n <n>python3 - <script>mkdir -p <path>env <vars> python3 <script> > <path> <n> >& <path>Requested file and log inspection related to source & workspace.
1 call · #0112–#0112
sed -n <val> <path>Requested file and log inspection and script or workload execution related to benchmark & validation setup.
1 call · #0113–#0113
tail -n <n> <path>python3 - <script>Requested file and log inspection, runtime inspection and source searches related to benchmark & validation setup.
1 call · #0114–#0114
tail -n <n> <path>ps <flag> <args>rg <val>cut <flag>Requested script or workload execution related to prefix caching.
1 call · #0115–#0115
python3 -m <module> -q <script> <script> <script> > <path> <n> >& <path>Requested script or workload execution related to benchmark & validation setup.
1 call · #0116–#0116
<command> <args>python3 <script> <path> <path> > <path>Requested file and log inspection related to source & workspace.
1 call · #0117–#0117
tail -n <n> <path>Requested source searches and file and log inspection related to attention kernels.
1 call · #0118–#0118
rg --files <val>rg <path>head -n <n>rg -n <val> <path>Requested source searches, file and log inspection and repository inspection related to device memory.
1 call · #0119–#0119
rg -n --max-columns <n> <val> <path>tail -n <n>git diff <path>Requested workspace file updates and script or workload execution related to benchmark & validation setup.
1 call · #0120–#0120
cp <path> <path>python3 - <script>Requested code edits related to source & workspace.
1 call · #0121–#0121
Apply patch <patch>Requested script or workload execution related to benchmark & validation setup.
1 call · #0122–#0122
python3 - <script>Requested file and log inspection, source searches and runtime inspection related to benchmark & validation setup.
2 calls · #0123–#0124
tail -n <n> <path>rg --files <path>sortps <flag> <args>rg <val>Requested file and log inspection related to task requirements.
1 call · #0125–#0125
cat <path>Requested repository inspection and file and log inspection related to source & workspace.
1 call · #0126–#0126
git diff --statsed -n <val> <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0127–#0127
cat <path>tail -n <n> <path>Requested file and log inspection and repository inspection related to attention kernels.
1 call · #0128–#0128
sed -n <val> <path>git diff <flag> <args>Requested runtime inspection and source searches related to runtime processes.
1 call · #0129–#0129
ps <flag> <args>rg <val>Requested source searches and file and log inspection related to benchmark & validation setup.
1 call · #0130–#0130
rg -n <val> <path>tail -n <n>cat <path>tail -n <n> <path>Requested source searches and file and log inspection related to attention kernels.
1 call · #0131–#0131
rg -n <val> <path>head -n <n>tail -n <n>Requested file and log inspection and source searches related to batching & scheduling.
1 call · #0132–#0132
sed -n <val> <path>rg -n <val> <path> <path> <path>Requested runtime inspection, source searches and file and log inspection related to benchmark & validation setup.
1 call · #0133–#0133
command -v <val>ps <flag> <args>rg -n <val> <path>tail -n <n>Requested file and log inspection related to batching & scheduling.
1 call · #0134–#0134
<command> <args>head -n <n> <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0135–#0135
tail -n <n> <path>sed -n <val> <path>Requested source searches and file and log inspection related to source & workspace.
2 calls · #0136–#0137
rg -n <val> <path>sed -n <val> <path>Requested environment setup or inspection and workspace file updates related to benchmark & validation setup.
2 calls · #0138–#0139
env <vars> bash <script> > <path> <n> >& <path>mkdir -p <path>Requested script or workload execution related to runtime processes.
1 call · #0140–#0140
python3 - <script>Requested file and log inspection and repository inspection related to benchmark & validation setup.
1 call · #0141–#0141
tail -n <n> <path>cat <path>git status --shortRequested file and log inspection, source searches and repository inspection related to attention kernels.
3 calls · #0142–#0144
tail -n <n> <path>rg -n <val> <path>tail -n <n>cat <path>git diff <flag> <args>sed -n <val> <path>Requested file and log inspection and source searches related to device memory.
1 call · #0145–#0145
tail -n <n> <path>rg -n <val> <path>head -n <n>Requested script or workload execution related to source & workspace.
1 call · #0146–#0146
python3 <script> > <path> <n> >& <path>Requested source searches and file and log inspection related to device memory.
1 call · #0147–#0147
rg -n <val> <path>head -n <n>sed -n <val> <path>tail -n <n> <path>Requested file and log inspection related to source & workspace.
1 call · #0148–#0148
sed -n <val> <path>Requested file and log inspection and script or workload execution related to attention kernels.
1 call · #0149–#0149
cat > <path> <script>python3 - <script>Requested source searches, file and log inspection and repository inspection related to benchmark & validation setup.
3 calls · #0150–#0152
rg --files <path>sorttail -n <n> <path>wc -l <path>git diff --checkcut <flag>Requested source searches and file and log inspection related to speculative decoding.
1 call · #0153–#0153
rg -n <val> <path>head -n <n>sed -n <val> <path>Requested runtime inspection, source searches and file and log inspection related to device memory.
1 call · #0154–#0154
ps <flag> <args>rg <val>tail -n <n> <path>cut <flag>npu-smi infoRequested script or workload execution, workspace file updates and environment setup or inspection related to benchmark & validation setup.
2 calls · #0155–#0156
python3 -m <module> -q <script> > <path> <n> >& <path>mkdir -p <path>env <vars> bash <script> > <path> <n> >& <path>Requested file and log inspection and source searches related to benchmark & validation setup.
1 call · #0157–#0157
wc -l <path>tail -n <n> <path>rg --files <path>sortRequested file and log inspection and source searches related to attention kernels.
1 call · #0158–#0158
sed -n <val> <path>rg -n <val> <path>head -n <n>tail -n <n> <path>cut <flag>Requested script or workload execution, source searches and file and log inspection related to benchmark & validation setup.
3 calls · #0159–#0161
python3 - <script>rg --files <path>sortwc -l <path>tail -n <n> <path>cut <flag>Requested script or workload execution related to source & workspace.
1 call · #0162–#0162
python3 - <script>Requested workspace file updates, environment setup or inspection and script or workload execution related to benchmark & validation setup.
2 calls · #0163–#0164
mkdir -p <path>env <vars> python3 <script> > <path> <n> >& <path>python3 <script> <path> <path> > <path>cat <path>Requested file and log inspection, source searches and repository inspection related to source & workspace.
1 call · #0165–#0165
tail -n <n> <path>rg --files <path>head -n <n>git diff --statgit diff --numstatRequested script or workload execution, repository inspection and environment setup or inspection related to attention kernels.
1 call · #0166–#0166
python3 - <script>git diff --checkenv <vars> bash <script> > <path> <n> >& <path>Requested file and log inspection, source searches and runtime inspection related to source & workspace.
1 call · #0167–#0167
tail -n <n> <path>rg -n <val> <path>tail -n <n>ps <flag> <args>rg <val>Requested file and log inspection related to attention kernels.
1 call · #0168–#0168
cat <path>sed -n <val> <path><command> <args>Requested file and log inspection and source searches related to source & workspace.
6 calls · #0169–#0174
cat <path>rg -n <val> <path> <path> <path> --glob <path> --glob <val> --glob <val> <args>rg -a -l -F --max-count <n> <val> <path> <path> <path>tail -n <n> <path>rg -n <val> <path>head -n <n>sed -n <val> <path>rg -a -L -l -F --max-count <n> <val> <path> <path> <path>tail -n <n>rg -a -L --no-ignore -l -F --max-count <n> <val> <path> <path> <path>Requested file and log inspection and source searches related to benchmark & validation setup.
1 call · #0175–#0175
tail -n <n> <path>cat <path>rg -n <val> <path>cut <flag>Requested script or workload execution and environment setup or inspection related to source & workspace.
1 call · #0176–#0176
python3 - <script>env <vars> python3 <script> > <path> <n> > <path>Requested source searches related to source & workspace.
1 call · #0177–#0177
rg -a -L --no-ignore -l -F --max-count <n> <val> <path> <path> > <path> <args>Requested source searches and file and log inspection related to attention kernels.
1 call · #0178–#0178
rg -n <val> <path> --glob <path>rg --files <path>head -n <n>cat <path>tail -n <n> <path>Requested source searches and file and log inspection related to source & workspace.
1 call · #0179–#0179
<command> <args>rg -n <val>tail -n <n>rg -n <val> <path> --glob <path> --glob <val> --glob <val>head -n <n>tail -n <n> <path>Requested environment setup or inspection related to attention kernels.
1 call · #0180–#0180
env <vars> python3 -m <module> -q <script> <path> > <path> <n> >& <path>Requested file and log inspection and repository inspection related to attention kernels.
2 calls · #0181–#0182
tail -n <n> <path>sed -n <val> <path>git diff --checkcat <path>git status --shortRequested script or workload execution, repository inspection and environment setup or inspection related to attention kernels.
1 call · #0183–#0183
python3 - <script>git diff --checkenv <vars> bash <script> > <path> <n> >& <path>python3 -m <module> -q <script> > <path> <n> >& <path>Requested file and log inspection and script or workload execution related to attention kernels.
2 calls · #0184–#0185
tail -n <n> <path>sed -n <val> <path>python3 - <script>Requested source searches and file and log inspection related to benchmark & validation setup.
1 call · #0186–#0186
rg --files <path>sorttail -n <n> <path>cut <flag>Requested code edits related to runtime processes.
1 call · #0187–#0187
Apply patch <patch>Requested file and log inspection and repository inspection related to benchmark & validation setup.
2 calls · #0188–#0189
wc -l <path>tail -n <n> <path>cut <flag>git diff --checkdu <flag> <args>Requested file and log inspection and source searches related to task requirements.
1 call · #0190–#0190
wc -l <path>tail -n <n> <path>cut <flag>rg -n <val> <path> <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0191–#0191
wc -l <path>tail -n <n> <path>cut <flag>Requested script or workload execution related to benchmark & validation setup.
1 call · #0192–#0192
python3 -m <module> -q <script> > <path> <n> >& <path>Requested source searches and file and log inspection related to benchmark & validation setup.
1 call · #0193–#0193
rg --files <path>head -n <n>sed -n <val> <path>tail -n <n> <path>wc -l <path>Requested file and log inspection and script or workload execution related to latency & request handling.
1 call · #0194–#0194
wc -l <path>tail -n <n> <path>cut <flag>python3 - <script>Requested file and log inspection and repository inspection related to benchmark & validation setup.
1 call · #0195–#0195
wc -l <path>tail -n <n> <path>cut <flag>sed -n <val> <path>git diff <flag>Requested workspace file updates and environment setup or inspection related to benchmark & validation setup.
1 call · #0196–#0196
mkdir -p <path>env <vars> python3 <script> > <path> <n> >& <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0197–#0197
wc -l <path>tail -n <n> <path>cut <flag>Requested script or workload execution and file and log inspection related to benchmark & validation setup.
1 call · #0198–#0198
python3 <script> <path> <path> > <path>cat <path>Requested code edits related to attention kernels.
1 call · #0199–#0199
Apply patch <patch>Requested script or workload execution related to benchmark & validation setup.
1 call · #0200–#0200
python3 -m <module> -q <script> <script> > <path> <n> >& <path>Requested file and log inspection, runtime inspection and source searches related to benchmark & validation setup.
1 call · #0201–#0201
tail -n <n> <path>ps <flag> <args>rg <val>Requested repository inspection related to attention kernels.
1 call · #0202–#0202
git diff --checkgit diff --statgit diff <flag> <args>Requested script or workload execution and file and log inspection related to benchmark & validation setup.
1 call · #0203–#0203
python3 - <script>wc -l <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0204–#0204
tail -n <n> <path>cut <flag>wc -l <path>Requested source searches and file and log inspection related to speculative decoding.
2 calls · #0205–#0206
rg -n -U <val> <path> <path> <path>head -n <n>rg -n <val> <path> --glob <path>sed -n <val> <path>rg -n <val> <path> <path>tail -n <n> <path>cut <flag>Requested file and log inspection related to benchmark & validation setup.
1 call · #0207–#0207
wc -l <path>tail -n <n> <path>cut <flag>Requested script or workload execution related to latency & request handling.
1 call · #0208–#0208
python3 - <script>Requested file and log inspection related to benchmark & validation setup.
1 call · #0209–#0209
wc -l <path>tail -n <n> <path>cut <flag>Requested workspace file updates, environment setup or inspection and script or workload execution related to benchmark & validation setup.
5 calls · #0210–#0214
mkdir -p <path>env <vars> bash <script> > <path> <n> >& <path>python3 - <script>wc -l <path>env <vars> python3 <script> > <path> <n> >& <path>python3 <script> <path> <path> > <path>cat <path>Requested script or workload execution and source searches related to benchmark & validation setup.
1 call · #0215–#0215
python3 - <script>rg --files <path>sortRequested file and log inspection and source searches related to benchmark & validation setup.
4 calls · #0216–#0219
tail -n <n> <path>cut <flag>rg --files <path>sortdu -h <flag> <args>sort -htail -n <n>rg <val>cat <path>rg <val> <path>Requested source searches and script or workload execution related to benchmark & validation setup.
2 calls · #0220–#0221
rg <val> <path>python3 - <script>rg --files <path>rg <val>Requested file and log inspection and source searches related to attention kernels.
1 call · #0222–#0222
sed -n <val> <path>rg -n <val> <path>head -n <n>Requested file and log inspection and source searches related to benchmark & validation setup.
1 call · #0223–#0223
tail -n <n> <path>cut <flag>rg --files <path>rg <val>Requested file and log inspection and script or workload execution related to benchmark & validation setup.
1 call · #0224–#0224
tail -n <n> <path>cut <flag>python3 - <script>Requested script or workload execution, source searches and file and log inspection related to batching & scheduling.
2 calls · #0225–#0226
python3 - <script>rg --files <path>rg <val>rg -n <val> <path>head -n <n>sed -n <val> <path>Requested file and log inspection related to batching & scheduling.
1 call · #0227–#0227
sed -n <val> <path>Requested source searches and file and log inspection related to prefix caching.
1 call · #0228–#0228
rg -n <val> <path>head -n <n>sed -n <val> <path>tail -n <n> <path>cut <flag>Requested file and log inspection and source searches related to attention kernels.
1 call · #0229–#0229
sed -n <val> <path>rg -n <val> <path> <path>head -n <n>rg -n <val> <path>Requested workspace file updates, environment setup or inspection and script or workload execution related to benchmark & validation setup.
3 calls · #0230–#0232
mkdir -p <path>env <vars> bash <script> > <path> <n> >& <path>python3 - <script>tail -n <n> <path>cut <flag>rg -n <val> <path> <path>head -n <n>rg -n <val> <path>tail -n <n>Requested file and log inspection and source searches related to source & workspace.
1 call · #0233–#0233
sed -n <val> <path>rg -n <val> <path>head -n <n>rg -n <val> <path> <path> <path>Requested script or workload execution and file and log inspection related to benchmark & validation setup.
1 call · #0234–#0234
python3 - <script>bash <script> > <path> <n> >& <path>cat <path>Requested repository inspection, runtime inspection and source searches related to batching & scheduling.
1 call · #0235–#0235
git diff --checkgit status --shortps <flag> <args>rg <val>Requested script or workload execution related to benchmark & validation setup.
1 call · #0236–#0236
python3 - <script>Requested script or workload execution, runtime inspection and repository inspection related to device memory.
1 call · #0237–#0237
python3 - <script>npu-smi infogit diff --check03 / CANDIDATE ARTIFACT
Read code changes as Git diffs. Identifying strings are masked; binary files are listed by their full relative names.
Base commit: 340db9201005fc64635bb25db1d2538f955761c3
@@ -41,11 +41,11 @@ class NPUPagedTokenToKVPoolAllocator(PagedTokenToKVPoolAllocator): ) if num_new_pages is None:- num_new_pages_tensor = (- (seq_lens + self.roundup) // self.page_size- - (prefix_lens + self.roundup) // self.page_size- ).sum()- num_new_pages_item = num_new_pages_tensor.item()+ num_new_pages_item = get_num_new_pages(+ seq_lens=seq_lens_cpu,+ prefix_lens=prefix_lens_cpu,+ page_size=self.page_size,+ ) else: num_new_pages_item = num_new_pages if self.need_sort and num_new_pages_item > len(self.free_pages):@@ -120,12 +120,12 @@ class NPUPagedTokenToKVPoolAllocator(PagedTokenToKVPoolAllocator): if num_new_pages > len(self.free_pages): return None - need_new_pages = (seq_lens % self.page_size == 1).int()- end_new_pages = torch.cumsum(need_new_pages, 0)- start_new_pages = end_new_pages - need_new_pages if num_new_pages == 0: out_indices = last_loc + 1 else:+ need_new_pages = (seq_lens % self.page_size == 1).int()+ end_new_pages = torch.cumsum(need_new_pages, 0)+ start_new_pages = end_new_pages - need_new_pages out_indices = (last_loc + 1) * (1 - need_new_pages) + self.free_pages[ start_new_pages ] * self.page_size * need_new_pages@@ -430,7 +430,18 @@ 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 maintains host lengths. Reading the device+ # tensor here would synchronize the stream before every eager prefill.+ seq_lens_cpu = forward_batch.seq_lens_cpu+ if seq_lens_cpu is None:+ seq_lens_cpu = forward_batch.seq_lens.cpu()+ # Speculative workers can update device lengths independently.+ max_seq_lens = (+ seq_lens_cpu+ if forward_batch.spec_info is None+ else forward_batch.seq_lens+ )+ seq_lens_max = max_seq_lens.max().item() if forward_batch.forward_mode.is_target_verify(): seq_lens_max += self.speculative_num_draft_tokens elif (@@ -440,8 +451,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,18 +460,22 @@ 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) .contiguous() )+ extend_seq_lens_cpu = forward_batch.extend_seq_lens_cpu 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()+ if extend_seq_lens_cpu is None:+ extend_seq_lens_cpu = forward_batch.extend_seq_lens.cpu().tolist()+ self.forward_metadata.extend_seq_lens_cpu_int = torch.tensor(+ extend_seq_lens_cpu, dtype=torch.int32, device="cpu" ) if forward_batch.seq_lens is not None: self.forward_metadata.seq_lens = forward_batch.seq_lens.int()@@ -469,12 +484,12 @@ class AscendAttnBackend(AttentionBackend): self.device ).int() - self.forward_metadata.seq_lens_cpu_int = forward_batch.seq_lens_cpu.int()+ self.forward_metadata.seq_lens_cpu_int = seq_lens_cpu.int() if ( not forward_batch.forward_mode.is_draft_extend_v2() and not forward_batch.forward_mode.is_target_verify() ):- seq_lens_list_cumsum = np.cumsum(forward_batch.extend_seq_lens_cpu)+ seq_lens_list_cumsum = np.cumsum(extend_seq_lens_cpu) self.forward_metadata.seq_lens_list_cumsum = seq_lens_list_cumsum if forward_batch.forward_mode.is_target_verify() and not _is_dflash_verify(@@ -0,0 +1,235 @@+"""Batched QKV normalization and rotary embedding for the NPU backend."""++import torch+import triton+import triton.language as tl+import triton.language.extra.cann.extension as al+from sgl_kernel_npu.norm.split_qkv_rmsnorm_rope import (+ split_qkv_rmsnorm_rope as _split_qkv_rmsnorm_rope,+)+from sgl_kernel_npu.utils.triton_utils import get_device_properties+++@triton.jit+def _split_qkv_rmsnorm_rope_tiled_kernel(+ input_ptr,+ sin_ptr,+ cos_ptr,+ q_ptr,+ k_ptr,+ v_ptr,+ q_weight_ptr,+ k_weight_ptr,+ batch_size,+ Q_SIZE: tl.constexpr,+ KV_SIZE: tl.constexpr,+ HEAD_DIM: tl.constexpr,+ EPS: tl.constexpr,+ BLOCK_ROWS: tl.constexpr,+ Q_HEADS: tl.constexpr,+):+ """Process several tokens per core for full, split-half rotary embedding."""+ row_pid = tl.program_id(0)+ head_pid = tl.program_id(1)+ row_step = tl.num_programs(0) * BLOCK_ROWS+ total_size = Q_SIZE + 2 * KV_SIZE+ dims = tl.arange(0, HEAD_DIM)+ q_dims = tl.arange(0, Q_HEADS * HEAD_DIM)+ rows = tl.arange(0, BLOCK_ROWS)+ q_weight = tl.load(q_weight_ptr + dims).to(tl.float32)+ k_weight = tl.load(k_weight_ptr + dims).to(tl.float32)++ for start in range(row_pid * BLOCK_ROWS, batch_size, row_step):+ row = start + rows+ valid = row[:, None] < batch_size+ sin = tl.load(+ sin_ptr + row[:, None] * HEAD_DIM + dims[None, :],+ mask=valid,+ other=0,+ ).to(tl.float32)+ cos = tl.load(+ cos_ptr + row[:, None] * HEAD_DIM + dims[None, :],+ mask=valid,+ other=0,+ ).to(tl.float32)+ q_cols = head_pid * Q_HEADS * HEAD_DIM + q_dims[None, :]+ q = (+ tl.load(+ input_ptr + row[:, None] * total_size + q_cols,+ mask=valid,+ other=0,+ )+ .to(tl.float32)+ .reshape(BLOCK_ROWS, Q_HEADS, HEAD_DIM)+ )+ q_variance = tl.sum(q * q, axis=2) / HEAD_DIM+ q_inv = (1 / tl.sqrt(q_variance + EPS)).reshape(BLOCK_ROWS, Q_HEADS, 1)+ q_norm = q * q_inv * q_weight[None, None, :]+ q_left = al.extract_slice(+ q_norm,+ offsets=(0, 0, 0),+ sizes=(BLOCK_ROWS, Q_HEADS, HEAD_DIM // 2),+ strides=(1, 1, 1),+ )+ q_right = al.extract_slice(+ q_norm,+ offsets=(0, 0, HEAD_DIM // 2),+ sizes=(BLOCK_ROWS, Q_HEADS, HEAD_DIM // 2),+ strides=(1, 1, 1),+ )+ q_rot = tl.zeros((BLOCK_ROWS, Q_HEADS, HEAD_DIM), dtype=tl.float32)+ q_rot = al.insert_slice(+ q_rot,+ -q_right,+ offsets=(0, 0, 0),+ sizes=(BLOCK_ROWS, Q_HEADS, HEAD_DIM // 2),+ strides=(1, 1, 1),+ )+ q_rot = al.insert_slice(+ q_rot,+ q_left,+ offsets=(0, 0, HEAD_DIM // 2),+ sizes=(BLOCK_ROWS, Q_HEADS, HEAD_DIM // 2),+ strides=(1, 1, 1),+ )+ q_out = q_rot * sin[:, None, :] + q_norm * cos[:, None, :]+ tl.store(+ q_ptr + row[:, None] * Q_SIZE + q_cols,+ q_out.reshape(BLOCK_ROWS, Q_HEADS * HEAD_DIM),+ mask=valid,+ )++ kv_cols = head_pid * HEAD_DIM + dims[None, :]+ k = tl.load(+ input_ptr + row[:, None] * total_size + Q_SIZE + kv_cols,+ mask=valid,+ other=0,+ ).to(tl.float32)+ # Keep each single-head reduction and reciprocal at its original+ # shape to preserve CANN rounding.+ k_inv = tl.zeros((BLOCK_ROWS, 1), dtype=tl.float32)+ for r in tl.static_range(BLOCK_ROWS):+ k_row = al.extract_slice(+ k, offsets=(r, 0), sizes=(1, HEAD_DIM), strides=(1, 1)+ )+ k_variance = tl.sum(k_row * k_row, axis=1) / HEAD_DIM+ inv = (1 / tl.sqrt(k_variance + EPS)).reshape(1, 1)+ k_inv = al.insert_slice(+ k_inv, inv, offsets=(r, 0), sizes=(1, 1), strides=(1, 1)+ )+ k_norm = k * k_inv * k_weight[None, :]+ k_left = al.extract_slice(+ k_norm,+ offsets=(0, 0),+ sizes=(BLOCK_ROWS, HEAD_DIM // 2),+ strides=(1, 1),+ )+ k_right = al.extract_slice(+ k_norm,+ offsets=(0, HEAD_DIM // 2),+ sizes=(BLOCK_ROWS, HEAD_DIM // 2),+ strides=(1, 1),+ )+ k_rot = tl.zeros((BLOCK_ROWS, HEAD_DIM), dtype=tl.float32)+ k_rot = al.insert_slice(+ k_rot,+ -k_right,+ offsets=(0, 0),+ sizes=(BLOCK_ROWS, HEAD_DIM // 2),+ strides=(1, 1),+ )+ k_rot = al.insert_slice(+ k_rot,+ k_left,+ offsets=(0, HEAD_DIM // 2),+ sizes=(BLOCK_ROWS, HEAD_DIM // 2),+ strides=(1, 1),+ )+ k_out = k_rot * sin + k_norm * cos+ tl.store(k_ptr + row[:, None] * KV_SIZE + kv_cols, k_out, mask=valid)+ v = tl.load(+ input_ptr + row[:, None] * total_size + Q_SIZE + KV_SIZE + kv_cols,+ mask=valid,+ other=0,+ )+ tl.store(v_ptr + row[:, None] * KV_SIZE + kv_cols, v, mask=valid)+++def split_qkv_rmsnorm_rope(+ input,+ sin,+ cos,+ q_hidden_size,+ kv_hidden_size,+ head_dim,+ eps=None,+ q_weight=None,+ k_weight=None,+ q_bias=None,+ k_bias=None,+ is_neox_style=True,+):+ """Batch supported BF16 prefills and retain the library's other layouts."""+ batch_size = input.shape[0]+ q_heads_per_kv = q_hidden_size // kv_hidden_size+ if not (+ batch_size >= 128+ and input.dtype == torch.bfloat16+ and eps is not None+ and q_bias is None+ and is_neox_style+ and sin.shape[-1] == head_dim+ and 64 <= head_dim <= 256+ and head_dim == triton.next_power_of_2(head_dim)+ and kv_hidden_size % head_dim == 0+ and q_hidden_size % kv_hidden_size == 0+ and 1 < q_heads_per_kv <= 8+ and q_heads_per_kv == triton.next_power_of_2(q_heads_per_kv)+ and input.is_contiguous()+ and sin.is_contiguous()+ and cos.is_contiguous()+ and q_weight is not None+ and k_weight is not None+ and q_weight.is_contiguous()+ and k_weight.is_contiguous()+ ):+ return _split_qkv_rmsnorm_rope(+ input,+ sin,+ cos,+ q_hidden_size,+ kv_hidden_size,+ head_dim,+ eps=eps,+ q_weight=q_weight,+ k_weight=k_weight,+ q_bias=q_bias,+ k_bias=k_bias,+ is_neox_style=is_neox_style,+ )++ outputs = tuple(+ torch.empty((batch_size, size), device=input.device, dtype=input.dtype)+ for size in (q_hidden_size, kv_hidden_size, kv_hidden_size)+ )+ _, num_vectorcore = get_device_properties()+ n_cols = kv_hidden_size // head_dim+ n_rows = triton.cdiv(num_vectorcore, n_cols)+ # Bound the Q tile to keep live buffers within the vector core UB.+ block_rows = min(16, 4096 // (q_heads_per_kv * head_dim))+ _split_qkv_rmsnorm_rope_tiled_kernel[(n_rows, n_cols)](+ input,+ sin,+ cos,+ *outputs,+ q_weight,+ k_weight,+ batch_size,+ q_hidden_size,+ kv_hidden_size,+ head_dim,+ eps,+ block_rows,+ q_heads_per_kv,+ )+ return outputs@@ -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@@ -56,6 +56,7 @@ class NPUCudaGraphBackend(BaseCudaGraphBackend): self._device_id = self._device_module.current_device() self._tp_group = cuda_graph_runner.model_runner.tp_group self._capture_stream = None+ self._update_executor: Optional[ThreadPoolExecutor] = None self._memory_saver_adapter: Optional[Any] = TorchMemorySaverAdapter.create( enable=enable_memory_saver and get_bool_env_var("SGLANG_MEMORY_SAVER_CUDA_GRAPH")@@ -150,8 +151,9 @@ 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 concurrently with replay using one persistent worker.++ Used when the model is not deepseek-nsa. Two calling conventions: 1. (legacy) seq_lens + attr_name + attr_type:@@ -165,18 +167,30 @@ class NPUCudaGraphBackend(BaseCudaGraphBackend): cpu_update_input = [{attr_name: seq_lens}] 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()+ if self._update_executor is None:+ # Device selection is thread-local. Initialize it once instead of+ # creating a thread and its NPU context for every generated token.+ self._update_executor = ThreadPoolExecutor(+ max_workers=1,+ thread_name_prefix="sglang-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:+ # The NPU update may wait for replay, so join after launching it.+ # result() also propagates update errors to the model worker.+ 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 = None@@ -239,6 +239,8 @@ class NPUGraphRunner(DecodeCudaGraphRunner): is_deepseek_dsa(self.model_runner.model_config.hf_config) or is_deepseek_v4(self.model_runner.model_config.hf_config) ):+ # The device-to-host copy also fences the previous replay before+ # the graph's external update events are reused by the next one. 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)@@ -55,8 +55,9 @@ if _use_aiter: pass if _is_npu:- from sgl_kernel_npu.norm.split_qkv_rmsnorm_rope import split_qkv_rmsnorm_rope-+ from sglang.srt.hardware_backend.npu.attention.qkv_preprocess import (+ split_qkv_rmsnorm_rope,+ ) from sglang.srt.hardware_backend.npu.cmo import get_cmo_stream, wait_cmo_stream @@ -0,0 +1,231 @@+"""Host-side tests for NPU graph updates and paged attention metadata."""++import threading+import unittest+from types import SimpleNamespace+from unittest.mock import Mock, patch++import torch++from sglang.srt.hardware_backend.npu.allocator_npu import (+ NPUPagedTokenToKVPoolAllocator,+)+from sglang.srt.hardware_backend.npu.attention.ascend_backend import AscendAttnBackend+from sglang.srt.hardware_backend.npu.graph_runner.npu_cudagraph_backend import (+ NPUCudaGraphBackend,+)+from sglang.srt.model_executor.forward_batch_info import ForwardMode+++class TestNPUAttentionMetadata(unittest.TestCase):+ def make_backend_and_batch(self):+ backend = AscendAttnBackend.__new__(AscendAttnBackend)+ backend.page_size = 4+ backend.device = "cpu"+ backend.is_hybrid_swa = False+ backend.use_sliding_window_kv_pool = False+ backend.use_mla = False+ # Two requests share a physical prefix page; their suffix pages differ.+ pages = torch.tensor([[9, 3, 14], [6, 2, 8], [9, 7, 11]])+ req_to_token = (pages[:, :, None] * 4 + torch.arange(4)).flatten(1)+ backend.req_to_token_pool = SimpleNamespace(req_to_token=req_to_token)+ batch = SimpleNamespace(+ forward_mode=ForwardMode.EXTEND,+ spec_info=None,+ batch_size=3,+ req_pool_indices=torch.tensor([2, 1, 0]),+ seq_lens=torch.tensor([7, 4, 5]),+ seq_lens_cpu=torch.tensor([7, 4, 5]),+ extend_seq_lens=torch.tensor([3, 4, 1]),+ extend_seq_lens_cpu=[3, 4, 1],+ extend_prefix_lens_cpu=[4, 0, 4],+ )+ return backend, batch++ def test_mixed_prefixes_use_host_lengths(self):+ backend, batch = self.make_backend_and_batch()+ with patch.object(+ torch.Tensor, "cpu", side_effect=AssertionError("unexpected host copy")+ ):+ backend.init_forward_metadata(batch)+ metadata = backend.forward_metadata+ torch.testing.assert_close(+ metadata.block_tables, torch.tensor([[9, 7], [6, 2], [9, 3]])+ )+ torch.testing.assert_close(metadata.seq_lens_cpu_int, batch.seq_lens.int())+ torch.testing.assert_close(+ metadata.extend_seq_lens_cpu_int, batch.extend_seq_lens.int()+ )+ self.assertEqual(list(metadata.seq_lens_list_cumsum), [3, 7, 8])++ def test_missing_extend_mirror_falls_back(self):+ backend, batch = self.make_backend_and_batch()+ batch.extend_seq_lens_cpu = None+ batch.seq_lens_cpu = None+ backend.init_forward_metadata(batch)+ torch.testing.assert_close(+ backend.forward_metadata.extend_seq_lens_cpu_int,+ batch.extend_seq_lens.int(),+ )+ torch.testing.assert_close(+ backend.forward_metadata.seq_lens_cpu_int, batch.seq_lens.int()+ )++ def test_hybrid_sliding_window_maps_shared_and_suffix_pages(self):+ backend, batch = self.make_backend_and_batch()+ backend.is_hybrid_swa = True+ locations = torch.arange(64)+ backend.full_to_swa_index_mapping = (+ (locations // 4 + 5) % 16 * 4 + locations % 4+ )+ backend.init_forward_metadata(batch)+ torch.testing.assert_close(+ backend.forward_metadata.block_tables_swa,+ torch.tensor([[14, 12], [11, 7], [14, 8]], dtype=torch.int32),+ )++ def test_speculative_extent_keeps_device_upper_bound(self):+ backend, batch = self.make_backend_and_batch()+ backend.speculative_step_id = 0+ batch.forward_mode = ForwardMode.DECODE+ batch.spec_info = SimpleNamespace()+ batch.seq_lens = torch.tensor([9, 4, 5])+ backend.init_forward_metadata(batch)+ torch.testing.assert_close(+ backend.forward_metadata.block_tables,+ torch.tensor([[9, 7, 11], [6, 2, 8], [9, 3, 14]]),+ )+++class TestNPUGraphUpdateWorker(unittest.TestCase):+ def setUp(self):+ device = SimpleNamespace(current_device=lambda: 0, set_device=Mock())+ runner = SimpleNamespace(+ device_module=device, model_runner=SimpleNamespace(tp_group=None)+ )+ self.backend = NPUCudaGraphBackend(runner)+ self.addCleanup(self.backend.cleanup)+ self.device = device++ def test_update_and_replay_overlap_and_worker_is_reused(self):+ threads = []+ for lengths in ([17, 32], [18, 33], [6, 0]):+ replay_started = threading.Event()+ update_finished = threading.Event()+ observed = []++ def update(*, cpu_update_input):+ threads.append(threading.current_thread())+ # NPU updates must be allowed to run concurrently with replay.+ if not replay_started.wait(5):+ raise RuntimeError("update was serialized ahead of replay")+ observed.append(cpu_update_input)+ update_finished.set()++ def replay():+ replay_started.set()+ self.assertTrue(update_finished.wait(5))++ graph = SimpleNamespace(update=update, replay=replay)+ self.backend._graphs[2] = graph+ self.backend._outputs[2] = object()+ result = self.backend.replay_with_input_update(+ 2, lengths, attr_name="actual_seq_lengths_kv", attr_type=[]+ )+ self.assertIs(result, self.backend._outputs[2])+ self.assertEqual(observed, [[{"actual_seq_lengths_kv": lengths}]])++ self.assertTrue(all(thread is threads[0] for thread in threads))+ self.assertIsNot(threads[0], threading.current_thread())+ self.device.set_device.assert_called_once_with(0)+ self.backend.cleanup()+ self.assertFalse(threads[0].is_alive())+ # Cleanup is idempotent and the backend can capture/replay again.+ self.backend._graphs[1] = SimpleNamespace(update=Mock(), replay=Mock())+ self.backend._outputs[1] = object()+ self.backend.replay_with_input_update(1, [7], attr_name="actual_seq_lengths_kv")++ def test_update_error_reaches_caller(self):+ self.backend._graphs[1] = SimpleNamespace(+ update=Mock(side_effect=RuntimeError("invalid graph update")),+ replay=Mock(),+ )+ self.backend._outputs[1] = object()+ with self.assertRaisesRegex(RuntimeError, "invalid graph update"):+ self.backend.replay_with_input_update(+ 1, [7], attr_name="actual_seq_lengths_kv"+ )++ def test_speculative_and_tensor_update_conventions(self):+ update = Mock()+ self.backend._graphs[1] = SimpleNamespace(update=update, replay=Mock())+ self.backend._outputs[1] = object()+ steps = [{"actual_seq_lengths_kv": [7]}, {"actual_seq_lengths_kv": [8]}]+ self.backend.replay_with_input_update(1, None, cpu_update_input=steps)+ self.assertEqual(update.call_args.kwargs["cpu_update_input"], steps)+ self.backend.replay_with_input_update(+ 1, [7, 0], attr_name="context_lens", attr_type=torch.empty(0)+ )+ torch.testing.assert_close(+ update.call_args.kwargs["cpu_update_input"][0]["context_lens"],+ torch.tensor([7, 0], dtype=torch.int32),+ )+++class TestNPUDecodeAllocation(unittest.TestCase):+ def make_allocator(self, pages):+ allocator = NPUPagedTokenToKVPoolAllocator.__new__(+ NPUPagedTokenToKVPoolAllocator+ )+ allocator.page_size = 4+ allocator.debug_mode = False+ allocator.need_sort = False+ allocator.free_pages = torch.tensor(pages, dtype=torch.int64)+ allocator.merge_and_sort_free = Mock()+ return allocator++ def test_existing_pages_need_no_page_scan(self):+ allocator = self.make_allocator([10, 12])+ lengths = torch.tensor([3, 8])+ with patch.object(+ torch, "cumsum", side_effect=AssertionError("unneeded page scan")+ ):+ locations = allocator.alloc_decode(lengths, lengths, torch.tensor([21, 42]))+ torch.testing.assert_close(locations, torch.tensor([22, 43], dtype=torch.int32))+ torch.testing.assert_close(allocator.free_pages, torch.tensor([10, 12]))++ def test_mixed_boundary_crossings_allocate_in_request_order(self):+ allocator = self.make_allocator([10, 12, 14])+ lengths = torch.tensor([5, 3, 9])+ locations = allocator.alloc_decode(lengths, lengths, torch.tensor([7, 21, 35]))+ torch.testing.assert_close(+ locations, torch.tensor([40, 22, 48], dtype=torch.int32)+ )+ torch.testing.assert_close(allocator.free_pages, torch.tensor([14]))++ def test_allocation_failure_preserves_free_pages(self):+ allocator = self.make_allocator([10])+ lengths = torch.tensor([5, 9])+ self.assertIsNone(+ allocator.alloc_decode(lengths, lengths, torch.tensor([7, 35]))+ )+ torch.testing.assert_close(allocator.free_pages, torch.tensor([10]))++ def test_extend_admission_uses_cpu_page_counts(self):+ allocator = self.make_allocator([10])+ # Three pages are needed: two after the aligned prefix and one after+ # the partial prefix. Admission must not read any device tensors.+ result = allocator.alloc_extend(+ prefix_lens=object(),+ prefix_lens_cpu=torch.tensor([4, 3]),+ seq_lens=object(),+ seq_lens_cpu=torch.tensor([9, 5]),+ last_loc=None,+ extend_num_tokens=7,+ )+ self.assertIsNone(result)+ torch.testing.assert_close(allocator.free_pages, torch.tensor([10]))+++if __name__ == "__main__":+ unittest.main()@@ -0,0 +1,53 @@+"""QKV preprocessing must not change with the number of rows in a call."""++import pytest+import torch+import torch_npu # noqa: F401++from sglang.srt.hardware_backend.npu.attention.qkv_preprocess import (+ split_qkv_rmsnorm_rope,+)+++@pytest.mark.parametrize(+ "rows,head_dim,q_heads,kv_heads",+ [+ (129, 64, 8, 4),+ (257, 128, 16, 8),+ (513, 256, 8, 2),+ (2049, 128, 8, 8),+ (257, 256, 16, 2),+ (8193, 128, 16, 8),+ ],+)+@pytest.mark.parametrize("norm,bias", [(True, False), (True, True), (False, False)])+def test_qkv_preprocessing_batch_invariance(+ rows, head_dim, q_heads, kv_heads, norm, bias+):+ torch.manual_seed(73)+ device = "npu"+ q_size = q_heads * head_dim+ kv_size = kv_heads * head_dim+ qkv = torch.randn(rows, q_size + 2 * kv_size, device=device, dtype=torch.bfloat16)+ sin = torch.randn(rows, head_dim, device=device, dtype=torch.float32)+ cos = torch.randn(rows, head_dim, device=device, dtype=torch.float32)+ weights = [+ torch.randn(head_dim, device=device, dtype=torch.bfloat16) for _ in range(4)+ ]+ kwargs = dict(+ eps=1e-6 if norm else None,+ q_weight=weights[0] if norm else None,+ k_weight=weights[1] if norm else None,+ q_bias=weights[2] if bias else None,+ k_bias=weights[3] if bias else None,+ )+ actual = split_qkv_rmsnorm_rope(qkv, sin, cos, q_size, kv_size, head_dim, **kwargs)+ # Irregular small batches exercise a different tiling and all tail masks.+ parts = [+ split_qkv_rmsnorm_rope(x, s, c, q_size, kv_size, head_dim, **kwargs)+ for x, s, c in zip(qkv.split(31), sin.split(31), cos.split(31))+ ]+ expected = [torch.cat(tensors) for tensors in zip(*parts)]+ for full, partitioned in zip(actual, expected):+ torch.testing.assert_close(full, partitioned, rtol=0, atol=0)+ torch.testing.assert_close(actual[2], qkv[:, q_size + kv_size :], rtol=0, atol=0)