Skip to content

[CANN] fix flash-attn mask: use BOOL attenMask instead of F16 -Inf pseShift - #89

Open
July-h5kf3 wants to merge 4 commits into
tc-mb:feat/ascend-cannfrom
July-h5kf3:cann-fa-attenmask
Open

[CANN] fix flash-attn mask: use BOOL attenMask instead of F16 -Inf pseShift#89
July-h5kf3 wants to merge 4 commits into
tc-mb:feat/ascend-cannfrom
July-h5kf3:cann-fa-attenmask

Conversation

@July-h5kf3

@July-h5kf3 July-h5kf3 commented Jul 28, 2026

Copy link
Copy Markdown

Overview

FusedInferAttentionScoreV2 was receiving llama.cpp's additive F16 attention mask (-Inf for masked positions) via pseShiftOptional. Ascend documents pseShift as position encoding (F16/BFLOAT16) and attenMask as BOOL/INT8/UINT8.On long KV lengths (e.g. multi-image MiniCPM-o, Sk≈768), putting -Inf into pseShift produced NaNs in the fused op and garbled generation (? floods).

This change:

  • converts the hard-mask part of src3 (-Inf) to a contiguous BOOL attenMask (True = do not attend) and passes it via attenMaskOptional
  • keeps finite additive biases in pseShift (clamped so PSE never contains -Inf)
  • when max_bias != 0 (ALiBi), multiplies the finite PSE by the ALiBi slopes

Additional information

  • Ascend aclnnFusedInferAttentionScoreV2:
    • attenMaskOptional: BOOL / INT8 / UINT8
    • pseShiftOptional: F16 / BF16 position encoding / additive bias
  • Related prior workaround: CANN AUTO flash-attn force-off in llama-context.cpp (can revisit in a follow-up after this lands)
  • Same pse-as-mask pattern also exists in upstream ggml-org/llama.cpp

Test plan

  • test-backend-ops -b CANN0 -o FLASH_ATTN_EXT -p "mask=1,sinks=0,max_bias=0" → 320/320 OK
  • MiniCPM-o, multi-image, --flash-attn on: no NaN / no ? flood
  • text-only + --flash-attn on (llama-cli --single-turn): OK
  • Rebuild ggml-cann with this change

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - used AI to help isolate the CANN FA NaN (mask vs pseShift) and draft the attenMask conversion; I reviewed the final patch line-by-line and can explain / maintain it

tc-mb and others added 4 commits July 7, 2026 13:15
* “feat:simply e2e profiling” (tc-mb#71)

* fix(omni): harden duplex perf turn matching and RTF verdict

Signed-off-by: tc-mb <tianchi_cai@icloud.com>

---------

Signed-off-by: tc-mb <tianchi_cai@icloud.com>
Co-authored-by: Han Qingzhe <95479277+hNSBQZ@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions github-actions Bot added documentation Improvements or additions to documentation server ggml Ascend NPU labels Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ascend NPU documentation Improvements or additions to documentation ggml server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants