Compute scaled dot-product causal attention with shared KV heads. queries has shape Hq × T × D; keys is Hkv × S × D and values Hkv × S × Dv. Query head h uses KV head floor(h/(Hq/Hkv)).
Queries represent the last T positions of S keys. Key j is allowed for query i only if key_mask[j] is true and j ≤ S−T+i. Use scale 1/sqrt(D). A row with no allowed keys returns Dv zeros. Return Hq × T × Dv.