vllm.model_executor.layers.quantization.utils.int8_utils ¶
Functions:
-
block_dequant–This function conducts block-wise dequantization.
-
get_w8a8_block_int8_configs–Return optimized configurations for the w8a8 block fp8 kernel.
-
per_token_group_quant_int8–Function to perform per-token-group quantization on an input tensor
x. -
w8a8_block_int8_matmul–This function performs matrix multiplication with block-wise
_per_token_group_quant_int8(y_ptr, y_q_ptr, y_s_ptr, y_stride, N, eps, int8_min, int8_max, BLOCK) ¶
A Triton-accelerated function to perform per-token-group quantization on a tensor.
This function converts the tensor values into int8 values.
Source code in vllm/model_executor/layers/quantization/utils/int8_utils.py
_w8a8_block_int8_matmul(A, B, C, As, Bs, M, N, K, group_n, group_k, stride_am, stride_ak, stride_bk, stride_bn, stride_cm, stride_cn, stride_As_m, stride_As_k, stride_Bs_k, stride_Bs_n, BLOCK_SIZE_M, BLOCK_SIZE_N, BLOCK_SIZE_K, GROUP_SIZE_M) ¶
Triton-accelerated function used to perform linear operations (dot product) on input tensors A and B with block-wise quantization, and store the result in output tensor C.
Source code in vllm/model_executor/layers/quantization/utils/int8_utils.py
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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
block_dequant(x_q_block, x_s, block_size) ¶
This function conducts block-wise dequantization. The inputs are block-wise quantization tensor x_q_block, block-wise quantization scale and the block size. The outputs are dequantized tensor.
Source code in vllm/model_executor/layers/quantization/utils/int8_utils.py
get_w8a8_block_int8_configs(N, K, block_n, block_k) cached ¶
Return optimized configurations for the w8a8 block fp8 kernel.
The return value will be a dictionary that maps an irregular grid of batch sizes to configurations of the w8a8 block fp8 kernel. To evaluate the kernel on a given batch size bs, the closest batch size in the grid should be picked and the associated configuration chosen to invoke the kernel.
Source code in vllm/model_executor/layers/quantization/utils/int8_utils.py
per_token_group_quant_int8(x, group_size, eps=1e-10, dtype=torch.int8) ¶
Function to perform per-token-group quantization on an input tensor x.
It converts the tensor values into signed int8 values and returns the quantized tensor along with the scaling factor used for quantization.
Parameters:
-
(x¶Tensor) –The input tensor with ndim >= 2.
-
(group_size¶int) –The group size used for quantization.
-
(eps¶float, default:1e-10) –The minimum to avoid dividing zero.
-
(dtype¶dtype, default:int8) –The dype of output tensor. Note that only
torch.int8is supported for now.
Returns:
-
tuple[Tensor, Tensor]–tuple[torch.Tensor, torch.Tensor]: The quantized tensor and the scaling factor for quantization.
Source code in vllm/model_executor/layers/quantization/utils/int8_utils.py
w8a8_block_int8_matmul(A, B, As, Bs, block_size, output_dtype=torch.float16) ¶
This function performs matrix multiplication with block-wise quantization.
It takes two input tensors A and B with scales As and Bs. The output is returned in the specified output_dtype.
Parameters:
-
(A¶Tensor) –The input tensor, e.g., activation.
-
(B¶Tensor) –The input tensor, e.g., weight.
-
(As¶Tensor) –The per-token-group quantization scale for
A. -
(Bs¶Tensor) –The per-block quantization scale for
B. -
(block_size¶list[int]) –The block size for per-block quantization. It should be 2-dim, e.g., [128, 128].
-
(output_dtype¶dtype, default:float16) –The dtype of the returned tensor.
Returns:
-
Tensor–torch.Tensor: The result of matmul.
Source code in vllm/model_executor/layers/quantization/utils/int8_utils.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |