Skip to content

Add OPUS gfx950 bf16 fmha d192x128 kernel - #4205

Merged
shengnxu merged 9 commits into
ROCm:mainfrom
shay-li77:lxx/dev/opus-fmha-d192-v128-fwd
Jul 20, 2026
Merged

shengnxu merged 9 commits into
ROCm:mainfrom
shay-li77:lxx/dev/opus-fmha-d192-v128-fwd

Conversation

@shay-li77

@shay-li77 shay-li77 commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

DeepSeek V3 / V3.2 MLA prefill decompresses its latent KV into per-head K(192) / V(128), i.e. a standard causal MHA with an asymmetric head dim (D_QK=192, D_V=128). The default fmha_v3 backend leaves performance on the table for this shape, especially in the varlen (group) path used by flash_attn_varlen_func. This PR integrates the gfx950 OPUS asymmetric-head-dim flash-attention forward kernel into aiter and routes the (192,128) bf16 case to it, giving sizable speedups on the DeepSeek prefill shapes while falling back to fmha_v3/CK everywhere else.

Technical Details

  • Shared OPUS forward entry point. Generalized the former D=128-only opus path into a single fmha_fwd_bf16_opus_fwd (module module_fmha_fwd_bf16_opus) that dispatches by head dim in C++: the symmetric D=128 kernel (batch only, logic unchanged) or the new D_QK=192/D_V=128 kernel (batch + group/varlen). Both kernels are compiled in one translation unit.
  • New kernel-only headers fmha_fwd_hd192_v128_bf16_opus_{defs.h,kernel.hpp,.h} (ported from the standalone OPUS source), plus the shared host launcher fmha_fwd_bf16_opus_kernels.cu that builds kargs, computes the grid + the causal head/tail-merge opt bit, and launches the right (causal × group) instantiation.
  • Python wrappers. fmha_fwd_bf16_opus_fwd (batch, dense BSHD) and fmha_fwd_bf16_opus_varlen_fwd (packed THD) over one low-level @compile_ops stub; wired into _flash_attn_forward / _flash_attn_varlen_forward. D=192 is enabled by default (AITER_DISABLE_FMHA_OPUS=1 to opt out); D=128 stays env-gated (AITER_ENABLE_FMHA_OPUS=1). A gen_fake meta impl makes the op torch.compile / export / cudagraph safe.
  • Correctness fix — online-softmax rescale NaN. On the wave-wide !all_below path the per-lane new-tile max was applied unconditionally, so a lane whose tile max was below the running max computed exp2(m_row - row_max) with a large positive argument → inf → NaN. Clamped per lane: row_max = all_below ? m_row : max(m_row, row_max), keeping the running max monotonic. Applied to the D=192 and D=128 kernels. (Manifests only in the multi-tile pipeline at large logits; fmha_v3 and normal-magnitude inputs were unaffected.)
  • Review fixes. Plumb the caller's softmax_scale into the D=192 kernel via a new kargs.softmax_scale field (was hardcoded to 1/sqrt(192) and silently ignored); explicit group-mode input validation (packed head dims + seqstart_* dtype=int32 / 1-D / contiguous / length); normalize seqstart_* to int32+contiguous in the varlen wrapper.

Test Plan

  • pytest op_tests/test_mha.py -k opus — batch (flash_attn_func default routing) and group/varlen (direct wrapper) correctness vs the fp32 attention_ref, across partial/odd/large seqlen and MHA/GQA/MQA.
  • Numerical stress: magnitude-ramped q/k (NaN/Inf audit) + cross-attention / widely-varying group lengths / KV padding (incl. NaN padding) audit.
  • Perf: OPUS vs fmha_v3 via aiter.test_common.run_perftest on DeepSeek prefill shapes (nheads ∈ {16,32,64,128}, seqlen×batch=16384, causal, bf16).
  • Resource: compile with -Rpass-analysis=kernel-resource-usage to confirm VGPRs Spill: 0 / Occupancy 2.
  • Env: gfx950 (MI355), ROCm 7.2.2 / AMD clang 22.0.0git.

Test Result

  • Correctness: pytest -k opus → 50 passed. Group-mode perf shapes (28 combos) all consistent within bf16 tolerance, no NaN/Inf. --verify on the standalone harness: GPU KERNEL VALID (67M elements).
  • NaN fix: eliminates NaN/Inf up to |logit| ~1378 (previously failed at |logit| ~86 causal / ~194 non-causal); outputs within bf16 tolerance; fmha_v3 was always finite.
  • Resource: D=192 VGPRs 252–254, Occupancy 2, no spill; softmax_scale plumbing adds 0 VGPR.

Performance Summary

One line: across nheads ∈ {16, 32, 64, 128}, the OPUS D_QK=192/D_V=128 forward beats the default fmha_v3 backend by +25% to +47% (group mode) and +3% to +4% (batch mode) on average.

Toolchain: ROCm 7.2.2, HIP 7.2.53211-671d39a71e,
AMD clang 22.0.0git (roc-7.2.2, f58b06dce1f9c15707c5f808fd002e18c2accf7e).

Per-nheads average gain over fmha_v3 (group mode first, then batch mode):

  • nheads=16: group mode +25.1% (all seqlen) / +12.8% (seqlen ≥ 1024); batch mode +2.7%
  • nheads=32: group mode +32.6% (all seqlen) / +20.8% (seqlen ≥ 1024); batch mode +3.3%
  • nheads=64: group mode +43.3% (all seqlen) / +34.2% (seqlen ≥ 1024); batch mode +4.0%
  • nheads=128: group mode +46.6% (all seqlen) / +38.8% (seqlen ≥ 1024); batch mode +4.4%

Detailed tables

nheads=16 (DeepSeek V3/R1, TP8) — group mode (causal)

batch seqlen nheads head_dim (QK/V) default backend default TFLOPs OPUS TFLOPs improvement
64 256 16 192/128 fmha_v3_varlen_fwd 148 256 +73%
32 512 16 192/128 fmha_v3_varlen_fwd 312 434 +39%
16 1024 16 192/128 fmha_v3_varlen_fwd 509 654 +28%
8 2048 16 192/128 fmha_v3_varlen_fwd 835 935 +12%
4 4096 16 192/128 fmha_v3_varlen_fwd 1078 1166 +8%
2 8192 16 192/128 fmha_v3_varlen_fwd 1211 1315 +9%
1 16384 16 192/128 fmha_v3_varlen_fwd 1286 1382 +7%

nheads=16 (DeepSeek V3/R1, TP8) — batch mode (causal)

batch seqlen nheads head_dim (QK/V) default backend default TFLOPs OPUS TFLOPs improvement
64 256 16 192/128 fmha_v3_fwd 245 255 +4%
32 512 16 192/128 fmha_v3_fwd 442 441 +0%
16 1024 16 192/128 fmha_v3_fwd 665 676 +2%
8 2048 16 192/128 fmha_v3_fwd 913 926 +1%
4 4096 16 192/128 fmha_v3_fwd 1117 1124 +1%
2 8192 16 192/128 fmha_v3_fwd 1235 1282 +4%
1 16384 16 192/128 fmha_v3_fwd 1288 1376 +7%

nheads=32 (DeepSeek V3.2 DSA, TP4) — group mode (causal)

batch seqlen nheads head_dim (QK/V) default backend default TFLOPs OPUS TFLOPs improvement
64 256 32 192/128 fmha_v3_varlen_fwd 155 277 +78%
32 512 32 192/128 fmha_v3_varlen_fwd 316 460 +46%
16 1024 32 192/128 fmha_v3_varlen_fwd 502 680 +35%
8 2048 32 192/128 fmha_v3_varlen_fwd 664 890 +34%
4 4096 32 192/128 fmha_v3_varlen_fwd 986 1125 +14%
2 8192 32 192/128 fmha_v3_varlen_fwd 1154 1281 +11%
1 16384 32 192/128 fmha_v3_varlen_fwd 1254 1377 +10%

nheads=32 (DeepSeek V3.2 DSA, TP4) — batch mode (causal)

batch seqlen nheads head_dim (QK/V) default backend default TFLOPs OPUS TFLOPs improvement
64 256 32 192/128 fmha_v3_fwd 263 280 +7%
32 512 32 192/128 fmha_v3_fwd 456 463 +2%
16 1024 32 192/128 fmha_v3_fwd 690 705 +2%
8 2048 32 192/128 fmha_v3_fwd 933 949 +2%
4 4096 32 192/128 fmha_v3_fwd 1114 1126 +1%
2 8192 32 192/128 fmha_v3_fwd 1229 1271 +3%
1 16384 32 192/128 fmha_v3_fwd 1298 1373 +6%

