Skip to content

Flash Attention disabled mode support #94

Closed

Description

@ravi9

Ensure models run correctly when Flash Attention is unavailable by providing alternative implementations.

Activity

  1. self-assigned this
    on Mar 26, 2026
  2. moved this from Backlog to In progress in LlamaCPP_OpenVINO Backend Projecton Mar 26, 2026
  3. reopened this on Mar 27, 2026
  4. moved this from Done to In progress in LlamaCPP_OpenVINO Backend Projecton Mar 27, 2026
  5. wine99 commented on Apr 2, 2026

    @wine99
    Collaborator

    Paste comments from #118:

    Verified -fa off with llama-cli, llama-bench, and llama-perplexity on CPU.

    Two cases are still failing:

    • -fa off with STATEFUL
    • NPU

    STATEFUL and NPU support will be addressed in separate PRs.

    When -fa off, v_trans=true. In this case, the layout of cache V differs from cache K. Although the tensor shape of cache V is the same as cache K, i.e. [n_embd, kv_size, n_seq, 1], the data is actually stored and accessed in a transposed manner. The effective layout is [kv_size, n_embd, n_seq, 1].

    This causes two issues:

    1. The SET_ROWS op that updates cache V first flattens the cache and writes the current V using a scattered, element-wise update pattern, instead of row-wise updates as in cache K. Code snippets:
    -  13: [   512,     2,     1,     1] RESHAPE              Vcur-0 (reshaped)                            [ 4,  2048,  4096,  4096]       OPENVINO0
           [    64,     8,     2,     1]            0: RESHAPE     Vcur-0                                      [ 4,   256,  2048,  4096]       OPENVINO0
    -  14: [     1,  1024,     1,     1] RESHAPE              Vcur-0 (reshaped) (reshaped)                 [ 4,     4,  4096,  4096]       OPENVINO0
           [   512,     2,     1,     1]            0: RESHAPE     Vcur-0 (reshaped)                           [ 4,  2048,  4096,  4096]       OPENVINO0
    -  15: [     1, 524288,     1,     1] RESHAPE              cache_v_l0 (reshaped)                        [ 2,     2, 1048576, 1048576]       OPENVINO0
           [   512,  1024,     1,     1]            0: NONE        cache_v_l0                                  [ 2,  1024, 1048576, 1048576]       OPENVINO0
    -  16: [     1, 524288,     1,     1] SET_ROWS             cache_v_l0 (reshaped) (view)                 [ 2,     2, 1048576, 1048576]       OPENVINO0
           [     1,  1024,     1,     1]            0: RESHAPE     Vcur-0 (reshaped) (reshaped)                [ 4,     4,  4096,  4096]       OPENVINO0
           [  1024,     1,     1,     1]            1: NONE        leaf_11                                     [ 8,  8192,  8192,  8192]  OPENVINO0_HOST
           [     1, 524288,     1,     1]            2: RESHAPE     cache_v_l0 (reshaped)                       [ 2,     2, 1048576, 1048576]       OPENVINO0
    
    1. The VIEW–PERMUTE chain applied to cache V before attention differs from that of cache K. Code snippets:
    -  53: [   256,     8,    64,     1] VIEW                 cache_v_l1 (view)                            [ 2, 131072,  2048, 1048576]       OPENVINO0
           [   512,  1024,     1,     1]            0: NONE        cache_v_l1                                  [ 2,  1024, 1048576, 1048576]       OPENVINO0
    -  54: [   256,    64,     8,     1] PERMUTE              cache_v_l1 (view) (permuted)                 [ 2,  2048, 131072, 1048576]       OPENVINO0
           [   256,     8,    64,     1]            0: VIEW        cache_v_l1 (view)                           [ 2, 131072,  2048, 1048576]       OPENVINO0
    -  55: [    64,     8,   256,     1] VIEW                 cache_k_l1 (view)                            [ 2,   128,  1024, 1048576]       OPENVINO0
           [   512,  1024,     1,     1]            0: NONE        cache_k_l1                                  [ 2,  1024, 1048576, 1048576]       OPENVINO0
    -  56: [    64,   256,     8,     1] PERMUTE              cache_k_l1 (view) (permuted)                 [ 2,  1024,   128, 1048576]       OPENVINO0
           [    64,     8,   256,     1]            0: VIEW        cache_k_l1 (view)                           [ 2,   128,  1024, 1048576]       OPENVINO0
    

    STATEFUL is currently not working due to shape and layout mismatches.

    NPU is not working because it pads both the current K/V tensors and the SET_ROWS index input. This approach only works with row-wise updates.

  6. moved this from In progress to Ready in LlamaCPP_OpenVINO Backend Projecton Apr 2, 2026
  7. ravi9 commented on Jun 17, 2026

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

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions