• Jesse Gross's avatar
    kvcache: Group shift operations into batches · 764be748
    Jesse Gross authored
    Currently, when we need to do a shift on the cache, it is one
    RoPE operation on the entire size of the cache (per layer). In
    some cases, this can create a compute graph that is larger than
    the forward pass since the forward pass is working in batches.
    Since we don't consider shifting in our memory estimates, it's
    possible for this to cause a crash if we run out of memory.
    
    By limiting the size of the RoPE calls to batch size chunks, we
    ensure that the shift will never exceed the size of the forward
    pass, since the forward pass will also contain a RoPE of the same
    size. This does not have a sigificant impact on performance since
    RoPE is a math operation that is mostly proportional to the size
    of its inputs.
    
    In theory defrag could have the same issue since it also creates a
    compute graph outside of the forward pass, however, since it is
    only copies, it does not require any working space.
    764be748
causal.go 18.2 KB