vllm.model_executor.layers.quantization.utils.int8_utils
_per_token_group_quant_int8
¶
_per_token_group_quant_int8(
y_ptr,
y_q_ptr,
y_s_ptr,
y_stride,
N,
eps,
int8_min,
int8_max,
BLOCK: constexpr,
)
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
_per_token_quant_int8
¶
Source code in vllm/model_executor/layers/quantization/utils/int8_utils.py
_w8a8_block_int8_matmul
¶
_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: constexpr,
BLOCK_SIZE_N: constexpr,
BLOCK_SIZE_K: constexpr,
GROUP_SIZE_M: constexpr,
)
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
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 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
|
apply_w8a8_block_int8_linear
¶
apply_w8a8_block_int8_linear(
input: Tensor,
weight: Tensor,
block_size: list[int],
weight_scale: Tensor,
input_scale: Optional[Tensor] = None,
bias: Optional[Tensor] = None,
) -> Tensor
Source code in vllm/model_executor/layers/quantization/utils/int8_utils.py
block_dequant
¶
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
cached
¶
get_w8a8_block_int8_configs(
N: int, K: int, block_n: int, block_k: int
) -> Optional[dict[int, Any]]
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
input_to_int8
¶
This function quantizes input values to int8 values with tensor-wise quantization.
Source code in vllm/model_executor/layers/quantization/utils/int8_utils.py
per_token_group_quant_int8
¶
per_token_group_quant_int8(
x: Tensor,
group_size: int,
eps: float = 1e-10,
dtype: dtype = int8,
) -> tuple[Tensor, Tensor]
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:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input tensor with ndim >= 2. |
required |
group_size
|
int
|
The group size used for quantization. |
required |
eps
|
float
|
The minimum to avoid dividing zero. |
1e-10
|
dtype
|
dtype
|
The dype of output tensor. Note that only |
int8
|
Returns:
Type | Description |
---|---|
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
per_token_quant_int8
¶
Source code in vllm/model_executor/layers/quantization/utils/int8_utils.py
round_f32
¶
Source code in vllm/model_executor/layers/quantization/utils/int8_utils.py
round_int8
¶
w8a8_block_int8_matmul
¶
w8a8_block_int8_matmul(
A: Tensor,
B: Tensor,
As: Tensor,
Bs: Tensor,
block_size: list[int],
output_dtype: dtype = float16,
) -> Tensor
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:
Name | Type | Description | Default |
---|---|---|---|
A
|
Tensor
|
The input tensor, e.g., activation. |
required |
B
|
Tensor
|
The input tensor, e.g., weight. |
required |
As
|
Tensor
|
The per-token-group quantization scale for |
required |
Bs
|
Tensor
|
The per-block quantization scale for |
required |
block_size
|
list[int]
|
The block size for per-block quantization. It should be 2-dim, e.g., [128, 128]. |
required |
output_dytpe
|
The dtype of the returned tensor. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: The result of matmul. |
Source code in vllm/model_executor/layers/quantization/utils/int8_utils.py
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 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
|