Tasks/Chips & Compute Systems/GPU Kernels

Mamba-3 SISO Long-Ragged Multi-Chunk Joint States Full VJP

Mamba-3 scan with joint states and a full backward pass

mamba3_siso_longragged_multichunk_joint_states_full_vjp_speedup Chips & Compute Systems GPU Kernels
instruction.mdthis is what the agent is given

Optimize a packed variable-length Mamba-3 SISO training operator on one CUDA device. You inherit a correct but weak eager PyTorch baseline and must make it as fast as possible while staying inside the numerical tolerances the verifier enforces.

Hard Constraints

Keep this function name and positional signature unchanged:

mamba3_siso_varlen_joint_states_full_vjp(
    q, k, v, adt, dt, trap, q_bias, k_bias, angles, d, z,
    cu_seqlens, dout, dfinal_angle, dfinal_ssm, dfinal_k, dfinal_v
)

Return exactly:

(output, final_angle_state, final_ssm_state, final_k_state, final_v_state,
 dq, dk, dv, dadt, ddt, dtrap, dq_bias, dk_bias, dangles, dd, dz)

Every returned value must be a concrete CUDA torch.Tensor. Do not mutate any input. Do not retrieve, import, vendor, or call an external Mamba implementation; do not inspect verifier files or processes, access clocks or timers, specialize by call order, or attempt held-out access.

Inputs Q, K, V, trap, angles, and Z use BF16. ADT, DT, both biases, and D use FP32. Output, final-angle, final-V, and the corresponding BF16 input gradients use BF16; final-SSM, final-K, and FP32 input gradients use FP32.

What You Have

The batch is one packed buffer, and cu_seqlens contains the cumulative boundaries of three to five independent sequences. State, causal attention, angle accumulation, and gradients reset at every boundary.

For each packed sequence, the reference does the following:

  1. Expand the single Q/K head to the 32 value heads.
  2. Compute theta = tanh(angles) * pi, then the per-sequence cumulative rotary angle cumsum(theta * dt) mod 2*pi.
  3. Add q_bias and k_bias, and apply paired rotary embeddings to Q and K.
  4. Compute p = sigmoid(trap), shifted next-token values dt_next and p_next (zero at the final token), then shifted_gamma = dt_next * (1 - p_next) and scale = dt * p + shifted_gamma.
  5. Form the causal decayed QK interaction using ADT, scaled K, and V.
  6. Add the per-head d * v skip term, subtract the shifted-QK correction, and apply the z * sigmoid(z) gate.
  7. Return the final cumulative angle, SSM outer-product state, K state, and V state for every packed sequence.

The five nonzero cotangents contribute jointly to the gradients of all eleven differentiable inputs. Frozen shapes use GQA 1 -> 32, Q/K width 128, V width 64, rotary-angle width 32, chunk size 64, non-multiple ragged sequence lengths spanning 3--15 chunks, and three to five packed sequences.

The inherited solver is /app/methods/main/solver.py. Visible cases are in /app/problems/visible_cases.json, and python /app/selfcheck.py evaluates the complete visible panel. PyTorch, Triton, and locally authored helpers are available.

What You Submit

Submit the contents of /app/methods, with your final implementation at /app/methods/main/solver.py.

Record every attempted iteration as one row of a monotonically increasing v1, v2, ... table in /app/methods/experiment_log.md, and preserve that row's exact solver as the single file /app/methods/versions/vN/solver.py. A partial, interrupted, incorrect, or estimated iteration still needs its snapshot and must be marked invalid. Never reuse a label or delete a snapshot.

Afterwards restore the version you judge most likely to generalize into /app/methods/main/solver.py and run one final visible self-check. That final solver may duplicate a saved version; it is evaluated as an additional final entry.

How It Is Judged

Each case scores the frozen eager-baseline latency divided by your candidate latency, and the per-case speedups are combined by geometric mean. Any case that fails a correctness or protocol check zeroes the entire score.

Compilation and input generation are excluded from latency. All output, four final states, and eleven-input VJP work is included. The verifier checks every returned tensor, input immutability, fresh-call behavior, and timing stability, then re-runs your submission once on a sealed hidden panel to produce the final score.

Metric

geometric mean raw speedup over the sealed cases · higher is better

live paired-bracket eager baseline latency / candidate latency per case; any failed correctness check zeroes the run

anchorvisible setheld-outreward
Binherited eager baseline1.00x1.00x0.00
Shuman expert, geomean9.88x10.20x0.60
Uupper-bound proxy, geomean370.89x371.91x1.00
normalisation
m <= B0
B < m <= S0.6 * (m - B) / (S - B)
m > Smin(1, 0.6 + 0.4 * (m - S) / (U - S))

m = this run's held-out metric  ·  B = inherited eager baseline  ·  S = human expert, geomean  ·  U = upper-bound proxy, geomean

