Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25190
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 0f2b106 with merge base 6aebee6 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
digantdesai
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
This PR needs a
|
…hared masks Pull Request resolved: #25190 ## Ulterior Motive Closing the decode gap between ExecuTorch Native's GGML engine and llama.cpp on CUDA, measured with Gemma 4 31B Q4_K_M on an A100. ## Rationale **What**: The engine finds key extents for attention masks that are products of comparisons, and for masks that share values. **Why**: Attention covers only the keys below an extent the engine computes on the host, but only for masks it matches. It matched a single comparison whose values fed nothing but that mask. Gemma 4 builds its sliding-window mask as the causal comparison times a window comparison, and its global layers use the causal comparison itself. Both were rejected, so every layer's flash attention read all 4,096 cache rows at every decode step. ## Details - `aten.mul` of boolean masks matches as their logical and. A mask attends the keys every one of its comparisons attends. - Masks that share a value form one group. The group is computed over the widest extent any of its masks attends, and its values may feed only each other or SDPA masks over the same keys. - Host-evaluated integer constants may hold up to 2^16 elements instead of 64, so the key positions of a 4,096-row static cache evaluate on the host. Gemma 4 31B decode, per step: - **Before**: attention over all 4,096 keys in all 60 layers; flash attention kernels took 2.90 ms. - **After**: attention over the keys up to the end of the 256-key bucket holding the position; 0.88 ms, vs 0.93 ms in llama.cpp. Tests: - `test_sdpa_key_prefix_of_masks_that_share_values`: a causal mask and a sliding-window product that shares its comparison. - `test_sdpa_key_prefix_of_a_mask_group_is_its_widest`: masks of one group that end in different buckets. - `test_sdpa_key_prefix_of_a_mask_read_by_other_ops`: a comparison that also feeds a sum keeps attention over every key. - `test_sdpa_key_prefix_of_constant_key_positions`: key positions held by a constant. Authored with Claude Code. Differential Revision: [D130721994](https://our.internmc.facebook.com/intern/diff/D130721994/) ghstack-source-id: 476599442
…hared masks Pull Request resolved: #25190 ## Ulterior Motive Closing the decode gap between ExecuTorch Native's GGML engine and llama.cpp on CUDA, measured with Gemma 4 31B Q4_K_M on an A100. ## Rationale **What**: The engine finds key extents for attention masks that are products of comparisons, and for masks that share values. **Why**: Attention covers only the keys below an extent the engine computes on the host, but only for masks it matches. It matched a single comparison whose values fed nothing but that mask. Gemma 4 builds its sliding-window mask as the causal comparison times a window comparison, and its global layers use the causal comparison itself. Both were rejected, so every layer's flash attention read all 4,096 cache rows at every decode step. ## Details - `aten.mul` of boolean masks matches as their logical and. A mask attends the keys every one of its comparisons attends. - Masks that share a value form one group. The group is computed over the widest extent any of its masks attends, and its values may feed only each other or SDPA masks over the same keys. - Host-evaluated integer constants may hold up to 2^16 elements instead of 64, so the key positions of a 4,096-row static cache evaluate on the host. Gemma 4 31B decode, per step: - **Before**: attention over all 4,096 keys in all 60 layers; flash attention kernels took 2.90 ms. - **After**: attention over the keys up to the end of the 256-key bucket holding the position; 0.88 ms, vs 0.93 ms in llama.cpp. Tests: - `test_sdpa_key_prefix_of_masks_that_share_values`: a causal mask and a sliding-window product that shares its comparison. - `test_sdpa_key_prefix_of_a_mask_group_is_its_widest`: masks of one group that end in different buckets. - `test_sdpa_key_prefix_of_a_mask_read_by_other_ops`: a comparison that also feeds a sum keeps attention over every key. - `test_sdpa_key_prefix_of_constant_key_positions`: key positions held by a constant. Authored with Claude Code. ghstack-source-id: 477270600 Differential Revision: [D130721994](https://our.internmc.facebook.com/intern/diff/D130721994/)
…hared masks Pull Request resolved: #25190 ## Ulterior Motive Closing the decode gap between ExecuTorch Native's GGML engine and llama.cpp on CUDA, measured with Gemma 4 31B Q4_K_M on an A100. ## Rationale **What**: The engine finds key extents for attention masks that are products of comparisons, and for masks that share values. **Why**: Attention covers only the keys below an extent the engine computes on the host, but only for masks it matches. It matched a single comparison whose values fed nothing but that mask. Gemma 4 builds its sliding-window mask as the causal comparison times a window comparison, and its global layers use the causal comparison itself. Both were rejected, so every layer's flash attention read all 4,096 cache rows at every decode step. ## Details - `aten.mul` of boolean masks matches as their logical and. A mask attends the keys every one of its comparisons attends. - Masks that share a value form one group. The group is computed over the widest extent any of its masks attends, and its values may feed only each other or SDPA masks over the same keys. - Host-evaluated integer constants may hold up to 2^16 elements instead of 64, so the key positions of a 4,096-row static cache evaluate on the host. Gemma 4 31B decode, per step: - **Before**: attention over all 4,096 keys in all 60 layers; flash attention kernels took 2.90 ms. - **After**: attention over the keys up to the end of the 256-key bucket holding the position; 0.88 ms, vs 0.93 ms in llama.cpp. Tests: - `test_sdpa_key_prefix_of_masks_that_share_values`: a causal mask and a sliding-window product that shares its comparison. - `test_sdpa_key_prefix_of_a_mask_group_is_its_widest`: masks of one group that end in different buckets. - `test_sdpa_key_prefix_of_a_mask_read_by_other_ops`: a comparison that also feeds a sum keeps attention over every key. - `test_sdpa_key_prefix_of_constant_key_positions`: key positions held by a constant. Authored with Claude Code. ghstack-source-id: 477270600 Differential Revision: [D130721994](https://our.internmc.facebook.com/intern/diff/D130721994/)
…hared masks Pull Request resolved: #25190 ## Ulterior Motive Closing the decode gap between ExecuTorch Native's GGML engine and llama.cpp on CUDA, measured with Gemma 4 31B Q4_K_M on an A100. ## Rationale **What**: The engine finds key extents for attention masks that are products of comparisons, and for masks that share values. **Why**: Attention covers only the keys below an extent the engine computes on the host, but only for masks it matches. It matched a single comparison whose values fed nothing but that mask. Gemma 4 builds its sliding-window mask as the causal comparison times a window comparison, and its global layers use the causal comparison itself. Both were rejected, so every layer's flash attention read all 4,096 cache rows at every decode step. ## Details - `aten.mul` of boolean masks matches as their logical and. A mask attends the keys every one of its comparisons attends. - Masks that share a value form one group. The group is computed over the widest extent any of its masks attends, and its values may feed only each other or SDPA masks over the same keys. - Host-evaluated integer constants may hold up to 2^16 elements instead of 64, so the key positions of a 4,096-row static cache evaluate on the host. Gemma 4 31B decode, per step: - **Before**: attention over all 4,096 keys in all 60 layers; flash attention kernels took 2.90 ms. - **After**: attention over the keys up to the end of the 256-key bucket holding the position; 0.88 ms, vs 0.93 ms in llama.cpp. Tests: - `test_sdpa_key_prefix_of_masks_that_share_values`: a causal mask and a sliding-window product that shares its comparison. - `test_sdpa_key_prefix_of_a_mask_group_is_its_widest`: masks of one group that end in different buckets. - `test_sdpa_key_prefix_of_a_mask_read_by_other_ops`: a comparison that also feeds a sum keeps attention over every key. - `test_sdpa_key_prefix_of_constant_key_positions`: key positions held by a constant. Authored with Claude Code. ghstack-source-id: 477270600 Differential Revision: [D130721994](https://our.internmc.facebook.com/intern/diff/D130721994/)
Stack from ghstack (oldest at bottom):
Ulterior Motive
Closing the decode gap between ExecuTorch Native's GGML engine and llama.cpp on CUDA, measured with Gemma 4 31B Q4_K_M on an A100.
Rationale
What: The engine finds key extents for attention masks that are products of comparisons, and for masks that share values.
Why: Attention covers only the keys below an extent the engine computes on the host, but only for masks it matches. It matched a single comparison whose values fed nothing but that mask. Gemma 4 builds its sliding-window mask as the causal comparison times a window comparison, and its global layers use the causal comparison itself. Both were rejected, so every layer's flash attention read all 4,096 cache rows at every decode step.
Details
aten.mulof boolean masks matches as their logical and. A mask attends the keys every one of its comparisons attends.Gemma 4 31B decode, per step:
Tests:
test_sdpa_key_prefix_of_masks_that_share_values: a causal mask and a sliding-window product that shares its comparison.test_sdpa_key_prefix_of_a_mask_group_is_its_widest: masks of one group that end in different buckets.test_sdpa_key_prefix_of_a_mask_read_by_other_ops: a comparison that also feeds a sum keeps attention over every key.test_sdpa_key_prefix_of_constant_key_positions: key positions held by a constant.Authored with Claude Code.
Differential Revision: D130721994