nheads=64 (TP2, intermediate) — group mode (causal)

batch seqlen nheads head_dim (QK/V) default backend default TFLOPs OPUS TFLOPs improvement
64 256 64 192/128 fmha_v3_varlen_fwd 159 290 +82%
32 512 64 192/128 fmha_v3_varlen_fwd 324 486 +50%
16 1024 64 192/128 fmha_v3_varlen_fwd 488 696 +43%
8 2048 64 192/128 fmha_v3_varlen_fwd 577 869 +51%
4 4096 64 192/128 fmha_v3_varlen_fwd 707 984 +39%
2 8192 64 192/128 fmha_v3_varlen_fwd 992 1193 +20%
1 16384 64 192/128 fmha_v3_varlen_fwd 1117 1323 +18%

nheads=64 (TP2, intermediate) — batch mode (causal)

batch seqlen nheads head_dim (QK/V) default backend default TFLOPs OPUS TFLOPs improvement
64 256 64 192/128 fmha_v3_fwd 274 295 +8%
32 512 64 192/128 fmha_v3_fwd 470 491 +4%
16 1024 64 192/128 fmha_v3_fwd 700 728 +4%
8 2048 64 192/128 fmha_v3_fwd 940 950 +1%
4 4096 64 192/128 fmha_v3_fwd 1112 1124 +1%
2 8192 64 192/128 fmha_v3_fwd 1223 1271 +4%
1 16384 64 192/128 fmha_v3_fwd 1291 1370 +6%

nheads=128 (DP attention / TBO) — group mode (causal)

batch seqlen nheads head_dim (QK/V) default backend default TFLOPs OPUS TFLOPs improvement
64 256 128 192/128 fmha_v3_varlen_fwd 162 298 +84%
32 512 128 192/128 fmha_v3_varlen_fwd 337 501 +48%
16 1024 128 192/128 fmha_v3_varlen_fwd 503 705 +40%
8 2048 128 192/128 fmha_v3_varlen_fwd 597 869 +46%
4 4096 128 192/128 fmha_v3_varlen_fwd 646 962 +49%
2 8192 128 192/128 fmha_v3_varlen_fwd 731 1048 +43%
1 16384 128 192/128 fmha_v3_varlen_fwd 1012 1172 +16%

nheads=128 (DP attention / TBO) — batch mode (causal)

batch seqlen nheads head_dim (QK/V) default backend default TFLOPs OPUS TFLOPs improvement
64 256 128 192/128 fmha_v3_fwd 284 304 +7%
32 512 128 192/128 fmha_v3_fwd 482 509 +6%
16 1024 128 192/128 fmha_v3_fwd 709 741 +5%
8 2048 128 192/128 fmha_v3_fwd 947 957 +1%
4 4096 128 192/128 fmha_v3_fwd 1118 1131 +1%
2 8192 128 192/128 fmha_v3_fwd 1224 1273 +4%
1 16384 128 192/128 fmha_v3_fwd 1283 1369 +7%

Submission Checklist

…(D_QK=192/D_V=128)

Integrate the OPUS asymmetric-head-dim (Q/K=192, V/O=128) GQA/MHA forward
kernel for gfx950, supporting batch + group/varlen, causal + non-causal,
cross-attention, arbitrary seqlen, and GQA/MHA.

- Generalize the former D=128-only opus entry point into a shared
  `fmha_fwd_bf16_opus_fwd` that dispatches by head dim to the symmetric
  D=128 kernel (batch only, logic unchanged) or the new D_QK=192/D_V=128
  kernel (batch + group). Rename module/pybind/symbol accordingly.
- Add the D=192/V=128 kernel-only headers (defs/traits/kernel), ported from
  the standalone gcnasm source; the shared TU compiles both kernels.
- mha.py: split the public wrapper into batch (`fmha_fwd_bf16_opus_fwd`) and
  varlen (`fmha_fwd_bf16_opus_varlen_fwd`) entry points over one low-level
  stub; wire both into `_flash_attn_forward` / `_flash_attn_varlen_forward`.
  D=192 is enabled by default (AITER_DISABLE_FMHA_OPUS=1 to opt out); D=128
  stays env-gated (AITER_ENABLE_FMHA_OPUS=1).