B = 1. S and U are per case (7.19/10.78/13.71 and 346/369/403); each case is mapped first, then the three rewards are averaged.

Rollouts

156 minwall clock
$37.24spend
64.1Mtokens
35versions, 20 kept
0 2 4 6 8 10 $0 $7.5 $15 $22 $30 cumulative spend on the run visible-panel geomean speedup, higher is better human expert, geomean · visible · 9.88x v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 v17 v18 v19 v20 v21 v22 v23 v24 v25 v26 v27 v28 v29 v30 v31 v32 v33 v34 v35
keptrevertedno scoreturning point
  1. v1Inherited eager PyTorch reference, untouched1.04721 min · $0.20
  2. v2Compile the whole eager function with TorchInductor, graph breaks retained1.33171 min · $0.29
  3. v3Transfer packed boundaries once via tolist, not two scalar reads per sequence1.34232 min · $0.40
  4. v4Exact 64-token K-V-state chunk recurrence replaces the full causal matrices0.50223 min · $0.53
  5. v5torch.compile reduce-overhead mode1.30224 min · $0.66
  6. v6torch.compile max-autotune mode1.29744 min · $0.81
  7. v7Vectorized 64-token recurrence, batched intra-chunk attention, state mixing1.31136 min · $1.03
  8. v8Recurrence block widened from 64 to 128 tokens1.26917 min · $1.15
  9. v9Compile the primal alone so AOTAutograd owns the backward; VJP stays eager1.35018 min · $1.35
  10. v10Boundary extraction hoisted out; one full AOTAutograd graph for the layoutStop compiling pieces: one graph over the whole ragged layout, so AOTAutograd compiles the backward as well.3.03568 min · $1.48
  11. v11High matmul precision so TF32 tensor cores serve the FP32 contractions3.392114 min · $2.30
  12. v12Vectorized 64-token recurrence plus full AOTAutograd and TF32interrupted, case 318 min · $2.85
  13. v13Concrete dynamic=False full graphs to bound symbolic compile complexityLands the chunked recurrence on the accepted line by fixing the compile blowup that made v12 unusable.4.089824 min · $3.89
  14. v14Recurrence block reduced from 64 to 32 tokens3.813329 min · $4.69
  15. v15Exact sequential chunk-state scan replaces quadratic chunk-to-chunk mixing4.337834 min · $5.76
  16. v16BF16 tensor cores for intra-chunk QK and attention-value products4.344941 min · $7.01
  17. v17BF16 tensor cores also for the Q-times-carried-state output contraction4.711547 min · $8.12
  18. v18BF16 tensor cores also build each chunk K-V state4.633453 min · $9.47
  19. v19Hoist repeated per-chunk BF16 Q/K/V casts for graph reuse4.905261 min · $11.37
  20. v20Sequential-scan block widened from 64 to 128 tokens5.200266 min · $12.35
  21. v21Block widened from 128 to 256 tokens4.91272 min · $13.72
  22. v22Intermediate 96-token block5.123277 min · $14.91
  23. v23160-token block5.069683 min · $16.24
  24. v24Broadcast the single Q/K head with zero-stride expand, no 32 materialized copies5.488989 min · $17.57
  25. v25Drop the expanded views; bias addition broadcasts the one-head Q/K directly5.254791 min · $18.11
  26. v26Materialize the BF16 output before the SiLU gate, dropping FP32 Z expansion5.371897 min · $19.57
  27. v27Shifted-QK correction dot computed in BF165.215399 min · $20.39
  28. v28Angle modulo only on the returned final state; periodic sin/cos on the cumsum5.3262103 min · $21.35
  29. v29Rotate only the 64 Q/K channels the 32 angles cover; concat the unchanged tail5.4057105 min · $21.89
  30. v30Decompose the 32 biased shifted-QK dots into two dense matmuls4.6367111 min · $23.34
  31. v31Four BF16 contractions as batched matmul plus permutations, not einsum5.2905117 min · $25.16
  32. v32Factor intra-block decay into exp-scaled Q/K, dropping the full decay matrixgrad rel-L2 over limit122 min · $26.43
  33. v33Exhaustive max-autotune for the concrete full graphsCompilation is outside the timed window, so an exhaustive kernel search costs the run nothing at score time.7.3615128 min · $28.35
  34. v34Re-test 64-token blocks under max-autotuneinterrupted, case 2144 min · $33.39
  35. v35Max-autotune and CUDA graphs kept, coordinate-descent tuning disabled7.4218150 min · $36.02

35 snapshots, 156 min, $37.24. Roughly half were block-size or dtype sweeps worth under 5% each; v10 and v33 supplied most of the speedup.

On the hidden set

held-out metricreward
inherited eager baseline1.00x0.00
human expert, geomean10.20x0.60
upper-bound proxy, geomean371.91x1.00
this run7.33x0.4214