Inspect · Task requirements
1 tool errorRequested workspace inspection and source searches related to task requirements.
1 call · #0001–#0001
pwdrg --files -g <val> -g <path> <path> <path> <n> > <path>GPT-6 Astra · Training
Qwen3-4B CodeOpt TP2 training 2dev · 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 · 278 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 source searches related to task requirements.
1 call · #0001–#0001
pwdrg --files -g <val> -g <path> <path> <path> <n> > <path>Requested environment setup or inspection related to source & workspace.
1 call · #0002–#0002
printenv <vars>Requested file and log inspection, repository inspection and source searches related to task requirements.
4 calls · #0003–#0006
cat <path> <path><command> <args>git status --shortrg --files -g <val> -g <val> -g <val> -g <val> -g <val> <args>head -n <n>rg --files -g <val> -g <val> -g <val> -g <val>Requested file and log inspection related to benchmark & validation setup.
1 call · #0007–#0007
cat <path> <path> <path> <path> <path>Requested file and log inspection related to checkpoints & weight state.
1 call · #0008–#0008
cat <path> <path> <path> <path> <path>Requested file and log inspection related to source & workspace.
1 call · #0009–#0009
cat <path>Requested source searches and workspace inspection related to task requirements.
1 call · #0010–#0010
rg --files --hidden -g <val> -g <path> <path> <path>ls -l -a <path>Requested source searches related to checkpoints & weight state.
1 call · #0011–#0011
rg -n <val> <path>Requested source searches and file and log inspection related to source & workspace.
1 call · #0012–#0012
rg --files <val> <val>head -n <n>Requested script or workload execution related to source & workspace.
1 call · #0013–#0013
bash <script>Requested file and log inspection and source searches related to source & workspace.
3 calls · #0014–#0016
sed -n <val> <path>rg -n <val> <val>Requested file and log inspection related to benchmark & validation setup.
1 call · #0017–#0017
tail -n <n> <path>Requested source searches and file and log inspection related to attention kernels.
1 call · #0018–#0018
rg -n <val> <path> <path> <path>head -n <n>Requested file and log inspection and source searches related to parallelism & communication.
1 call · #0019–#0019
sed -n <val> <path>rg -n <val> <val> <path>head -n <n>Requested runtime inspection, source searches and workspace inspection related to device memory.
1 call · #0020–#0020
ps <flag> <args>rg <val>ls -l -h <val>npu-smi infoRequested file and log inspection related to attention kernels.
3 calls · #0021–#0023
cat <path>sed -n <val> <path>cat <path> <path>Requested file and log inspection and source searches related to benchmark & validation setup.
1 call · #0024–#0024
tail -n <n> <path>rg --files <val>sortRequested source searches and file and log inspection related to parallelism & communication.
1 call · #0025–#0025
rg -n <val> <path> <path>sed -n <val> <path>Requested file and log inspection and source searches related to benchmark & validation setup.
1 call · #0026–#0026
tail -n <n> <path>rg --files <path>head -n <n>Requested source searches and file and log inspection related to attention kernels.
3 calls · #0027–#0029
rg -n <val> <path> <path> -g <path>head -n <n>sed -n <val> <path>rg -n <val> <path>cat <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0030–#0030
tail -n <n> <path>Requested file and log inspection and source searches related to parallelism & communication.
1 call · #0031–#0031
cat <path>sed -n <val> <path>rg -n <val> <path> <path> -g <path>Requested file and log inspection and source searches related to benchmark & validation setup.
1 call · #0032–#0032
tail -n <n> <path>rg -n <val> <path>tail -n <n>cat <path>head -n <n>Requested source searches and file and log inspection related to attention kernels.
1 call · #0033–#0033
rg -n <val> <path> <path> <path>cat <path>sed -n <val> <path>Requested runtime inspection, source searches and file and log inspection related to dependencies & build setup.
1 call · #0034–#0034
ps <flag> <args>rg <val>head -n <n>tail -n <n> <path>Requested file and log inspection and source searches related to parallelism & communication.
1 call · #0035–#0035
cat <path>rg --files <path>rg <val>head -n <n>Requested source searches and file and log inspection related to attention kernels.
2 calls · #0036–#0037
rg -n <val> <path> <path> <path>sed -n <val> <path>cat <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0038–#0038
tail -n <n> <path>du <flag> <args>Requested file and log inspection and workspace inspection related to checkpoints & weight state.
2 calls · #0039–#0040
tail -n <n> <path>tail -n <n> <path> <n> > <path>du <flag> <args>df -h <path> <path>ls -l -h <path> <n> > <path>Requested file and log inspection and source searches related to parallelism & communication.
1 call · #0041–#0041
sed -n <val> <path>rg -n <val> <path> <path>Requested file and log inspection, runtime inspection and source searches related to benchmark & validation setup.
1 call · #0042–#0042
tail -n <n> <path>tail -n <n> <path> <n> > <path>ps <flag> <args>rg <val>cut -c <val>Requested source searches and file and log inspection related to checkpoints & weight state.
1 call · #0043–#0043
rg -n <val> <path> <path> <path>head -n <n>rg -n <val> <path> <path>Requested source searches and file and log inspection related to optimizer & gradients.
1 call · #0044–#0044
rg -n <val> <path>sed -n <val> <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0045–#0045
tail -n <n> <path>tail -n <n> <path> <n> > <path>cat <path> <n> > <path>Requested file and log inspection and source searches related to optimizer & gradients.
1 call · #0046–#0046
sed -n <val> <path>rg -n <val> <path> <val>Requested file and log inspection related to checkpoints & weight state.
3 calls · #0047–#0049
du <flag> <args>tail -n <n> <path>tail -n <n> <path> <n> > <path>Requested file and log inspection and source searches related to parallelism & communication.
1 call · #0050–#0050
sed -n <val> <path>rg -n <val> <path>head -n <n>Requested file and log inspection and workspace inspection related to benchmark & validation setup.
1 call · #0051–#0051
tail -n <n> <path> <n> > <path>ls -l -h <path> <n> > <path>Requested file and log inspection related to benchmark & validation setup.
2 calls · #0052–#0053
tail -n <n> <path>Requested source searches and file and log inspection related to optimizer & gradients.
1 call · #0054–#0054
rg -n <val> <path> <path>head -n <n>sed -n <val> <path>Requested file and log inspection, runtime inspection and source searches related to benchmark & validation setup.
2 calls · #0055–#0056
tail -n <n> <path>ps <flag> <args>rg <path>cut -c <val>head -n <n>Requested script or workload execution related to benchmark & validation setup.
2 calls · #0057–#0058
bash <script> > <path> <n> >& <path>python3 - <script>Requested source searches and file and log inspection related to source & workspace.
1 call · #0059–#0059
rg -n <val> <path> <path>head -n <n>rg -n <val> <path> <path> <path>Requested source searches and file and log inspection related to attention kernels.
1 call · #0060–#0060
rg --files <val>rg <path>head -n <n>rg -n <val> <path> <path> <path>Requested file and log inspection and source searches related to source & workspace.
1 call · #0061–#0061
sed -n <val> <path>rg -n <val> <val>head -n <n>Requested script or workload execution related to source & workspace.
1 call · #0062–#0062
python3 - <script>Requested file and log inspection related to benchmark & validation setup.
1 call · #0063–#0063
tail -n <n> <path>tail -n <n> <path> <n> > <path>Requested file and log inspection related to benchmark & validation setup.
2 calls · #0064–#0065
tail -n <n> <path>Requested file and log inspection related to source & workspace.
1 call · #0066–#0066
cat > <path> <script>Requested file and log inspection and source searches related to benchmark & validation setup.
1 call · #0067–#0067
tail -n <n> <path>tail -n <n> <path> <n> > <path>rg --files <path> <n> > <path>head -n <n>Requested file and log inspection related to source & workspace.
1 call · #0068–#0068
tail -n <n> <path> <n> > <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0069–#0069
tail -n <n> <path>Requested file and log inspection related to source & workspace.
1 call · #0070–#0070
sed -n <val> <path>tail -n <n> <path>cat <path>Requested source searches and file and log inspection related to runtime processes.
1 call · #0071–#0071
rg -n <val> <path> <path>sed -n <val> <path>rg -n <val> <path>Requested file and log inspection, source searches and script or workload execution related to source & workspace.
3 calls · #0072–#0074
tail -n <n> <path>rg --files <path> <n> > <path>head -n <n>cat > <path> <script>rg --files <path>rg <val>python3 - <script>Requested script or workload execution related to benchmark & validation setup.
1 call · #0075–#0075
python3 - <script>Requested script or workload execution related to attention kernels.
1 call · #0076–#0076
python3 - <script>Requested code edits related to attention kernels.
1 call · #0077–#0077
Apply patch <patch>Requested environment setup or inspection related to source & workspace.
1 call · #0078–#0078
env <vars> python3 <script> > <path> <n> >& <path>Requested code edits related to attention kernels.
1 call · #0079–#0079
Apply patch <patch>Requested file and log inspection related to source & workspace.
1 call · #0080–#0080
cat <path>Requested source searches and file and log inspection related to parallelism & communication.
1 call · #0081–#0081
rg -n <val> <path> <path> <path>head -n <n>rg --files <val>rg <val>cat <path>Requested file and log inspection and repository inspection related to attention kernels.
1 call · #0082–#0082
tail -n <n> <path>git diff --checkgit diff --statcat <path>head -n <n>Requested file and log inspection related to parallelism & communication.
1 call · #0083–#0083
cat <path> <path>sed -n <val> <path>Requested repository inspection, file and log inspection and source searches related to attention kernels.
1 call · #0084–#0084
git status --shorttail -n <n> <path>rg -n <val> <path> <path>Requested environment setup or inspection related to attention kernels.
1 call · #0085–#0085
env <vars> python3 -m <module> -q <script> > <path> <n> >& <path>Requested file and log inspection related to attention kernels.
1 call · #0086–#0086
tail -n <n> <path>Requested environment setup or inspection related to source & workspace.
1 call · #0087–#0087
env <vars> python3 <script> > <path> <n> >& <path>Requested file and log inspection and source searches related to parallelism & communication.
2 calls · #0088–#0089
tail -n <n> <path>sed -n <val> <path>rg -n <val> <path>rg -n <val> <path> <path>Requested file and log inspection and source searches related to attention kernels.
1 call · #0090–#0090
tail -n <n> <path>rg -n <val> <path>head -n <n>sed -n <val> <path>Requested file and log inspection and source searches related to parallelism & communication.
1 call · #0091–#0091
cat <path>rg -n <val> <path> <val>sed -n <val> <path>rg -n <val> <path>Requested environment setup or inspection related to attention kernels.
1 call · #0092–#0092
env <vars> python3 -m <module> -q <script> <script> > <path> <n> >& <path>Requested file and log inspection and repository inspection related to attention kernels.
2 calls · #0093–#0094
tail -n <n> <path>git diff --checksed -n <val> <path>Requested file and log inspection related to parallelism & communication.
1 call · #0095–#0095
cat > <path> <script>tail -n <n> <path>Requested source searches and file and log inspection related to parallelism & communication.
1 call · #0096–#0096
rg -n <val> <path>sed -n <val> <path>Requested script or workload execution related to source & workspace.
1 call · #0097–#0097
python3 - <script>Requested file and log inspection related to benchmark & validation setup.
1 call · #0098–#0098
tail -n <n> <path>Requested file and log inspection and source searches related to attention kernels.
3 calls · #0099–#0101
sed -n <val> <path>rg -n <val> <path> <path>cat <path>head -n <n>Requested script or workload execution related to checkpoints & weight state.
1 call · #0102–#0102
python3 - <script>Requested script or workload execution related to source & workspace.
1 call · #0103–#0103
bash <script>Requested code edits related to attention kernels.
1 call · #0104–#0104
Apply patch <patch>Requested repository inspection related to source & workspace.
1 call · #0105–#0105
git diff --checkgit diff --statRequested repository inspection, source searches and file and log inspection related to attention kernels.
2 calls · #0106–#0107
git diff <flag> <args>rg -n <val> <path> -g <path>head -n <n>sed -n <val> <path>tail -n <n> <path>Requested environment setup or inspection related to attention kernels.
1 call · #0108–#0108
env <vars> python3 -m <module> -q <script> > <path> <n> >& <path>Requested runtime inspection and file and log inspection related to attention kernels.
2 calls · #0109–#0110
npu-smi info -t <val>tail -n <n> <path>head -n <n> <path>Requested code edits related to attention kernels.
1 call · #0111–#0111
Apply patch <patch>Requested environment setup or inspection related to attention kernels.
1 call · #0112–#0112
env <vars> python3 -m <module> -q <script> > <path> <n> >& <path>Requested file and log inspection related to attention kernels.
1 call · #0113–#0113
tail -n <n> <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0114–#0114
tail -n <n> <path>Requested script or workload execution related to source & workspace.
1 call · #0115–#0115
python3 - <script>Requested source searches and file and log inspection related to parallelism & communication.
1 call · #0116–#0116
rg -n <val> <path> <path>head -n <n>sed -n <val> <path>Requested script or workload execution related to source & workspace.
1 call · #0117–#0117
python3 - <script>Requested source searches and file and log inspection related to parallelism & communication.
1 call · #0118–#0118
rg --files <path>rg <val>rg -n <val> <path>sed -n <val> <path>Requested file and log inspection related to checkpoints & weight state.
1 call · #0119–#0119
tail -n <n> <path>du <flag> <args>Requested source searches and file and log inspection related to parallelism & communication.
2 calls · #0120–#0121
rg -n <val> <path> <path> <path> -g <val> -g <path> -g <val>head -n <n>rg -n <val> <path> <path> -g <path>rg -n <val> <path> <path> -g <val> -g <val> -g <path>sed -n <val> <path>Requested file and log inspection related to parallelism & communication.
1 call · #0122–#0122
cat > <path> <script>tail -n <n> <path>tail -n <n> <path> <n> > <path>Requested file and log inspection and source searches related to parallelism & communication.
1 call · #0123–#0123
sed -n <val> <path>rg -n <val> <path> <path>rg -n <val> <path>cat <path>Requested script or workload execution related to attention kernels.
1 call · #0124–#0124
bash <script> > <path> <n> >& <path>Requested file and log inspection related to attention kernels.
1 call · #0125–#0125
tail -n <n> <path>Requested source searches related to parallelism & communication.
1 call · #0126–#0126
rg -n <val> <path> <path>Requested file and log inspection related to source & workspace.
1 call · #0127–#0127
sed -n <val> <path>Requested file and log inspection related to parallelism & communication.
1 call · #0128–#0128
sed -n <val> <path>Requested file and log inspection and source searches related to benchmark & validation setup.
1 call · #0129–#0129
sed -n <val> <path>rg -n <val> <path>Requested repository inspection, file and log inspection and source searches related to source & workspace.
2 calls · #0130–#0131
git diff --statsed -n <val> <path>rg -n <val> <path>Requested script or workload execution related to checkpoints & weight state.
1 call · #0132–#0132
python3 - <script>Requested repository inspection and file and log inspection related to attention kernels.
1 call · #0133–#0133
git diff <flag> <args>sed -n <val> <path>Requested file and log inspection and source searches related to parallelism & communication.
1 call · #0134–#0134
sed -n <val> <path>rg -n <val> <val>Requested file and log inspection related to source & workspace.
1 call · #0135–#0135
tail -n <n> <path>Requested file and log inspection and source searches related to parallelism & communication.
1 call · #0136–#0136
sed -n <val> <path>rg -n <val> <path>Requested file and log inspection related to source & workspace.
1 call · #0137–#0137
tail -n <n> <path>Requested file and log inspection and source searches related to parallelism & communication.
1 call · #0138–#0138
cat <path>sed -n <val> <path>rg -n <val> <path> <path>Requested file and log inspection related to attention kernels.
1 call · #0139–#0139
sed -n <val> <path>cat <path>Requested file and log inspection related to task requirements.
1 call · #0140–#0140
cat <path>Requested file and log inspection related to source & workspace.
1 call · #0141–#0141
tail -n <n> <path>Requested file and log inspection and source searches related to parallelism & communication.
5 calls · #0142–#0146
sed -n <val> <path>rg -n <val> <val>tail -n <n> <path>rg -n <val> <path>head -n <n>cat <path>Requested file and log inspection and source searches related to attention kernels.
2 calls · #0147–#0148
sed -n <val> <path>rg -n <val> <path>rg -n <val> <path> <path> <path>Requested file and log inspection related to parallelism & communication.
1 call · #0149–#0149
tail -n <n> <path>Requested script or workload execution related to parallelism & communication.
1 call · #0150–#0150
python3 - <script>Requested source searches related to attention kernels.
1 call · #0151–#0151
rg --files <val>rg <val>Requested file and log inspection and source searches related to parallelism & communication.
2 calls · #0152–#0153
tail -n <n> <path>rg -n <val> <path>sed -n <val> <path>rg -n <val> <path> <path>Requested source searches and file and log inspection related to attention kernels.
1 call · #0154–#0154
rg -n <val> <path>sed -n <val> <path>Requested file and log inspection related to parallelism & communication.
1 call · #0155–#0155
sed -n <val> <path>cat <path>Requested source searches related to source & workspace.
1 call · #0156–#0156
rg -n <val> <path> <path> <path>Requested file and log inspection related to attention kernels.
1 call · #0157–#0157
tail -n <n> <path>Requested source searches and file and log inspection related to source & workspace.
1 call · #0158–#0158
rg -n <val> <val> <path>head -n <n>Requested source searches and file and log inspection related to benchmark & validation setup.
1 call · #0159–#0159
rg -n <val> <path> <path>head -n <n>rg -n <val> <path>tail -n <n>Requested file and log inspection related to attention kernels.
1 call · #0160–#0160
tail -n <n> <path>Requested source searches and file and log inspection related to source & workspace.
1 call · #0161–#0161
rg -n -i -C <n> <val> <path>rg -n -i <val> <path> <path> <n> > <path>head -n <n>Requested script or workload execution related to source & workspace.
1 call · #0162–#0162
python3 - <script>Requested file and log inspection and source searches related to parallelism & communication.
1 call · #0163–#0163
sed -n <val> <path>rg -n -A <n> <val> <path> <path>Requested source searches and file and log inspection related to benchmark & validation setup.
1 call · #0164–#0164
rg -n -A <n> <val> <path>tail -n <n> <path>Requested file and log inspection and source searches related to source & workspace.
1 call · #0165–#0165
sed -n <val> <path>rg -n <val> <path> <path>Requested source searches and file and log inspection related to parallelism & communication.
1 call · #0166–#0166
rg --files <path>rg <val>head -n <n>Requested source searches related to source & workspace.
1 call · #0167–#0167
rg -n <val> <val>Requested file and log inspection related to parallelism & communication.
2 calls · #0168–#0169
cat > <path> <script>sed -n <val> <path>Requested file and log inspection related to attention kernels.
1 call · #0170–#0170
tail -n <n> <path>Requested script or workload execution related to source & workspace.
1 call · #0171–#0171
python3 - <script>Requested script or workload execution related to attention kernels.
1 call · #0172–#0172
bash <script> > <path> <n> >& <path>Requested file and log inspection related to parallelism & communication.
1 call · #0173–#0173
cat > <path> <script>Requested file and log inspection related to attention kernels.
1 call · #0174–#0174
tail -n <n> <path>Requested script or workload execution related to attention kernels.
1 call · #0175–#0175
python3 - <script>Requested code edits related to source & workspace.
1 call · #0176–#0176
Apply patch <patch>Requested file and log inspection related to source & workspace.
1 call · #0177–#0177
tail -n <n> <path>Requested repository inspection and file and log inspection related to parallelism & communication.
1 call · #0178–#0178
git diff --checkgit status --shortsed -n <val> <path>Requested source searches and file and log inspection related to attention kernels.
1 call · #0179–#0179
rg --files <val>rg <val>head -n <n>rg --files <path>Requested file and log inspection related to source & workspace.
1 call · #0180–#0180
sed -n <val> <path>tail -n <n> <path>Requested source searches and file and log inspection related to attention kernels.
1 call · #0181–#0181
rg --files <path> <path>rg <path>head -n <n>rg --files <val>rg <val>Requested file and log inspection related to source & workspace.
1 call · #0182–#0182
tail -n <n> <path>Requested runtime inspection, source searches and file and log inspection related to benchmark & validation setup.
1 call · #0183–#0183
ps <flag> <args>rg <val>head -n <n>tail -n <n> <path>Requested file and log inspection related to attention kernels.
1 call · #0184–#0184
sed -n <val> <path>Requested script or workload execution related to parallelism & communication.
1 call · #0185–#0185
python3 - <script>Requested file and log inspection, source searches and repository inspection related to source & workspace.
2 calls · #0186–#0187
tail -n <n> <path>rg -n <val> <path>git diff --checkRequested file and log inspection related to benchmark & validation setup.
1 call · #0188–#0188
tail -n <n> <path>Requested source searches and file and log inspection related to optimizer & gradients.
1 call · #0189–#0189
rg -n <val> <val> -g <val>head -n <n>rg -n <val> <path>Requested source searches and file and log inspection related to parallelism & communication.
2 calls · #0190–#0191
rg -n -A <n> -B <n> <val> <path>sed -n <val> <path>rg -n <val> <path>head -n <n>rg -n <val> <path> <path>Requested source searches and file and log inspection related to benchmark & validation setup.
1 call · #0192–#0192
rg -n <val> <path>head -n <n>tail -n <n> <path>Requested source searches and file and log inspection related to source & workspace.
1 call · #0193–#0193
rg -n <val> <path> <path>cat <path>head -n <n>Requested file and log inspection and source searches related to optimizer & gradients.
1 call · #0194–#0194
cat <path>rg -n <val> <path> <path>Requested source searches and file and log inspection related to parallelism & communication.
1 call · #0195–#0195
rg -n -A <n> <val> <path>cat <path>head -n <n>Requested script or workload execution related to benchmark & validation setup.
1 call · #0196–#0196
bash <script> > <path> <n> >& <path>Requested script or workload execution related to source & workspace.
1 call · #0197–#0197
bash <script> > <path> <n> >& <path>Requested code edits related to parallelism & communication.
1 call · #0198–#0198
Apply patch <patch>Requested script or workload execution related to parallelism & communication.
1 call · #0199–#0199
python3 - <script>Requested file and log inspection and repository inspection related to source & workspace.
1 call · #0200–#0200
tail -n <n> <path>cat <path>git diff --checkRequested file and log inspection and source searches related to optimizer & gradients.
1 call · #0201–#0201
sed -n <val> <path>cat <path> <n> > <path>rg -n <val> <path> <path>Requested environment setup or inspection related to parallelism & communication.
1 call · #0202–#0202
env <vars> python3 - <script>Requested file and log inspection and source searches related to source & workspace.
1 call · #0203–#0203
tail -n <n> <path>rg --files <val>rg <val>head -n <n>Requested script or workload execution related to benchmark & validation setup.
1 call · #0204–#0204
python3 - <script>Requested source searches and file and log inspection related to source & workspace.
1 call · #0205–#0205
rg -n -i <val> <path>head -n <n>sed -n <val> <path>rg -n <val> <val> -g <path>Requested source searches and file and log inspection related to attention kernels.
1 call · #0206–#0206
rg -n <val> <path>head -n <n>Requested workspace file updates and file and log inspection related to parallelism & communication.
1 call · #0207–#0207
mkdir -p <path>cat > <path> <script>Requested file and log inspection related to benchmark & validation setup.
1 call · #0208–#0208
tail -n <n> <path>Requested file and log inspection related to source & workspace.
1 call · #0209–#0209
sed -n <val> <path>Requested file and log inspection related to optimizer & gradients.
1 call · #0210–#0210
cat > <path> <script>Requested file and log inspection related to benchmark & validation setup.
2 calls · #0211–#0212
tail -n <n> <path>Requested source searches related to parallelism & communication.
1 call · #0213–#0213
rg -n <val> <path> <path> <path> <path>Requested file and log inspection related to benchmark & validation setup.
3 calls · #0214–#0216
tail -n <n> <path>Requested file and log inspection and repository inspection related to source & workspace.
1 call · #0217–#0217
sed -n <val> <path>git diff --statgit diff --checkRequested script or workload execution related to benchmark & validation setup.
1 call · #0218–#0218
bash <script> > <path> <n> >& <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0219–#0219
tail -n <n> <path>Requested script or workload execution related to checkpoints & weight state.
1 call · #0220–#0220
python3 - <script>Requested source searches and file and log inspection related to optimizer & gradients.
1 call · #0221–#0221
rg -n -A <n> <val> <path>tail -n <n> <path>Requested repository inspection related to source & workspace.
1 call · #0222–#0222
git diff <flag> <args>git diff --checkgit status --shortRequested script or workload execution related to attention kernels.
1 call · #0223–#0223
python3 - <script>Requested file and log inspection related to optimizer & gradients.
1 call · #0224–#0224
tail -n <n> <path>Requested script or workload execution related to source & workspace.
1 call · #0225–#0225
python3 - <script>Requested file and log inspection related to benchmark & validation setup.
1 call · #0226–#0226
tail -n <n> <path>Requested source searches and file and log inspection related to attention kernels.
1 call · #0227–#0227
rg -n <val> <path>head -n <n>tail -n <n> <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0228–#0228
tail -n <n> <path>Requested repository inspection and source searches related to source & workspace.
1 call · #0229–#0229
git diff --checkgit diff --numstatrg -n <val> <path> <path>Requested file and log inspection related to dependencies & build setup.
1 call · #0230–#0230
sed -n <val> <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0231–#0231
tail -n <n> <path>Requested file and log inspection related to checkpoints & weight state.
1 call · #0232–#0232
cat > <path> <script>Requested script or workload execution related to optimizer & gradients.
1 call · #0233–#0233
python3 - <script>Requested file and log inspection related to benchmark & validation setup.
1 call · #0234–#0234
tail -n <n> <path>Requested script or workload execution related to optimizer & gradients.
1 call · #0235–#0235
python3 - <script>Requested code edits related to optimizer & gradients.
1 call · #0236–#0236
Apply patch <patch>Requested script or workload execution related to optimizer & gradients.
1 call · #0237–#0237
python3 - <script>Requested file and log inspection related to optimizer & gradients.
1 call · #0238–#0238
tail -n <n> <path>Requested repository inspection related to source & workspace.
2 calls · #0239–#0240
git diff --checkgit diff --statgit status --shortRequested file and log inspection related to optimizer & gradients.
1 call · #0241–#0241
tail -n <n> <path>Requested source searches and file and log inspection related to task requirements.
1 call · #0242–#0242
rg --files <path>sed -n <val> <path>rg -n <val> <path>head -n <n>Requested environment setup or inspection related to attention kernels.
2 calls · #0243–#0244
env <vars> python3 -m <module> -q <script> <script> > <path> <n> >& <path>env <vars> python3 -m <module> -q <script> > <path> <n> >& <path>Requested file and log inspection related to attention kernels.
1 call · #0245–#0245
tail -n <n> <path>Requested file and log inspection related to benchmark & validation setup.
1 call · #0246–#0246
tail -n <n> <path>Requested source searches, file and log inspection and script or workload execution related to optimizer & gradients.
2 calls · #0247–#0248
rg -n <val> <path> <path> <path> <n> > <path>tail -n <n> <path>bash <script> > <path> <n> >& <path>Requested file and log inspection related to optimizer & gradients.
1 call · #0249–#0249
tail -n <n> <path>Requested script or workload execution related to checkpoints & weight state.
1 call · #0250–#0250
python3 - <script>Requested file and log inspection related to benchmark & validation setup.
1 call · #0251–#0251
tail -n <n> <path>Requested script or workload execution related to runtime processes.
1 call · #0252–#0252
python3 - <script>Requested file and log inspection related to benchmark & validation setup.
2 calls · #0253–#0254
tail -n <n> <path>Requested file and log inspection related to runtime processes.
1 call · #0255–#0255
cat > <path> <script>Requested file and log inspection related to benchmark & validation setup.
1 call · #0256–#0256
tail -n <n> <path>Requested script or workload execution related to benchmark & validation setup.
1 call · #0257–#0257
python3 - <script>Requested script or workload execution related to attention kernels.
1 call · #0258–#0258
python3 - <script>Requested file and log inspection and source searches related to source & workspace.
2 calls · #0259–#0260
sed -n <val> <path>rg -n <val> <path> -g <path>rg <val> <path>tail -n <n>tail -n <n> <path>Requested script or workload execution related to optimizer & gradients.
1 call · #0261–#0261
python3 - <script>Requested source searches and file and log inspection related to source & workspace.
1 call · #0262–#0262
rg <val> <path>tail -n <n>tail -n <n> <path>Requested code edits related to source & workspace.
1 call · #0263–#0263
Apply patch <patch>Requested repository inspection related to source & workspace.
1 call · #0264–#0264
git diff --checkgit diff <flag> <args>Requested source searches and file and log inspection related to benchmark & validation setup.
3 calls · #0265–#0267
rg <path> <path>tail -n <n> <path>Requested script or workload execution related to benchmark & validation setup.
1 call · #0268–#0268
bash <script> > <path> <n> >& <path>Requested file and log inspection related to benchmark & validation setup.
5 calls · #0269–#0273
tail -n <n> <path>Requested file and log inspection and script or workload execution related to benchmark & validation setup.
1 call · #0274–#0274
tail -n <n> <path>python3 - <script>Requested script or workload execution related to checkpoints & weight state.
1 call · #0275–#0275
python3 - <script>Requested file and log inspection and repository inspection related to benchmark & validation setup.
1 call · #0276–#0276
tail -n <n> <path>git diff --checkRequested repository inspection related to source & workspace.
1 call · #0277–#0277
git diff --checkgit status --shortRequested script or workload execution related to checkpoints & weight state.
1 call · #0278–#0278
python3 - <script>03 / CANDIDATE ARTIFACT
Read code changes as Git diffs. Identifying strings are masked; binary files are listed by their full relative names.
Base commit: df2ea7fad8e43016b0e2edbf7ce16026496df2ae
@@ -1,6 +1,6 @@ # Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. # Copyright (c) 2025, Huawei Technologies Co., Ltd. All rights reserved.-from functools import wraps+from functools import lru_cache, wraps from typing import Optional import logging @@ -24,6 +24,35 @@ except ImportError: HAVE_APPLY_ROPE_FUSION = False +def _compute_rotary_cos_sin(freqs, dtype, mscale):+ return (torch.cos(freqs) * mscale).to(dtype), (torch.sin(freqs) * mscale).to(dtype)+++@lru_cache(maxsize=8)+def _cached_rotary_cos_sin(freqs, dtype, mscale, version, stream):+ # The version invalidates entries after in-place frequency updates. The stream+ # keeps asynchronous device results local to the stream that produced them.+ return _compute_rotary_cos_sin(freqs, dtype, mscale)+++def _get_rotary_cos_sin(freqs, dtype, mscale):+ # Learned frequencies need a fresh autograd graph. Inference tensors do not+ # track versions, and tensors created in inference mode cannot be saved for+ # a subsequent training backward pass.+ if (+ freqs.requires_grad+ or torch.is_inference_mode_enabled()+ or freqs.is_inference()+ or not isinstance(mscale, (int, float))+ ):+ return _compute_rotary_cos_sin(freqs, dtype, mscale)++ stream = None+ device_module = getattr(torch, freqs.device.type, None)+ if device_module is not None and hasattr(device_module, "current_stream"):+ stream = device_module.current_stream(freqs.device)+ return _cached_rotary_cos_sin(freqs, dtype, mscale, freqs._version, stream)+ def apply_rotary_pos_emb_bshd( t: Tensor,@@ -61,9 +90,12 @@ def apply_rotary_pos_emb_bshd( t = torch.cat((x1, x2), dim=-1) rot_dim = freqs.shape[-1]- t, t_pass = t[..., :rot_dim], t[..., rot_dim:]- cos_ = (torch.cos(freqs) * _mscale).to(t.dtype)- sin_ = (torch.sin(freqs) * _mscale).to(t.dtype)+ # Full-head rotation has no pass-through channels. Avoid creating empty+ # slices and concatenating them, including their backward copy/add work.+ t_pass = None+ if rot_dim < t.shape[-1]:+ t, t_pass = t[..., :rot_dim], t[..., rot_dim:]+ cos_, sin_ = _get_rotary_cos_sin(freqs, t.dtype, _mscale) if getattr(args, "use_fused_rotary_pos_emb"): mode = 1 if rotary_interleaved else 0@@ -71,7 +103,7 @@ def apply_rotary_pos_emb_bshd( else: t = (t * cos_) + (_rotate_half(t, rotary_interleaved) * sin_) - return torch.cat((t, t_pass), dim=-1)+ return t if t_pass is None else torch.cat((t, t_pass), dim=-1) def transformer_config_post_init_wrapper(fn):@@ -0,0 +1,78 @@+"""Regression checks for rotary constants reused across training forwards."""++from types import SimpleNamespace++import pytest+import torch++from mindspeed import megatron_adaptor # noqa: F401+from mindspeed.core.fusions import fused_rope+++@pytest.fixture(autouse=True)+def rotary_state(monkeypatch):+ fused_rope._cached_rotary_cos_sin.cache_clear()+ monkeypatch.setattr(+ fused_rope, "get_full_args", lambda: SimpleNamespace(use_fused_rotary_pos_emb=False)+ )+ yield+ fused_rope._cached_rotary_cos_sin.cache_clear()+++def test_constants_reused_and_invalidated():+ base = torch.randn(7, 16)+ freqs = base[:, None, None, :]+ first = fused_rope._get_rotary_cos_sin(freqs, torch.bfloat16, 1.0)+ assert fused_rope._get_rotary_cos_sin(freqs, torch.bfloat16, 1.0) is first++ # Mutations through the base of a view must also invalidate the constants.+ base.add_(0.25)+ changed = fused_rope._get_rotary_cos_sin(freqs, torch.bfloat16, 1.0)+ assert changed is not first+ torch.testing.assert_close(changed[0], freqs.cos().bfloat16(), atol=0, rtol=0)+ torch.testing.assert_close(changed[1], freqs.sin().bfloat16(), atol=0, rtol=0)++ scaled = fused_rope._get_rotary_cos_sin(freqs, torch.float32, 1.5)+ torch.testing.assert_close(scaled[0], freqs.cos() * 1.5, atol=0, rtol=0)+ torch.testing.assert_close(scaled[1], freqs.sin() * 1.5, atol=0, rtol=0)+++def test_learned_frequencies_have_fresh_graphs():+ freqs = torch.randn(5, 1, 1, 8, requires_grad=True)+ for _ in range(2):+ cos, sin = fused_rope._get_rotary_cos_sin(freqs, torch.float32, 1.0)+ (cos + sin).sum().backward()+ torch.testing.assert_close(freqs.grad, freqs.cos() - freqs.sin())+ freqs.grad = None+ assert fused_rope._cached_rotary_cos_sin.cache_info().currsize == 0+++def test_inference_does_not_poison_training_cache():+ freqs = torch.randn(5, 1, 1, 8)+ with torch.inference_mode():+ fused_rope._get_rotary_cos_sin(freqs, torch.float32, 1.0)+ inference_freqs = freqs.clone()+ assert fused_rope._cached_rotary_cos_sin.cache_info().currsize == 0+ # Inference tensors have no version counter, even outside inference mode.+ fused_rope._get_rotary_cos_sin(inference_freqs, torch.float32, 1.0)+ cos, sin = fused_rope._get_rotary_cos_sin(freqs, torch.float32, 1.0)+ x = torch.randn_like(freqs, requires_grad=True)+ (x * cos + x * sin).sum().backward()+ torch.testing.assert_close(x.grad, cos + sin)+++@pytest.mark.parametrize("rotary_dim", [8, 16])+@pytest.mark.parametrize("interleaved", [False, True])+def test_rotation_and_backward_preserve_norm(rotary_dim, interleaved):+ angles = torch.randn(7, 1, 1, rotary_dim // 2)+ freqs = (+ angles.repeat_interleave(2, dim=-1)+ if interleaved+ else torch.cat((angles, angles), dim=-1)+ )+ x = torch.randn(7, 2, 3, 16, requires_grad=True)+ result = fused_rope.apply_rotary_pos_emb_bshd(x, freqs, interleaved)+ torch.testing.assert_close(result.square().sum(-1), x.square().sum(-1))+ torch.testing.assert_close(result[..., rotary_dim:], x[..., rotary_dim:])+ result.square().sum().backward()+ torch.testing.assert_close(x.grad, 2 * x)@@ -38,8 +38,13 @@ def multi_tensor_scale(overflow_buf, tensor_lists, scale): raise AssertionError('The size of tensor list must be same, but got {} and {}' .format(len(tensor_lists[0]), len(tensor_lists[1]))) with torch.no_grad():- for i in range(len(tensor_lists[0])):- tensor_lists[1][i].copy_(tensor_lists[0][i] * scale)+ for source, output in zip(*tensor_lists):+ # Gradient clipping passes the same tensors as input and output.+ # Avoid allocating and copying a full temporary for every gradient.+ if source is output and source.is_floating_point() and isinstance(scale, (int, float)):+ output.mul_(scale)+ else:+ output.copy_(source * scale) def type_wrapper(fn):@@ -0,0 +1,25 @@+"""Check in-place gradient scaling, including strided and conversion paths."""++import pytest+import torch+from mindspeed.core.megatron_basic.requirements_basic import multi_tensor_scale+++@pytest.mark.parametrize("dtype", [torch.float32, torch.float16, torch.bfloat16, torch.int64])+def test_inplace_scale_preserves_views(dtype):+ base = torch.arange(96, dtype=dtype).reshape(8, 12)+ view = base[:, ::2]+ expected = base.clone()+ expected[:, ::2].copy_(expected[:, ::2] * 0.034535123452)+ multi_tensor_scale(None, [[view], [view]], 0.034535123452)+ torch.testing.assert_close(base, expected, atol=0, rtol=0)+++def test_separate_output_and_repeated_alias():+ source = torch.randn(7, 13)+ output = torch.empty_like(source, dtype=torch.float16)+ multi_tensor_scale(None, [[source], [output]], 0.034535123452)+ torch.testing.assert_close(output, (source * 0.034535123452).half(), atol=0, rtol=0)+ expected = source.clone() * 0.5 * 0.5+ multi_tensor_scale(None, [[source, source], [source, source]], 0.5)+ torch.testing.assert_close(source, expected, atol=0, rtol=0)@@ -23,19 +23,17 @@ def adamw(params: List[Tensor], r"""Functional API that performs AdamW algorithm computation. See :class:`~torch.optim.AdamW` for details. """- for i, param in enumerate(params):- grad = grads[i]- exp_avg = exp_avgs[i]- exp_avg_sq = exp_avg_sqs[i]- max_exp_avg_sq = max_exp_avg_sqs[i] if amsgrad else None-+ if not params:+ return+ # The fused API already accepts lists. Batch tensors with matching device+ # and dtype, retaining the shared step counter of this parameter group.+ grouped_tensors = Optimizer._group_tensors_by_device_and_dtype(+ [params, grads, exp_avgs, exp_avg_sqs, max_exp_avg_sqs if amsgrad else []]+ )+ for tensor_lists, _ in grouped_tensors.values(): torch._fused_adamw_(- [param],- [grad],- [exp_avg],- [exp_avg_sq],- [max_exp_avg_sq] if amsgrad else [],- [step_tensor],+ *tensor_lists,+ [step_tensor] * len(tensor_lists[0]), amsgrad=amsgrad, lr=lr, beta1=beta1,@@ -0,0 +1,87 @@+"""Compare fused AdamW dispatch and optimizer restart with scalar dispatch."""++import io++import pytest+import torch+import torch_npu++from mindspeed import megatron_adaptor # noqa: F401+from mindspeed.core.optimizer.adamw import AdamW, adamw+++@pytest.fixture(scope="module", autouse=True)+def npu_device():+ if not torch.npu.is_available():+ pytest.skip("requires an NPU")+ torch.npu.set_device(0)+++@pytest.mark.parametrize("amsgrad", [False, True])+@pytest.mark.parametrize("maximize", [False, True])+def test_batched_update_matches_individual(amsgrad, maximize):+ torch.manual_seed(931)+ params = [torch.randn(shape, device="npu", dtype=dtype)+ for dtype in (torch.float32, torch.float16, torch.bfloat16)+ for shape in ((128,), (17, 32), (2560,))]+ grads = [torch.randn_like(p) for p in params]+ avgs = [torch.zeros_like(p) for p in params]+ squares = [torch.zeros_like(p) for p in params]+ maxima = [torch.zeros_like(p) for p in params] if amsgrad else []+ actual = [params, grads, avgs, squares, maxima]+ expected = [[t.clone() for t in values] for values in actual]+ step = torch.tensor(1, device="npu", dtype=torch.int64)+ options = dict(amsgrad=amsgrad, maximize=maximize, beta1=0.9, beta2=0.95,+ lr=1e-3, weight_decay=0.1, eps=1e-8)+ for _ in range(6):+ for index in range(len(params)):+ torch._fused_adamw_(+ *[[values[index]] if values else [] for values in expected],+ [step], **options,+ )+ adamw(*actual, step, **options)+ step.add_(1)+ options['lr'] *= 0.9+ for xs, ys in zip(actual, expected):+ for x, y in zip(xs, ys):+ torch.testing.assert_close(x, y, atol=0, rtol=0)+++def test_restart_and_parameters_without_gradients():+ torch.manual_seed(932)+ params = [torch.nn.Parameter(torch.randn(128, device="npu")) for _ in range(3)]+ optimizer = AdamW([+ {'params': params[:2], 'lr': 1e-3},+ {'params': params[2:], 'lr': 2e-3, 'amsgrad': True, 'maximize': True},+ ], betas=(0.9, 0.95))+ for _ in range(3):+ for p in params[:2]:+ p.grad = torch.randn_like(p)+ optimizer.step()+ # Reload optimizer tensors through the CPU just as a saved checkpoint does.+ stream = io.BytesIO()+ torch.save(optimizer.state_dict(), stream)+ stream.seek(0)+ state = torch.load(stream, map_location='cpu', weights_only=False)+ resumed_params = [torch.nn.Parameter(p.detach().clone()) for p in params]+ resumed = AdamW([{'params': resumed_params[:2]}, {'params': resumed_params[2:]}])+ resumed.load_state_dict(state)+ for _ in range(3):+ for p, q in zip(params, resumed_params):+ p.grad = torch.randn_like(p)+ q.grad = p.grad.clone()+ optimizer.step()+ resumed.step()+ for p, q in zip(params, resumed_params):+ torch.testing.assert_close(p, q, atol=0, rtol=0)+ for name, value in optimizer.state[p].items():+ torch.testing.assert_close(value, resumed.state[q][name], atol=0, rtol=0)+ for group, resumed_group in zip(optimizer.param_groups, resumed.param_groups):+ torch.testing.assert_close(group['step'], resumed_group['step'], atol=0, rtol=0)+++def test_empty_update():+ step = torch.tensor(1, device="npu", dtype=torch.int64)+ adamw([], [], [], [], [], step, amsgrad=False, maximize=False,+ beta1=0.9, beta2=0.95, lr=1e-3, weight_decay=0.1, eps=1e-8)+ assert step.item() == 1@@ -0,0 +1,116 @@+# Copyright (c) 2026, Huawei Technologies Co., Ltd. All rights reserved.+"""Fuse dense row-parallel projections with their HCCL sum reduction."""++import os+from functools import lru_cache, wraps+from itertools import combinations++import torch+import torch_npu+from megatron.core.parallel_state import get_tensor_model_parallel_group+from megatron.core.tensor_parallel.layers import custom_bwd, custom_fwd+from megatron.core.utils import prepare_input_tensors_for_wgrad_compute+++def register_row_parallel_linear_fusion(patch_manager, args):+ # MC2 permits one communication domain per model. Leave specialized+ # parallel implementations in charge of their own communication.+ if not any(getattr(args, name, False) for name in (+ 'use_ascend_mc2', 'use_ascend_coc', 'use_nd_matmul', 'tp_2d', 'num_experts',+ )):+ patch_manager.register_patch(+ 'megatron.core.tensor_parallel.layers.RowParallelLinear.forward',+ row_parallel_linear_forward_wrapper)+++@lru_cache(maxsize=8)+def _matmul_all_reduce_comm(group, device_index):+ """Return a communicator only for a local A2 HCCS mesh.++ Topology discovery is optional: older runtimes and launchers with a different+ device mapping keep the separate matmul and collective implementation.+ """+ if not hasattr(torch_npu, "npu_mm_all_reduce_base"):+ return None+ if not torch.npu.get_device_name(device_index).startswith("Ascend910B"):+ return None+ if torch.distributed.get_backend(group) != "hccl":+ return None+ ranks = torch.distributed.get_process_group_ranks(group)+ if len(ranks) not in (2, 4, 8):+ return None+ local_world_size = int(os.environ.get("LOCAL_WORLD_SIZE", "0"))+ if (+ local_world_size <= 0+ or local_world_size != torch.npu.device_count()+ or device_index != torch.distributed.get_rank() % local_world_size+ or len({rank // local_world_size for rank in ranks}) != 1+ ):+ return None+ try:+ import acl+ except ImportError:+ return None+ if not hasattr(acl.rt, "get_devices_topo"):+ return None+ for first, second in combinations(ranks, 2):+ topology, status = acl.rt.get_devices_topo(+ first % local_world_size, second % local_world_size+ )+ # ACL_RT_DEVS_TOPOLOGY_HCCS: direct HCCS links, not PCIe or a switch.+ if status != 0 or topology != 0x01:+ return None+ backend = group._get_backend(torch.device("npu", device_index))+ return backend.get_hccl_comm_name(torch.distributed.get_rank())+++class _RowMatmulAllReduce(torch.autograd.Function):+ @staticmethod+ @custom_fwd+ def forward(ctx, input_, weight, hcomm):+ ctx.save_for_backward(input_, weight)+ return torch_npu.npu_mm_all_reduce_base(input_, weight.t(), hcomm, reduce_op="sum")++ @staticmethod+ @custom_bwd+ def backward(ctx, grad_output):+ input_, weight = ctx.saved_tensors+ # These are the same two GEMMs, in the same order and dtype, as the+ # unfused linear backward. Each microbatch still rounds its weight+ # gradient before the distributed optimizer accumulates it.+ grad_input = grad_output.matmul(weight)+ grad_output, input_ = prepare_input_tensors_for_wgrad_compute(grad_output, input_)+ grad_weight = grad_output.t().matmul(input_)+ return grad_input, grad_weight, None+++def row_parallel_linear_forward_wrapper(forward):+ @wraps(forward)+ def wrapper(self, input_):+ if (+ input_.device.type != "npu"+ or input_.dtype not in (torch.float16, torch.bfloat16)+ or input_.dtype != self.weight.dtype+ or input_.dim() not in (2, 3)+ or input_.numel() == 0+ or not input_.is_contiguous()+ or not self.weight.is_contiguous()+ or not self.weight.requires_grad+ or not self.input_is_parallel+ or self.sequence_parallel+ or self.is_expert+ or self.gradient_accumulation_fusion+ or self.config._cpu_offloading_context is not None+ ):+ return forward(self, input_)+ group = get_tensor_model_parallel_group()+ hcomm = _matmul_all_reduce_comm(group, input_.device.index)+ if hcomm is None or torch_npu.get_npu_format(input_) != 2:+ return forward(self, input_)+ output = _RowMatmulAllReduce.apply(input_, self.weight, hcomm)+ if self.skip_bias_add:+ return output, self.bias+ # Bias is replicated across ranks and must be added after the sum.+ return (output + self.bias if self.bias is not None else output), None++ return wrapper@@ -0,0 +1,116 @@+"""Run with torchrun --nproc_per_node=2 -m pytest to check HCCL and gradients."""++import datetime+import os+from types import SimpleNamespace++import pytest+import torch+import torch_npu++from mindspeed import megatron_adaptor # noqa: F401+from mindspeed.core.tensor_parallel import fused_row_parallel_linear as fused+++@pytest.fixture(scope="module")+def tp_group():+ if int(os.environ.get("WORLD_SIZE", "1")) != 2:+ pytest.skip("requires two torchrun workers")+ torch.npu.set_device(int(os.environ["LOCAL_RANK"]))+ torch.distributed.init_process_group("hccl", timeout=datetime.timedelta(seconds=120))+ yield torch.distributed.group.WORLD+ fused._matmul_all_reduce_comm.cache_clear()+ torch.npu.synchronize()+ torch.distributed.destroy_process_group()+++@pytest.mark.parametrize("dtype", [torch.bfloat16, torch.float16])+@pytest.mark.parametrize("shape", [(256, 512), (128, 2, 512)])+@pytest.mark.parametrize("bias_mode", ["none", "add", "return"])+def test_forward_backward_and_bias(tp_group, monkeypatch, dtype, shape, bias_mode):+ monkeypatch.setattr(fused, "get_tensor_model_parallel_group", lambda: tp_group)+ torch.manual_seed(183 + torch.distributed.get_rank())+ x = torch.randn(*shape, device="npu", dtype=dtype, requires_grad=True)+ weight = torch.nn.Parameter(torch.randn(256, shape[-1], device="npu", dtype=dtype))+ bias = None if bias_mode == "none" else torch.nn.Parameter(+ torch.ones(256, device="npu", dtype=dtype)+ )+ layer = SimpleNamespace(+ weight=weight, bias=bias, input_is_parallel=True, sequence_parallel=False,+ is_expert=False, gradient_accumulation_fusion=False,+ config=SimpleNamespace(_cpu_offloading_context=None), skip_bias_add=bias_mode == "return",+ )+ def unexpected_fallback(*args):+ pytest.fail("compatible HCCS projection did not use fusion")+ forward = fused.row_parallel_linear_forward_wrapper(unexpected_fallback)+ # Reusing the group and parameters must also work for later microbatches.+ for _ in range(2):+ x.grad = weight.grad = None+ if bias is not None:+ bias.grad = None+ output, output_bias = forward(layer, x)+ if bias_mode == "return":+ assert output_bias is bias+ output = output + output_bias+ else:+ assert output_bias is None+ ref_x = x.detach().clone().requires_grad_()+ ref_w = weight.detach().clone().requires_grad_()+ ref = ref_x.matmul(ref_w.t())+ with torch.no_grad():+ torch.distributed.all_reduce(ref, group=tp_group)+ if bias is not None:+ ref_b = bias.detach().clone().requires_grad_()+ ref = ref + ref_b+ torch.testing.assert_close(output, ref, atol=0, rtol=0)+ grad = torch.randn_like(output)+ output.backward(grad)+ ref.backward(grad)+ torch.testing.assert_close(x.grad, ref_x.grad, atol=0, rtol=0)+ torch.testing.assert_close(weight.grad, ref_w.grad, atol=0, rtol=0)+ if bias is not None:+ torch.testing.assert_close(bias.grad, ref_b.grad, atol=0, rtol=0)+++def test_incompatible_projection_falls_back(tp_group, monkeypatch):+ marker = object()+ forward = fused.row_parallel_linear_forward_wrapper(lambda *args: marker)+ monkeypatch.setattr(fused, "get_tensor_model_parallel_group", lambda: tp_group)+ x = torch.ones(256, 512, device="npu", dtype=torch.bfloat16)+ layer = SimpleNamespace(+ weight=torch.nn.Parameter(torch.ones(256, 512, device="npu", dtype=x.dtype)),+ input_is_parallel=True, sequence_parallel=False, is_expert=False,+ gradient_accumulation_fusion=False, config=SimpleNamespace(_cpu_offloading_context=None),+ )+ for name, value in [("sequence_parallel", True), ("is_expert", True),+ ("gradient_accumulation_fusion", True), ("input_is_parallel", False)]:+ with monkeypatch.context() as m:+ m.setattr(layer, name, value)+ assert forward(layer, x) is marker+ assert forward(layer, x.t()) is marker+ assert forward(layer, x.float()) is marker+ assert forward(layer, x.cpu()) is marker+ layer.weight.requires_grad_(False)+ assert forward(layer, x) is marker+++def test_topology_and_launcher_guards(monkeypatch):+ import acl+ group = object()+ monkeypatch.setattr(torch.npu, "get_device_name", lambda device: "Ascend910B1")+ monkeypatch.setattr(torch.npu, "device_count", lambda: 4)+ monkeypatch.setattr(torch.distributed, "get_backend", lambda group: "hccl")+ monkeypatch.setattr(torch.distributed, "get_rank", lambda: 0)+ monkeypatch.setattr(torch.distributed, "get_process_group_ranks", lambda group: [0, 1])+ monkeypatch.setenv("LOCAL_WORLD_SIZE", "4")+ monkeypatch.setattr(acl.rt, "get_devices_topo", lambda *args: (2, 0)) # PCIe+ fused._matmul_all_reduce_comm.cache_clear()+ assert fused._matmul_all_reduce_comm(group, 0) is None+ monkeypatch.setattr(acl.rt, "get_devices_topo", lambda *args: (1, 0))+ monkeypatch.setattr(torch.distributed, "get_process_group_ranks", lambda group: [0, 4])+ fused._matmul_all_reduce_comm.cache_clear()+ assert fused._matmul_all_reduce_comm(group, 0) is None+ monkeypatch.setenv("LOCAL_WORLD_SIZE", "0")+ fused._matmul_all_reduce_comm.cache_clear()+ assert fused._matmul_all_reduce_comm(group, 0) is None+ fused._matmul_all_reduce_comm.cache_clear()@@ -16,3 +16,5 @@ class AffinityFeature(MindSpeedFeature): patch_manager.register_patch( 'megatron.core.tensor_parallel.cross_entropy.VocabParallelCrossEntropy.calculate_predicted_logits', calculate_predicted_logits)+ from mindspeed.core.tensor_parallel.fused_row_parallel_linear import register_row_parallel_linear_fusion+ register_row_parallel_linear_fusion(patch_manager, args)Base commit: 72c49a6260c73669678b8f39b1ba41a4789bb555
@@ -11,6 +11,7 @@ import torch_npu from megatron.training import get_args from megatron.core import parallel_state from megatron.core.models.common.embeddings.rotary_pos_embedding import _rotate_half, get_pos_emb_on_this_cp_rank+from mindspeed.core.fusions.fused_rope import _get_rotary_cos_sin from mindspeed.ops.npu_rotary_position_embedding import npu_rotary_position_embedding from mindspeed_llm.tasks.common.yarn_rope import YarnRotaryPositionEmbedding @@ -249,14 +250,15 @@ def apply_rotary_pos_emb_bshd( 1 + math.log(scale) / math.log(args.rope_scaling_original_max_position_embeddings)) rot_dim = freqs.shape[-1]- t, t_pass = t[..., :rot_dim], t[..., rot_dim:]+ t_pass = None+ if rot_dim < t.shape[-1]:+ t, t_pass = t[..., :rot_dim], t[..., rot_dim:] if multi_latent_attention: *dims, d = t.shape t = t.reshape(*dims, d // 2, 2).transpose(-2, -1).reshape(*dims, d) - cos_ = (torch.cos(freqs) * _mscale).to(t.dtype)- sin_ = (torch.sin(freqs) * _mscale).to(t.dtype)+ cos_, sin_ = _get_rotary_cos_sin(freqs, t.dtype, _mscale) if args.use_fused_rotary_pos_emb: mode = 1 if rotary_interleaved else 0@@ -264,7 +266,7 @@ def apply_rotary_pos_emb_bshd( else: t = (t * cos_) + (_rotate_half(t, rotary_interleaved) * sin_) - return torch.cat((t, t_pass), dim=-1)+ return t if t_pass is None else torch.cat((t, t_pass), dim=-1) def apply_rotary_pos_emb_thd(@@ -315,4 +317,4 @@ def apply_rotary_pos_emb_bshd_in_complex( if rotary_interleaved: y = torch.cat([y[..., 0::2], y[..., 1::2]], dim=-1) - return y.to(t.dtype)\ No newline at end of file+ return y.to(t.dtype)@@ -0,0 +1,36 @@+"""Check the LLM rotary adapter as well as the shared constant cache."""++from types import SimpleNamespace++import pytest+import torch++from mindspeed_llm import megatron_adaptor # noqa: F401+from mindspeed.core.fusions.fused_rope import _cached_rotary_cos_sin+from mindspeed_llm.core.models.common.embeddings import rotary_pos_embedding as rope+++@pytest.mark.parametrize("rotary_dim", [8, 16])+@pytest.mark.parametrize("interleaved", [False, True])+def test_rotation_reuses_constants_and_preserves_gradients(monkeypatch, rotary_dim, interleaved):+ monkeypatch.setattr(rope, "get_args", lambda: SimpleNamespace(+ use_fused_rotary_pos_emb=False, use_glm_rope=False, rope_scaling_type=None+ ))+ _cached_rotary_cos_sin.cache_clear()+ angles = torch.randn(7, 1, 1, rotary_dim // 2)+ freqs = (+ angles.repeat_interleave(2, dim=-1)+ if interleaved+ else torch.cat((angles, angles), dim=-1)+ )+ try:+ for _ in range(2):+ x = torch.randn(7, 2, 3, 16, requires_grad=True)+ result = rope.apply_rotary_pos_emb_bshd(x, freqs, interleaved)+ torch.testing.assert_close(result.square().sum(-1), x.square().sum(-1))+ torch.testing.assert_close(result[..., rotary_dim:], x[..., rotary_dim:])+ result.square().sum().backward()+ torch.testing.assert_close(x.grad, 2 * x)+ assert _cached_rotary_cos_sin.cache_info().hits == 1+ finally:+ _cached_rotary_cos_sin.cache_clear()@@ -1,13 +1,15 @@-# Copyright (c) 2025, Huawei Technologies Co., Ltd. All rights reserved.-from mindspeed.features_manager.feature import MindSpeedFeature---class AffinityFeature(MindSpeedFeature):- def __init__(self):- super(AffinityFeature, self).__init__('affinity', optimization_level=0)-- def register_patches(self, patch_manager, args):- from mindspeed_llm.core.tensor_parallel.cross_entropy import calculate_predicted_logits- # use logical negation followed by multiplication to achieve the same effect as setting selected elements to zero- patch_manager.register_patch('megatron.core.tensor_parallel.cross_entropy.VocabParallelCrossEntropy.calculate_predicted_logits',- calculate_predicted_logits)\ No newline at end of file+# Copyright (c) 2025, Huawei Technologies Co., Ltd. All rights reserved.+from mindspeed.features_manager.feature import MindSpeedFeature+++class AffinityFeature(MindSpeedFeature):+ def __init__(self):+ super(AffinityFeature, self).__init__('affinity', optimization_level=0)++ def register_patches(self, patch_manager, args):+ from mindspeed_llm.core.tensor_parallel.cross_entropy import calculate_predicted_logits+ # use logical negation followed by multiplication to achieve the same effect as setting selected elements to zero+ patch_manager.register_patch('megatron.core.tensor_parallel.cross_entropy.VocabParallelCrossEntropy.calculate_predicted_logits',+ calculate_predicted_logits)+ from mindspeed.core.tensor_parallel.fused_row_parallel_linear import register_row_parallel_linear_fusion+ register_row_parallel_linear_fusion(patch_manager, args)@@ -0,0 +1,16 @@+"""Ensure the LLM feature list installs the shared projection optimization."""++from mindspeed_llm import megatron_adaptor # noqa: F401+from megatron.core.tensor_parallel.layers import RowParallelLinear+from mindspeed.core.tensor_parallel import fused_row_parallel_linear+++def test_llm_installs_row_projection_fusion():+ # LLM builds its own feature list, so testing the MindSpeed adapter alone+ # does not establish that model construction will use this implementation.+ forward = RowParallelLinear.forward+ while forward is not None:+ if forward.__code__.co_filename == fused_row_parallel_linear.__file__:+ return+ forward = getattr(forward, "__wrapped__", None)+ raise AssertionError("LLM row projections did not receive the fusion wrapper")@@ -594,7 +594,11 @@ def train(forward_step_func, model, optimizer, opt_param_scheduler, if args.manual_gc_interval < 0: raise ValueError('Manual garbage collection interval should be larger than or equal to 0.') gc.disable()- gc.collect()++ # Collect model/optimizer setup garbage at the same boundary on every rank.+ # Promoting the surviving setup objects together avoids full collections+ # interrupting different optimizer updates on different TP ranks.+ gc.collect() total_flops = 0.0 num_microbatches = get_num_microbatches()@@ -1433,4 +1437,4 @@ def num_floating_point_operations(args, batch_size): ) else: # Compute standard Transformer model FLOPs.- return transformer_flops()\ No newline at end of file+ return transformer_flops()