awslabs / awslabs/keys_values

Implement context parallelism (RingAttention) as `KVCache`

Open
#19 5 comments 0 reactions 1 assignee Claimed by @mseeger View on GitHub
enhancement
Dominant language
Python
Stars
18
Forks
8
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**

LARGER PROJECT

Currently, all `KVCache` implementations store buffers and run computation on a single device. RingAttention distributes memory and compute across several devices. Our `KVCache` abstraction allows for that to be implemented fairly easily.

**Describe the solution you'd like**

To the user, this should look like a normal KV cache, just with a much larger length:

* Different to RingAttention: Any KV cache type supported on the devices (but same type on each)
* Allows for much larger cache length
* RingAttention also parallelizes over the query axis. So this speeds up processing of large chunks

Should be doable with `isend`, `irecv`: https://docs.pytorch.org/tutorials/intermediate/dist_tuto.html#our-own-ring-allreduce

Approach:
* Copy KV buffers to CPU and transfer them from there. Sync point at the end of the computation
* Each rank computes part along query axis
* At the end: all_reduce to spread the results

Note: We cannot couple this with DDP, to obtain a larger batch size. RingAttention parallelizes over the query axis as well, but the batch size also scales the KV cache buffers. We can get away with larger chunks here, though.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.