- Add batch + group op tests for the D=192/V=128 path.

Inference-only (no LSE/dropout/bias/alibi/swa/sink/quant/paged). Validated
against fp32 reference (50 passed) and benchmarked vs fmha_v3 on MI355:
batch ~+3%, group ~+34% average.
@shay-li77
shay-li77 requested review from a team and Copilot July 12, 2026 13:15
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 4205 --add-label <label>

@shay-li77 shay-li77 changed the title Add OPUS gfx950 bf16 flash-attention forward for asymmetric head dim … Add OPUS gfx950 bf16 fmha d192x128 kernel Jul 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR integrates a new OPUS gfx950 bf16 FMHA forward kernel for asymmetric head dims (D_QK=192, D_V=128), and refactors the previous D=128 OPUS entry point into a single shared dispatching module/wrapper that supports both (128,128) and (192,128) (including a new varlen/group Python entry point for (192,128)).

Changes:

  • Adds the gfx950 OPUS (192,128) forward kernel headers and a shared C++/pybind entry point that dispatches by head dims.
  • Updates Python dispatch/wrappers in aiter/ops/mha.py to expose dense + varlen wrappers and route _flash_attn_forward/_flash_attn_varlen_forward to OPUS where eligible.
  • Adds OP tests for dense + group/varlen coverage of the new (192,128) path and updates the existing D=128 test to use the shared wrapper.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
op_tests/test_mha.py Adds dense and group/varlen tests to validate routing and numerical correctness for OPUS (192,128); updates D=128 routing check to the new wrapper.
csrc/pybind/fmha_fwd_bf16_opus_pybind.cu Renames/retargets the pybind module to the new shared OPUS forward symbol.
csrc/py_itfs_cu/fmha_fwd_hd128_bf16_opus_kernels.cu Removes the old D=128-only host TU (superseded by shared TU).
csrc/py_itfs_cu/fmha_fwd_bf16_opus_kernels.cu New shared host launcher TU: dispatches (128,128) vs (192,128); adds group/varlen launch plumbing for (192,128).
csrc/include/rocm_ops.hpp Updates pybind macro to bind the new shared OPUS forward API with optional varlen args.
csrc/include/fmha_fwd_hd192_v128_bf16_opus.h New kernel-only header declaring the (192,128) device kernel template under IMPL guard.
csrc/include/fmha_fwd_hd192_v128_bf16_opus_defs.h New shared defs/traits/kargs/constants for the (192,128) kernel.
csrc/include/fmha_fwd_hd192_v128_bf16_opus_kernel.hpp New OPUS kernel implementation for (192,128) on gfx950.
csrc/include/fmha_fwd_hd128_bf16_opus.h Re-scopes the D=128 header to “kernel-only” (public API moved to shared header).
csrc/include/fmha_fwd_hd128_bf16_opus_defs.h Adds a guard to avoid duplicate ceil_div definition across headers.
csrc/include/fmha_fwd_bf16_opus.h New shared public C++ API header for OPUS bf16 fmha forward (dense + optional varlen args).
aiter/ops/mha.py Introduces shared OPUS stub/wrappers (dense + varlen), updates dense/varlen dispatch gating to route to OPUS for (192,128) by default (with env rollback).
aiter/jit/optCompilerConfig.json Renames the JIT module entry to compile the new shared TU + pybind module.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread aiter/ops/mha.py Resolved
Comment thread csrc/include/rocm_ops.hpp Resolved
- Register a gen_fake (meta) implementation for the shared OPUS bf16 forward
  custom op so it is torch.compile / export / cudagraph safe. The kernel writes
  `out` in place and returns nothing (out is pre-allocated by the wrapper), so
  the fake simply returns None; without it the guard would fall back to running
  the real kernel under FakeTensorMode.
- Consolidate the dense (batch) eligibility check into a single
  can_impl_fmha_fwd_bf16_opus(): shared inference-only conditions are evaluated
  first (cheapest / most selective, e.g. gfx950 + bf16), and the per-head-dim
  helpers (D=128 env-gated, D=192 default-on) are only checked once those hold.
@zufayu
zufayu requested a review from amd-ruitang3 July 13, 2026 01:37
The online-softmax running-max update took the wave-wide `all_below` (ballot)
decision but then applied the per-lane new-tile max unconditionally. On the
!all_below path, a lane whose own tile max is BELOW the running max `m_row`
computed rescale = exp2(m_row - row_max) with a large positive argument, which
overflows to inf → O/l become inf → NaN (it also wrongly lowered m_row).

