Attention optimizations (part 2): channel-aware backward cache#232
Draft
azrael417 wants to merge 14 commits into
Draft
Attention optimizations (part 2): channel-aware backward cache#232azrael417 wants to merge 14 commits into
azrael417 wants to merge 14 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Second batch of spherical-attention work on top of the optimized kernels. User-visible piece:
channel counts we now cache those per-neighbor dot products in shared memory in pass 1 and read them back in pass 2, eliminating the recompute. Gated to nchan >= 192 and compile-time templated
(template + if constexpr) so the sub-192 path is byte-for-byte identical to the previous kernel — no effect on the common C=64 ERA5 workload.
Plus benchmark and test coverage for the wide-channel regime the cache targets.
Motivation
The backward pass was the remaining hotspot after the forward work in part 1. Profiling showed pass-2 recompute (re-gathering K/V and redoing the dot products) is pure redundant work when
there's shared-memory budget to hold the pass-1 results — which only pays off once the channel dimension is wide enough to dominate the per-neighbor cost, hence the nchan >= 192 gate.
WGMMA/tensor-core rewrites were prototyped and rejected (small skinny latency-bou Jump to bottom (ctrl+End) ↓ r), so this MR keeps the scalar/vectorized kernel and only removes redundant
This MR is marked as draft because #231 needs to be merged first.