Skip to content

vllm.model_executor.layers.rotary_embedding.linear_scaling_rope

Classes:

LinearScalingRotaryEmbedding

Bases: RotaryEmbedding

RotaryEmbedding extended with linear scaling.

It supports multiple scaling factors. Since multiple LoRA adapters may have different scaling factors, we need multiple cos/sin caches. In this way, instead of running rotary embedding kernel per lora, we can run multiple lora in a batched way.

In addition to that, we also keep the cos/sin cache for the scaling factor of 1 (default) at all times.

Exemplary for two scaling factors x=1, y and z with embeddings [[x11, x12, ... x1m], ..., [xn1, xn2, ..., xnm]] and [[y11, y12, ... y1o], ..., [yn1, yn2, ..., yno]], and [[z11, z12, ... z1p], ..., [zn1, zn2, ..., znp]],

we construct the cos/sin cache as follows: [[x11, x12, ... x1m, y11, y12, ... y1o, z11, z12, ... z1p], ... [xn1, xn2, ... xnm, yn1, yn2, ... yno, zn1, zn2, ... znp]]

We then use offsets to index into the cos/sin cache for the respective scaling factors.

The offset to cache can be accessed via scaling_factor_to_offset API.

Credits to the Reddit user /u/kaiokendev