Clamp per lane: row_max = all_below ? m_row : max(m_row, row_max). This keeps the
running max monotonic so rescale = exp2(m_row - max(...)) <= 1 (no overflow) and
matches the correct online-softmax semantics. Applied to both the D_QK=192/D_V=128
and the symmetric D=128 kernels.

Only manifests in the multi-tile pipeline (seqlen > one KV tile) at large logits
(|logit| ~> 86 causal / ~194 non-causal); normal-magnitude inputs are unaffected.
Verified: NaN/Inf eliminated up to |logit| ~1378, outputs within bf16 tolerance,
and no performance change (batch ~+3%, group ~+30%+ vs v3 unchanged).
@shay-li77
shay-li77 force-pushed the lxx/dev/opus-fmha-d192-v128-fwd branch from 3f1d460 to 6473c12 Compare July 13, 2026 08:40
shay-li77 and others added 2 commits July 13, 2026 04:28
… seqstart

- Plumb the caller's softmax_scale into the D_QK=192/D_V=128 kernel via a new
  kargs.softmax_scale field (after stride_v_h). The kernel previously hardcoded
  1/sqrt(192)*log2(e) and silently ignored a non-default scale, producing wrong
  results; it now derives temperature_scale from kargs.softmax_scale.
- Validate group/varlen inputs in the shared launcher before use: packed q/k/v/out
  head dims, and each seqstart_* (incl. *_pad) dtype==int32 / 1-D / contiguous /
  length==num_groups+1 — before reinterpreting data_ptr() as const int*.
- Normalize seqstart_* to int32 + contiguous in the varlen Python wrapper so
  callers passing int64 / non-contiguous cumulative lengths work.
- black-format the opus test additions in op_tests/test_mha.py.
@shengnxu
shengnxu merged commit 874840a into ROCm:main Jul 20, 2026
78 of 80 checks passed
@shay-li77
shay-li77 deleted the lxx/dev/opus-fmha-d192-v128-fwd branch July 20, 2026 01:12
@fxmarty-amd

fxmarty-amd commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

@shengnxu in vllm/vllm-openai-rocm:nightly-311b3513af33bc29b4acb2fde2e9313e5e9966a0:

VLLM_ENGINE_READY_TIMEOUT_S=1800 \
HIP_VISIBLE_DEVICES="0,1,2,3,4,5,6,7" \
VLLM_ROCM_USE_AITER=1 \
VLLM_ROCM_USE_AITER_MOE=1 \
VLLM_ROCM_USE_AITER_FUSION_SHARED_EXPERTS=0 \
VLLM_DISABLE_SHARED_EXPERTS_STREAM=1 \
vllm serve amd/Kimi-K2.6-MXFP4 \
	--tensor-parallel-size 8 \
	--trust-remote-code \
	--port 8004 \
    --max-cudagraph-capture-size 128

and vllm bench serve --port 8004 --ready-check-timeout-sec 1200 --num-prompts 400 --max-concurrency 64 --input-len 1024 --output-len 128 --num-warmups 96 --trust-remote-code

crashes due in vllm/vllm-openai-rocm:nightly-311b3513af33bc29b4acb2fde2e9313e5e9966a0 to this PR on latest vLLM + aiter==0.1.19 with

