vllm.v1.kv_offload.worker.cpu_gpu ¶
CpuGpuOffloadingHandlers ¶
Source code in vllm/v1/kv_offload/worker/cpu_gpu.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
cpu_to_gpu_handler instance-attribute ¶
cpu_to_gpu_handler = SingleDirectionOffloadingHandler(
src_tensors=cpu_tensors,
dst_tensors=gpu_tensors,
kv_dim_before_num_blocks=kv_dim_before_num_blocks,
src_block_size_factor=cpu_block_size_factor,
dst_block_size_factor=gpu_block_size_factor,
priority=-1,
)
gpu_to_cpu_handler instance-attribute ¶
gpu_to_cpu_handler = SingleDirectionOffloadingHandler(
src_tensors=gpu_tensors,
dst_tensors=cpu_tensors,
kv_dim_before_num_blocks=kv_dim_before_num_blocks,
src_block_size_factor=gpu_block_size_factor,
dst_block_size_factor=cpu_block_size_factor,
priority=1,
)
__init__ ¶
__init__(
gpu_block_size: int,
cpu_block_size: int,
num_cpu_blocks: int,
gpu_caches: dict[str, Tensor],
attn_backends: dict[str, type[AttentionBackend]],
)
Source code in vllm/v1/kv_offload/worker/cpu_gpu.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
SingleDirectionOffloadingHandler ¶
Bases: OffloadingHandler
SingleDirectionOffloadingHandler handles transfers for a single direction, either CPU->GPU or GPU->CPU. Transfers are guaranteed to be executed in order of their submission. Each transfer uses a unique CUDA stream, and its stream will start executing only after the streams of previous transfers have finished.
Source code in vllm/v1/kv_offload/worker/cpu_gpu.py
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 165 166 167 168 | |
kv_dim_before_num_blocks instance-attribute ¶
__init__ ¶
__init__(
src_tensors: list[Tensor],
dst_tensors: list[Tensor],
kv_dim_before_num_blocks: list[bool],
src_block_size_factor: int,
dst_block_size_factor: int,
priority: int,
)
Initialize a SingleDirectionOffloadingHandler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src_tensors | list[Tensor] | list of KV cache tensors to copy from. | required |
dst_tensors | list[Tensor] | list of KV cache tensors to copy to. Order should match src_tensors. | required |
kv_dim_before_num_blocks | list[bool] | list of bools, indicating whether the respective KV cache tensor has a KV dimension before its num_blocks dimension. e.g. (2, num_blocks, ...) | required |
src_block_size_factor | int | The number of kernel blocks per KV block in a source tensor. | required |
dst_block_size_factor | int | The number of kernel blocks per KV block in a destination tensor. | required |
priority | int | The priority of the backing CUDA streams. Lower numbers indicate higher priority. | required |
Source code in vllm/v1/kv_offload/worker/cpu_gpu.py
get_finished ¶
get_finished() -> list[TransferResult]
Source code in vllm/v1/kv_offload/worker/cpu_gpu.py
transfer_async ¶
transfer_async(
job_id: int, transfer_spec: TransferSpec
) -> bool
Source code in vllm/v1/kv_offload/worker/cpu_gpu.py
expand_block_ids ¶
expand_block_ids(
block_ids: ndarray,
block_size_factor: int,
output: ndarray,
skip_count: int = 0,
)
Convert a list of block IDs to a list of matching block ids, assuming each block is composed of actual block_size_factor blocks. Outputs to output tensor. The first skip_count blocks will be skipped. Note that skip_count must be less than block_size_factor.
For example, if block_ids = [0, 1, 3] and block_size_factor = 4, then it yields [0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15] since 0 maps to [0, 1, 2, 3] 1 maps to [4, 5, 6, 7] and 3 maps to [12, 13, 14, 15]