TileOPs-Metax/workloads
stelladuyx 2f6dc23c47
[BugFix][Mamba] Fix da_cumsum kernel to support dt_bias, softplus, and clamp (#1118)
## Summary

### da_cumsum
Accepts raw `dt` and applies the full pipeline as
compile-time-conditional steps:
- Add per-head `dt_bias` (`has_dt_bias=True`)
- Softplus with overflow bypass at `dt > 20` (`dt_softplus=True`)
- Clamp to `[dt_min, dt_max]`
- Inclusive prefix sum of `dA = dt_out * A`

Returns two outputs: `dt_out` (processed dt) and `dA_cumsum`. The kernel
signature is fixed regardless of flags; unused inputs are dummy-zeroed
at the
op boundary **only when `has_dt_bias=False`** — calling `forward` with
`dt_bias=None` when `has_dt_bias=True` now raises `ValueError`
immediately
instead of silently computing un-biased results.

### ssd_chunk_scan
Tensor layouts updated to match the official `_chunk_scan_fwd`:
- `x`, `C`, `out` changed from chunk-fused `[B,C,L,H,P]` to seqlen-fused
`[B,S,H,P]`
- `cb` changed from head-owned `[B,C,H,L,L]` to group-owned
`[B,C,G,L,L]`
- `prev_states` axis order changed from `[B,C,H,N,P]` to `[B,C,H,P,N]`
(P before N, official convention)
- `dt` layout changed from `[B,C,L,H]` to `[B,H,C,L]`
- `n_groups` added as a constructor parameter

`dA_l` shared-memory load moved to just before it is consumed (after the
history path), eliminating a redundant `sync_threads` stall.

### ssd_state_passing
Fixed output convention to match Mamba-2 spec: `out[:,c]` now holds the
state
*before* chunk `c`, so `out[:,0] = initial_states` and `out[:,c+1] =
s_c` for
`c` in `[0, C-2]`. Reference implementations in tests and benchmarks
updated
to match.

### All Mamba kernels
Added `@functools.lru_cache` to all five kernel factory functions
(`da_cumsum`, `ssd_chunk_scan`, `ssd_chunk_state`, `ssd_decode`,
`ssd_state_passing`) to prevent redundant TileLang recompilation on
repeated
calls with identical static parameters.

## Test plan
- [x] Run `tests/ops/test_mamba.py` — all existing and new test cases
pass
  (includes new smoke test `test_da_cumsum_fwd_missing_bias_raises`)
- [x] Run `benchmarks/ops/bench_mamba.py` — benchmark executes cleanly
with no
  regressions

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 18:00:38 +08:00
..
attention [Feat][Attention] support GQA prefill fused RoPE (#1234) 2026-05-06 20:30:34 +08:00
__init__.py [Refactor][Benchmark] Detach benchmarks from tests via workloads layer (#787) 2026-04-05 11:38:51 +08:00
activation.py [Refactor] Rename base modules to <module>_base.py convention (#950) 2026-04-13 18:13:32 +08:00
ada_layer_norm.py [Refactor] Rename base modules to <module>_base.py convention (#950) 2026-04-13 18:13:32 +08:00
ada_layer_norm_zero.py [Refactor] Rename base modules to <module>_base.py convention (#950) 2026-04-13 18:13:32 +08:00
argreduce.py [Refactor] Rename base modules to <module>_base.py convention (#950) 2026-04-13 18:13:32 +08:00
base.py [Refactor] Rename base modules to <module>_base.py convention (#950) 2026-04-13 18:13:32 +08:00
batch_norm.py [Refactor][Benchmark] Narrow gen_inputs return types across workload protocols (#970) 2026-04-15 00:46:16 +08:00
binary_arith.py [Refactor] Rename base modules to <module>_base.py convention (#950) 2026-04-13 18:13:32 +08:00
deltanet.py [Refactor][Benchmark] Narrow gen_inputs return types across workload protocols (#970) 2026-04-15 00:46:16 +08:00
engram.py [Refactor][Benchmark] Narrow gen_inputs return types across workload protocols (#970) 2026-04-15 00:46:16 +08:00
fft.py [Refactor][Benchmark] Narrow gen_inputs return types across workload protocols (#970) 2026-04-15 00:46:16 +08:00
fp8_lighting_indexer.py [Refactor][Benchmark] Narrow gen_inputs return types across workload protocols (#970) 2026-04-15 00:46:16 +08:00
fp8_quant.py [Refactor][Benchmark] Narrow gen_inputs return types across workload protocols (#970) 2026-04-15 00:46:16 +08:00
fused_add_layer_norm.py [Refactor] Rename base modules to <module>_base.py convention (#950) 2026-04-13 18:13:32 +08:00
fused_add_rms_norm.py [Refactor] Rename base modules to <module>_base.py convention (#950) 2026-04-13 18:13:32 +08:00
gated_deltanet.py [Refactor][Benchmark] Narrow gen_inputs return types across workload protocols (#970) 2026-04-15 00:46:16 +08:00
gemm.py [Refactor][Benchmark] Narrow gen_inputs return types across workload protocols (#970) 2026-04-15 00:46:16 +08:00
gla.py [Refactor][Benchmark] Narrow gen_inputs return types across workload protocols (#970) 2026-04-15 00:46:16 +08:00
group_norm.py [Refactor] Rename base modules to <module>_base.py convention (#950) 2026-04-13 18:13:32 +08:00
grouped_gemm.py [Refactor][Benchmark] Narrow gen_inputs return types across workload protocols (#970) 2026-04-15 00:46:16 +08:00
instance_norm.py [Refactor] Rename base modules to <module>_base.py convention (#950) 2026-04-13 18:13:32 +08:00
layer_norm.py [Refactor] Rename base modules to <module>_base.py convention (#950) 2026-04-13 18:13:32 +08:00
logical_reduce.py [Refactor] Rename base modules to <module>_base.py convention (#950) 2026-04-13 18:13:32 +08:00
mamba.py [BugFix][Mamba] Fix da_cumsum kernel to support dt_bias, softplus, and clamp (#1118) 2026-05-09 18:00:38 +08:00
mhc.py [Refactor][Benchmark] Narrow gen_inputs return types across workload protocols (#970) 2026-04-15 00:46:16 +08:00
moe.py [Refactor][Benchmark] Narrow gen_inputs return types across workload protocols (#970) 2026-04-15 00:46:16 +08:00
nsa_utils.py [Refactor][Benchmark] Detach benchmarks from tests via workloads layer (#787) 2026-04-05 11:38:51 +08:00
reduce.py [Refactor] Rename base modules to <module>_base.py convention (#950) 2026-04-13 18:13:32 +08:00
rms_norm.py [Refactor] Rename base modules to <module>_base.py convention (#950) 2026-04-13 18:13:32 +08:00
softmax.py [Refactor] Rename base modules to <module>_base.py convention (#950) 2026-04-13 18:13:32 +08:00
topk_selector.py [Refactor][Benchmark] Narrow gen_inputs return types across workload protocols (#970) 2026-04-15 00:46:16 +08:00
vector_norm.py [Refactor] Rename base modules to <module>_base.py convention (#950) 2026-04-13 18:13:32 +08:00
workload_base.py [Feat][Ops] implement Argmax/Argmin dim=None full-tensor reduction (#1106) 2026-04-29 17:10:18 +08:00