vllm.lora.punica_wrapper.utils
compute_meta
¶
Get the information required for the sgmv kernel. With the features: 1. If consecutive requests in the batch use the same LoRA, this function will combine them into a single request, improving sgmv kernel inference performance. 2. At the beginning of each prefill stage inference, recalculations are needed based on the input, but only once.
Source code in vllm/lora/punica_wrapper/utils.py
convert_mapping
¶
convert_mapping(
mapping: LoRAMapping,
lora_index_to_id: list[Optional[int]],
max_loras: int,
vocab_size: int,
extra_vocab_size: int,
device: device,
long_lora_context: Optional[
LongContextLoRAContext
] = None,
) -> tuple[
Tensor,
Tensor,
Tensor,
Tensor,
Optional[Tensor],
list[int],
]
Converts LoRAMapping to index tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mapping
|
LoRAMapping
|
LoRAMapping mapping rows in a batch to LoRA ids. |
required |
lora_index_to_id
|
list[Optional[int]]
|
List mapping LoRA ids to LoRA indices. |
required |
max_loras
|
int
|
Maximum number of LoRAs. |
required |
vocab_size
|
int
|
Model vocab size. |
required |
extra_vocab_size
|
int
|
Extra vocab size each LoRA can have. |
required |
long_lora_context
|
Optional[LongContextLoRAContext]
|
Passed if there are long context lora in a batch. |
None
|
Returns:
Type | Description |
---|---|
tuple[Tensor, Tensor, Tensor, Tensor, Optional[Tensor], list[int]]
|
A tuple of tensors: base_indices: Tensor of shape [batch_size] mapping batch rows to LoRA indices. sampler_indices: Tensor of shape [batch_size] mapping requests to LoRA indices for sampler. For generation, this will be the same as base_indices. For prefill, this will map requests to LoRA indices. sampler_indices_padded: Tensor of shape [batch_size] mapping requests to LoRA indices for sampler with padding. Same as sampler_indices, but -1 is replaced with max_loras. embeddings_indices: Tensor of shape [2, batch_size] mapping requests to embedding indices. First row is for embeddings added by the LoRAs, second row is for the LoRA.lora_a embeddings. long_lora_indices: Tensor of shape [batch_size] mapping requests to RoPE offsets and rot dims for long LoRAs. None if long context lora doesn't exist. indices_len: List of lengths of the above tensors. It contains (base_indices, sampler_indices, sampler_indices_padded, embeddings_indices, long_lora_indices). |
Source code in vllm/lora/punica_wrapper/utils.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|