(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/model_executor/models/kimi_k25.py", line 465, in forward
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     hidden_states = self.language_model(
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]                     ^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py", line 1778, in _wrapped_call_impl
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return self._call_impl(*args, **kwargs)
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py", line 1789, in _call_impl
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return forward_call(*args, **kwargs)
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/model_executor/models/deepseek_v2.py", line 1894, in forward
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     hidden_states = self.model(
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]                     ^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/compilation/decorators.py", line 520, in __call__
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return self.aot_compiled_fn(self, *args, **kwargs)
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/torch/_dynamo/aot_compile.py", line 240, in __call__
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return self.fn(*args, **kwargs)
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/model_executor/models/deepseek_v2.py", line 1427, in forward
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     def forward(
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/compilation/caching.py", line 225, in __call__
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return self.optimized_call(*args, **kwargs)
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "<string>", line 504, in execution_fn
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "<string>", line 9, in __vllm_inlined_submods__2
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/torch/_ops.py", line 1275, in __call__
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return self._op(*args, **kwargs)
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050] WorkerProc hit an exception.
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/model_executor/layers/attention/kv_transfer_utils.py", line 40, in wrapper
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050] Traceback (most recent call last):
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return func(*args, **kwargs)
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/v1/executor/multiproc_executor.py", line 1042, in worker_busy_loop
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     output = func(*args, **kwargs)
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/model_executor/layers/attention/mla_attention.py", line 1271, in unified_mla_attention_with_output
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]              ^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     layer.forward_impl(
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/v1/worker/worker_base.py", line 355, in execute_model
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/model_executor/layers/attention/mla_attention.py", line 853, in forward_impl
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return self.worker.execute_model(scheduler_output)
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     self.impl.forward_mha(  # type: ignore[attr-defined]
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/v1/attention/backends/mla/rocm_aiter_mla.py", line 1138, in forward_mha
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/torch/utils/_contextlib.py", line 124, in decorate_context
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return super().forward_mha(
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return func(*args, **kwargs)
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/model_executor/layers/attention/mla_attention.py", line 2890, in forward_mha
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/v1/worker/gpu_worker.py", line 1113, in execute_model
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     output_prefill = prefill_metadata.prefill_backend.run_prefill_new_tokens(
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     output = self.model_runner.execute_model(
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/v1/attention/backends/mla/prefill/aiter_flash_attn.py", line 83, in run_prefill_new_tokens
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/torch/utils/_contextlib.py", line 124, in decorate_context
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     result = self.flash_attn_varlen_func(
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return func(*args, **kwargs)
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/aiter/ops/mha.py", line 3649, in flash_attn_varlen_func
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/v1/worker/gpu_model_runner.py", line 4570, in execute_model
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return FlashAttnVarlenFunc.apply(
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     model_output = self._model_forward(
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]                    ^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/torch/autograd/function.py", line 596, in apply
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/v1/worker/gpu_model_runner.py", line 3986, in _model_forward
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return super().apply(*args, **kwargs)  # type: ignore[misc]
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return self.model(
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/aiter/ops/mha.py", line 3282, in forward
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/compilation/cuda_graph.py", line 254, in __call__
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return self.runnable(*args, **kwargs)
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/aiter/ops/mha.py", line 2918, in _flash_attn_varlen_forward
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py", line 1778, in _wrapped_call_impl
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     out = fmha_fwd_bf16_opus_varlen_fwd(
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return self._call_impl(*args, **kwargs)
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/aiter/ops/mha.py", line 429, in fmha_fwd_bf16_opus_varlen_fwd
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py", line 1789, in _call_impl
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     _fmha_fwd_bf16_opus_fwd(
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return forward_call(*args, **kwargs)
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/aiter/jit/utils/torch_guard.py", line 289, in wrapper_custom
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     getattr(torch.ops.aiter, f"{loadName}")(*args, **kwargs)
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/model_executor/models/kimi_k25.py", line 465, in forward
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/torch/_ops.py", line 1275, in __call__
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     hidden_states = self.language_model(
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return self._op(*args, **kwargs)
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]                     ^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py", line 1778, in _wrapped_call_impl
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/aiter/jit/utils/torch_guard.py", line 312, in outer_wrapper
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return self._call_impl(*args, **kwargs)
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     wrapper(*args, **kwargs)
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/aiter/jit/utils/torch_guard.py", line 207, in wrapper
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py", line 1789, in _call_impl
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return func(*args, **kwargs)
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return forward_call(*args, **kwargs)
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/aiter/jit/core.py", line 1784, in custom_wrapper
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/model_executor/models/deepseek_v2.py", line 1894, in forward
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return wrapper(*args, **kwargs)
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     hidden_states = self.model(
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]                     ^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/aiter/jit/core.py", line 1780, in wrapper
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/felmarty/repos/vllm/vllm/compilation/decorators.py", line 520, in __call__
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return op(*args, **kwargs)
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return self.aot_compiled_fn(self, *args, **kwargs)
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050] TypeError: fmha_fwd_bf16_opus_fwd(): incompatible function arguments. The following argument types are supported:
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]   File "/usr/local/lib/python3.12/dist-packages/torch/_dynamo/aot_compile.py", line 240, in __call__
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     1. (q: aiter_tensor_t, k: aiter_tensor_t, v: aiter_tensor_t, out: aiter_tensor_t, causal: bool, softmax_scale: typing.SupportsFloat | typing.SupportsIndex, seqstart_q: aiter_tensor_t | None = None, seqstart_k: aiter_tensor_t | None = None, seqstart_q_pad: aiter_tensor_t | None = None, seqstart_k_pad: aiter_tensor_t | None = None, max_seqlen_q: typing.SupportsInt | typing.SupportsIndex = 0, max_seqlen_k: typing.SupportsInt | typing.SupportsIndex = 0) -> None
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]     return self.fn(*args, **kwargs)
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]
(Worker_TP7 pid=88650) ERROR 08-18 15:22:04 [multiproc_executor.py:1050]            ^^^^^^^^^^^^^^^^^^^^^^^^
(Worker_TP6 pid=88649) ERROR 08-18 15:22:04 [multiproc_executor.py:1050] Invoked with: <aiter.jit.module_aiter_core.aiter_tensor_t object at 0x7f2178d60e30>, <aiter.jit.module_aiter_core.aiter_tensor_t object at 0x7f217902c5f0>, <aiter.jit.module_aiter_core.aiter_tensor_t object at 0x7f217902e9f0>, <aiter.jit.module_aiter_core.aiter_tensor_t object at 0x7f217902c570>, True, 0.14467962580268923, <aiter.jit.module_aiter_core.aiter_tensor_t object at 0x7f217902db70>, <aiter.jit.module_aiter_core.aiter_tensor_t object at 0x7f217902ec70>, <aiter.jit.module_aiter_core.aiter_tensor_t object at 0x7f217902ef30>, <aiter.jit.module_aiter_core.aiter_tensor_t object at 0x7f217902ef70>, 1024, 1024

This is caused by:

The code that selects it is unchanged in substance from the container:

def can_impl_fmha_fwd_hd192_v128_bf16_opus_varlen():
enables OPUS automatically on gfx950 for bf16 Q/K=192, V=128.

out = fmha_fwd_bf16_opus_varlen_fwd(
dispatches that case to fmha_fwd_bf16_opus_varlen_fwd.

_fmha_fwd_bf16_opus_fwd(
passes the tensors and four sequence-offset tensors into the native OPUS binding—the exact call that fails.

#define FMHA_FWD_BF16_OPUS_PYBIND \
registers that function with pybind as fmha_fwd_bf16_opus_fwd.

PYBIND11_MODULE(TORCH_EXTENSION_NAME, m)
builds the separate module_fmha_fwd_bf16_opus extension containing that registration.

torch_to_aiter_pybind creates module_aiter_core.aiter_tensor_t, but module_fmha_fwd_bf16_opus.so rejects those instances despite advertising the same type.

Repro:

"""Reproduce AITER gfx950 OPUS varlen FlashAttention binding failure.

Run inside the ROCm container with its default Python, for example:

    HIP_VISIBLE_DEVICES=0 python repro_opus.py

With the affected AITER build, this raises ``TypeError`` from
``fmha_fwd_bf16_opus_fwd`` even though all inputs are valid contiguous CUDA
tensors. To verify the fallback, run with ``AITER_DISABLE_FMHA_OPUS=1``.
"""

import inspect

import aiter
import torch
from aiter import flash_attn_varlen_func


def main() -> None:
    if not torch.cuda.is_available():
        raise RuntimeError("This reproducer requires a ROCm CUDA/HIP device.")

    device = "cuda"
    q = torch.randn(4, 16, 192, device=device, dtype=torch.bfloat16)
    k = torch.randn(4, 1, 192, device=device, dtype=torch.bfloat16)
    v = torch.randn(4, 1, 128, device=device, dtype=torch.bfloat16)
    cu_seqlens = torch.tensor([0, 4], device=device, dtype=torch.int32)

    print(f"torch: {torch.__version__}")
    print(f"aiter: {getattr(aiter, '__version__', 'unknown')}")
    print(f"GPU: {torch.cuda.get_device_name(0)}")
    print(f"flash_attn_varlen_func: {inspect.signature(flash_attn_varlen_func)}")

    output = flash_attn_varlen_func(
        q,
        k,
        v,
        cu_seqlens,
        cu_seqlens,
        max_seqlen_q=4,
        max_seqlen_k=4,
        softmax_scale=192**-0.5,
        causal=True,
    )
    torch.cuda.synchronize()
    print(f"PASS: {output.shape=}, {output.dtype=}, {output.device=}")


if __name__ == "__main__":
    main()

that crashes with

Traceback (most recent call last):
  File "/felmarty/repos/vllm/repro_opus.py", line 50, in <module>
    main()
  File "/felmarty/repos/vllm/repro_opus.py", line 34, in main
    output = flash_attn_varlen_func(
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/aiter/ops/mha.py", line 3649, in flash_attn_varlen_func
    return FlashAttnVarlenFunc.apply(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/autograd/function.py", line 596, in apply
    return super().apply(*args, **kwargs)  # type: ignore[misc]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/aiter/ops/mha.py", line 3282, in forward
    out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/aiter/ops/mha.py", line 2918, in _flash_attn_varlen_forward
    out = fmha_fwd_bf16_opus_varlen_fwd(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/aiter/ops/mha.py", line 429, in fmha_fwd_bf16_opus_varlen_fwd
    _fmha_fwd_bf16_opus_fwd(
  File "/usr/local/lib/python3.12/dist-packages/aiter/jit/utils/torch_guard.py", line 289, in wrapper_custom
    getattr(torch.ops.aiter, f"{loadName}")(*args, **kwargs)
  File "/usr/local/lib/python3.12/dist-packages/torch/_ops.py", line 1275, in __call__
    return self._op(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/aiter/jit/utils/torch_guard.py", line 312, in outer_wrapper
    wrapper(*args, **kwargs)
  File "/usr/local/lib/python3.12/dist-packages/aiter/jit/utils/torch_guard.py", line 207, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/aiter/jit/core.py", line 1784, in custom_wrapper
    return wrapper(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/aiter/jit/core.py", line 1780, in wrapper
    return op(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
TypeError: fmha_fwd_bf16_opus_fwd(): incompatible function arguments. The following argument types are supported:
    1. (q: aiter_tensor_t, k: aiter_tensor_t, v: aiter_tensor_t, out: aiter_tensor_t, causal: bool, softmax_scale: typing.SupportsFloat | typing.SupportsIndex, seqstart_q: aiter_tensor_t | None = None, seqstart_k: aiter_tensor_t | None = None, seqstart_q_pad: aiter_tensor_t | None = None, seqstart_k_pad: aiter_tensor_t | None = None, max_seqlen_q: typing.SupportsInt | typing.SupportsIndex = 0, max_seqlen_k: typing.SupportsInt | typing.SupportsIndex = 0) -> None

Invoked with: <aiter.jit.module_aiter_core.aiter_tensor_t object at 0x7f88642aa5b0>, <aiter.jit.module_aiter_core.aiter_tensor_t object at 0x7f8863f97630>, <aiter.jit.module_aiter_core.aiter_tensor_t object at 0x7f8863e50bf0>, <aiter.jit.module_aiter_core.aiter_tensor_t object at 0x7f8863e503b0>, True, 0.07216878364870322, <aiter.jit.module_aiter_core.aiter_tensor_t object at 0x7f886408a670>, <aiter.jit.module_aiter_core.aiter_tensor_t object at 0x7f88643dae30>, <aiter.jit.module_aiter_core.aiter_tensor_t object at 0x7f8863e3abb0>, <aiter.jit.module_aiter_core.aiter_tensor_t object at 0x7f88798179b0>, 4, 4

AITER_DISABLE_FMHA_OPUS=1 fixes the issue.

@fxmarty-amd

Copy link
Copy Markdown
Contributor

cc @shay-li77

@shay-li77

Copy link
Copy Markdown
Contributor Author

Root cause

fmha_fwd_bf16_opus_fwd takes aiter_tensor_t, a pybind11-registered class owned by module_aiter_core, but module_fmha_fwd_bf16_opus is excluded from the wheel prebuild (setup.py drops every module whose name contains "mha") and is therefore JIT-compiled at runtime against the user's torch/pybind11. When that toolchain produces a different PYBIND11_INTERNALS_ID than the prebuilt module_aiter_core.so, the two .so files no longer share a pybind type registry, so the registration is invisible and every aiter_tensor_t argument is rejected — hence the bare, unresolved aiter_tensor_t in the expected signature versus the fully qualified aiter.jit.module_aiter_core.aiter_tensor_t in the passed values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants