Skip to content

refactor: unify the processing of the attention mask - #1230

Merged
leejet merged 2 commits into
masterfrom
refactor_attn_mask
Jan 25, 2026
Merged

refactor: unify the processing of the attention mask#1230
leejet merged 2 commits into
masterfrom
refactor_attn_mask

Conversation

@leejet

@leejet leejet commented Jan 25, 2026

Copy link
Copy Markdown
Owner

Fix #857, #1040.

@leejet
leejet merged commit 43e829f into master Jan 25, 2026
13 checks passed
@leejet
leejet deleted the refactor_attn_mask branch January 25, 2026 16:46
gianni-cor pushed a commit to gianni-cor/ggml that referenced this pull request May 14, 2026
Adds Metal backend support for ops required by Wan video diffusion
models on Apple Silicon. Without this patch the Metal backend crashes
with: ggml_metal_op_encode_impl: error: unsupported op 'IM2COL_3D'.

Changes
-------
- IM2COL_3D Metal kernel implementation (f32 and f16 variants)
- Pipeline getter and op handler for IM2COL_3D dispatch
- PAD kernel updated to support non-zero left padding (lp0..lp3)
- ggml_metal_kargs_pad extended with left-padding fields
- supports_op for PAD relaxed to allow any padding values

DIAG_MASK_INF intentionally omitted
-----------------------------------
The original CLDawes patch (ggml-org/llama.cpp#16669) also added a
Metal DIAG_MASK_INF kernel, but it is not included here because:
  - GGML maintainers are deprecating GGML_OP_DIAG_MASK_INF in favor
    of generic ops (see ggml-org/llama.cpp#17654)
  - leejet/stable-diffusion.cpp#1230 (merged Jan 2026) refactored the
    attention path to build explicit -INFINITY mask tensors and no
    longer calls ggml_diag_mask_inf in app code
  - Wan attention sites pass mask=nullptr and never request
    DIAG_MASK_INF, so the kernel would be dead code on this stack

Adapted from CLDawes' patch
(https://github.com/CLDawes/ggml/tree/patch-qwen-image), updated to
use the current ggml_metal_pipeline_with_params API.

Verified on Apple M3 Ultra: Wan2.1 1.3B txt2video runs end-to-end on
Metal with the host process at 0-1.5% CPU throughout.

Made-with: Cursor
aegioscy added a commit to tetherto/qvac-ext-ggml that referenced this pull request Jun 29, 2026
Adds Metal backend support for ops required by Wan video diffusion
models on Apple Silicon. Without this patch the Metal backend crashes
with: ggml_metal_op_encode_impl: error: unsupported op 'IM2COL_3D'.

Changes
-------
- IM2COL_3D Metal kernel implementation (f32 and f16 variants)
- Pipeline getter and op handler for IM2COL_3D dispatch
- PAD kernel updated to support non-zero left padding (lp0..lp3)
- ggml_metal_kargs_pad extended with left-padding fields
- supports_op for PAD relaxed to allow any padding values

DIAG_MASK_INF intentionally omitted
-----------------------------------
The original CLDawes patch (ggml-org/llama.cpp#16669) also added a
Metal DIAG_MASK_INF kernel, but it is not included here because:
  - GGML maintainers are deprecating GGML_OP_DIAG_MASK_INF in favor
    of generic ops (see ggml-org/llama.cpp#17654)
  - leejet/stable-diffusion.cpp#1230 (merged Jan 2026) refactored the
    attention path to build explicit -INFINITY mask tensors and no
    longer calls ggml_diag_mask_inf in app code
  - Wan attention sites pass mask=nullptr and never request
    DIAG_MASK_INF, so the kernel would be dead code on this stack

Adapted from CLDawes' patch
(https://github.com/CLDawes/ggml/tree/patch-qwen-image), updated to
use the current ggml_metal_pipeline_with_params API.

Verified on Apple M3 Ultra: Wan2.1 1.3B txt2video runs end-to-end on
Metal with the host process at 0-1.5% CPU throughout.

Made-with: Cursor
aegioscy added a commit to tetherto/qvac-ext-ggml that referenced this pull request Aug 11, 2026
Adds Metal backend support for ops required by Wan video diffusion
models on Apple Silicon. Without this patch the Metal backend crashes
with: ggml_metal_op_encode_impl: error: unsupported op 'IM2COL_3D'.

Changes
-------
- IM2COL_3D Metal kernel implementation (f32 and f16 variants)
- Pipeline getter and op handler for IM2COL_3D dispatch
- PAD kernel updated to support non-zero left padding (lp0..lp3)
- ggml_metal_kargs_pad extended with left-padding fields
- supports_op for PAD relaxed to allow any padding values

DIAG_MASK_INF intentionally omitted
-----------------------------------
The original CLDawes patch (ggml-org/llama.cpp#16669) also added a
Metal DIAG_MASK_INF kernel, but it is not included here because:
  - GGML maintainers are deprecating GGML_OP_DIAG_MASK_INF in favor
    of generic ops (see ggml-org/llama.cpp#17654)
  - leejet/stable-diffusion.cpp#1230 (merged Jan 2026) refactored the
    attention path to build explicit -INFINITY mask tensors and no
    longer calls ggml_diag_mask_inf in app code
  - Wan attention sites pass mask=nullptr and never request
    DIAG_MASK_INF, so the kernel would be dead code on this stack

Adapted from CLDawes' patch
(https://github.com/CLDawes/ggml/tree/patch-qwen-image), updated to
use the current ggml_metal_pipeline_with_params API.

Verified on Apple M3 Ultra: Wan2.1 1.3B txt2video runs end-to-end on
Metal with the host process at 0-1.5% CPU throughout.

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Metal]: Regression after 1ba30ce: Unsupported Op with nitro models

1 participant