vllm_gaudi.extension.ops
¶
MAX_EXPERTS_PER_SLICE
module-attribute
¶
is_hpu_gaudi2
module-attribute
¶
is_hpu_gaudi3
module-attribute
¶
DynamicFusedMOE
¶
Bases: Module
Source code in vllm_gaudi/extension/ops.py
__init__
¶
forward
¶
Source code in vllm_gaudi/extension/ops.py
MoeFP8Matmul
¶
Bases: Module
Source code in vllm_gaudi/extension/ops.py
__init__
¶
Source code in vllm_gaudi/extension/ops.py
dequant_block_fp8_weight
¶
dequant_block_fp8_weight(layer: MoeFP8Matmul) -> Tensor
Source code in vllm_gaudi/extension/ops.py
forward
¶
get_dequant_weight
¶
Source code in vllm_gaudi/extension/ops.py
get_dequant_weights_func
¶
set_high_precision
¶
MoeMXFP4Matmul
¶
Bases: Module
Weight holder for packed MXFP4 weights + E8M0 scales (+ optional bias).
Source code in vllm_gaudi/extension/ops.py
MoeMatmul
¶
MoeWNA16Matmul
¶
Bases: Module
Matmul wrapper for compressed int4 WNA16 format
Source code in vllm_gaudi/extension/ops.py
VllmMixtureOfExpertsOp
¶
Bases: VllmMixtureOfExpertsOpBase
Source code in vllm_gaudi/extension/ops.py
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 | |
w13_list
instance-attribute
¶
w13_list = torch.nn.ModuleList(
[(MoeMatmul()) for _ in (range(num_total_experts))]
)
w2_list
instance-attribute
¶
w2_list = torch.nn.ModuleList(
[(MoeMatmul()) for _ in (range(num_total_experts))]
)
__init__
¶
__init__(
global_num_experts: int,
num_total_experts: int,
experts_min: int = 0,
experts_max: int = 8,
bias=None,
dispatch_fn: Callable[[Tensor], Tensor] = None,
)
Source code in vllm_gaudi/extension/ops.py
_apply
¶
_cache_weight_lists
¶
Build and cache weight/bias views only (no torch.stack / no extra allocation).
Source code in vllm_gaudi/extension/ops.py
_load_from_state_dict
¶
_load_from_state_dict(
state_dict,
prefix,
local_metadata,
strict,
missing_keys,
unexpected_keys,
error_msgs,
)
Source code in vllm_gaudi/extension/ops.py
forward
¶
forward(
hidden_states,
expert_routing_table,
router_weights,
permuted_weights=True,
activation="silu",
)
Source code in vllm_gaudi/extension/ops.py
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 | |
VllmMixtureOfExpertsOpBase
¶
Bases: Module
Source code in vllm_gaudi/extension/ops.py
moe_n_slice
instance-attribute
¶
moe_n_slice = (
1
if self.num_experts <= max_expert_per_slice
else self.num_experts // max_expert_per_slice
)
num_expert_per_group
instance-attribute
¶
chunk_size is a key performance tuning parameter for the op torch.ops.hpu.mixture_of_experts operator, and its configuration depends on the number of tokens, so we set it by different values.
__init__
¶
__init__(
global_num_experts: int,
num_total_experts: int,
experts_min: int = 0,
experts_max: int = 8,
bias=None,
dispatch_fn: Callable[[Tensor], Tensor] = None,
)
Source code in vllm_gaudi/extension/ops.py
_get_dispatch_func
¶
_get_extra_kwargs
¶
_get_extra_kwargs(tokens_num: int)
Source code in vllm_gaudi/extension/ops.py
VllmMixtureOfExpertsOpFP8
¶
Bases: VllmMixtureOfExpertsOpBase
Source code in vllm_gaudi/extension/ops.py
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 | |
w13_list
instance-attribute
¶
w13_list = torch.nn.ModuleList(
[
(
MoeFP8Matmul(
quant_method=FusedMoeWeightScaleSupported.BLOCK.value
)
)
for _ in (range(num_experts))
]
)
w2_list
instance-attribute
¶
w2_list = torch.nn.ModuleList(
[
(
MoeFP8Matmul(
quant_method=FusedMoeWeightScaleSupported.BLOCK.value
)
)
for _ in (range(num_experts))
]
)
__init__
¶
__init__(
global_num_experts: int,
num_experts: int,
experts_min: int = 0,
experts_max: int = 8,
dispatch_fn: Callable[[Tensor], Tensor] = None,
)
Source code in vllm_gaudi/extension/ops.py
forward
¶
Source code in vllm_gaudi/extension/ops.py
VllmMixtureOfExpertsOpFP8PerChannel
¶
Bases: VllmMixtureOfExpertsOpBase
Source code in vllm_gaudi/extension/ops.py
1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 | |
w13_list
instance-attribute
¶
w13_list = torch.nn.ModuleList(
[(MoeFP8Matmul()) for _ in (range(num_experts))]
)
w2_list
instance-attribute
¶
w2_list = torch.nn.ModuleList(
[(MoeFP8Matmul()) for _ in (range(num_experts))]
)
__init__
¶
__init__(
global_num_experts: int,
num_experts: int,
experts_min: int = 0,
experts_max: int = 8,
dispatch_fn: Callable[[Tensor], Tensor] = None,
)
Source code in vllm_gaudi/extension/ops.py
_apply
¶
_cache_weight_lists
¶
Source code in vllm_gaudi/extension/ops.py
_load_from_state_dict
¶
_load_from_state_dict(
state_dict,
prefix,
local_metadata,
strict,
missing_keys,
unexpected_keys,
error_msgs,
)
Source code in vllm_gaudi/extension/ops.py
forward
¶
Source code in vllm_gaudi/extension/ops.py
VllmMixtureOfExpertsOpMXFP4
¶
Bases: VllmMixtureOfExpertsOpBase
Native MXFP4 MOE op using torch.ops.hpu.mixture_of_experts.mxfp4_fused_weights.
Weights are stored in packed uint8 MXFP4 format (2 FP4 E2M1 values per byte) with uint8 E8M0 scales (one per group of 32 elements). The native TPC kernel performs dequantization on-the-fly during the MOE computation.
IMPORTANT: The mxfp4 ops have frontend_blocklist: [eager], meaning they can only execute through the graph compilation path (torch.compile with hpu_backend). The forward() method is decorated accordingly.
Source code in vllm_gaudi/extension/ops.py
1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 | |
w13_list
instance-attribute
¶
w13_list = torch.nn.ModuleList(
[
(MoeMXFP4Matmul())
for _ in (range(num_total_experts))
]
)
w2_list
instance-attribute
¶
w2_list = torch.nn.ModuleList(
[
(MoeMXFP4Matmul())
for _ in (range(num_total_experts))
]
)
__init__
¶
__init__(
global_num_experts: int,
num_total_experts: int,
experts_min: int = 0,
experts_max: int = 8,
block_size: int = 32,
has_bias: bool = False,
alpha: float = 1.702,
limit: float = 7.0,
dispatch_fn: Callable[[Tensor], Tensor] = None,
)
Source code in vllm_gaudi/extension/ops.py
_apply
¶
_cache_weight_lists
¶
Source code in vllm_gaudi/extension/ops.py
_get_compiled_forward
¶
Source code in vllm_gaudi/extension/ops.py
_load_from_state_dict
¶
_load_from_state_dict(
state_dict,
prefix,
local_metadata,
strict,
missing_keys,
unexpected_keys,
error_msgs,
)
Source code in vllm_gaudi/extension/ops.py
forward
¶
forward(
hidden_states,
expert_routing_table,
router_weights,
permuted_weights=True,
activation="silu",
)
Source code in vllm_gaudi/extension/ops.py
VllmMixtureOfExpertsOpWNA16
¶
Bases: Module
Mixture of Experts for compressed int4 WNA16
Source code in vllm_gaudi/extension/ops.py
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 | |
moe_n_slice
instance-attribute
¶
moe_n_slice = (
1
if self.num_experts <= max_expert_per_slice
else self.num_experts // max_expert_per_slice
)
num_expert_per_group
instance-attribute
¶
w13_list
instance-attribute
¶
w13_list = torch.nn.ModuleList(
[(MoeWNA16Matmul()) for _ in (range(num_experts))]
)
w2_list
instance-attribute
¶
w2_list = torch.nn.ModuleList(
[(MoeWNA16Matmul()) for _ in (range(num_experts))]
)
__init__
¶
Source code in vllm_gaudi/extension/ops.py
forward
¶
Source code in vllm_gaudi/extension/ops.py
_as_activation_str
¶
_flex_prompt_attention
¶
_flex_prompt_attention(
query: Tensor,
key: Tensor,
value: Tensor,
scale: float,
**ignored_args,
) -> Tensor
Source code in vllm_gaudi/extension/ops.py
_fsdpa_prompt_attention
¶
_fsdpa_prompt_attention(
query: Tensor,
key: Tensor,
value: Tensor,
scale: float,
fsdpa_op,
is_causal: bool,
attn_bias: Optional[Tensor] = None,
valid_seq_lengths: Optional[Tensor] = None,
window_size: Optional[int] = None,
sinks: Optional[Tensor] = None,
**ignored_args,
) -> Tensor
Source code in vllm_gaudi/extension/ops.py
_get_all
¶
_get_context
¶
_include_past
¶
Source code in vllm_gaudi/extension/ops.py
_naive_prompt_attention
¶
_naive_prompt_attention(
query: Tensor,
key: Tensor,
value: Tensor,
scale: float,
attn_bias: Optional[Tensor] = None,
position_bias: Optional[Tensor] = None,
matmul_qk_op=matmul,
softmax_op=softmax,
matmul_av_op=matmul,
sinks: Optional[Tensor] = None,
**ignored_args,
) -> Tensor
Source code in vllm_gaudi/extension/ops.py
apply_block_fp8_linear_hpu
¶
apply_block_fp8_linear_hpu(
input: Tensor,
layer: Module,
block_size: List[int],
bias: Optional[Tensor] = None,
do_unpad: bool = False,
force_channel_fp8: bool = False,
) -> Tensor
Source code in vllm_gaudi/extension/ops.py
apply_block_fp8_linear_hpu_dequant
¶
apply_block_fp8_linear_hpu_dequant(
input: Tensor,
weight: Tensor,
block_size: List[int],
weight_scale: Tensor,
input_scale: Optional[Tensor] = None,
bias: Optional[Tensor] = None,
original_M: Optional[Tensor] = None,
original_N: Optional[Tensor] = None,
do_unpad: bool = False,
) -> Tensor
Source code in vllm_gaudi/extension/ops.py
apply_fp8_linear_hpu
¶
apply_fp8_linear_hpu(
input: Tensor,
weight: Tensor,
weight_scale: Tensor,
input_scale: Optional[Tensor] = None,
bias: Optional[Tensor] = None,
trans_B: bool = True,
)
Source code in vllm_gaudi/extension/ops.py
b2b_impl
¶
dequant_block_fp8_weight_naive
¶
dequant_block_fp8_weight_naive(
weight,
weight_scale,
block_size,
dtype=bfloat16,
original_M=None,
original_N=None,
do_unpad=False,
)
Source code in vllm_gaudi/extension/ops.py
dispatch_bgmv_embedding
¶
wb_t_all contains all LoRA-B weight matrices stacked at dimension 0 into
a single tensor, assuming same rank. wb is the transposed and reshaped
version of wb_t_all of shape (num_loras * lora_rank, embedding_dim).
Output of LoRA-A embedding (tensor x) is repeated max_loras times to match
the shape of wb. Multiply x with a mask to zero-out inputs of inactive
LoRA indices. Matmul masked output with wb and scale it to get the final
output.
Source code in vllm_gaudi/extension/ops.py
dispatch_bgmv_linear
¶
dispatch_bgmv_linear(
y: Tensor,
x: Tensor,
wa_t_all: Tensor,
wb_t_all: Tensor,
layer_idx: int,
scale: float,
)
wa_t_all and wb_t_all contains all LoRA A and LoRA B weight matrices
stacked at dimension 0 into single tensors, assuming same rank. wa is the
reshaped and transposed version of wa_t_all of shape
(h_in, max_loras * lora_rank) and wb is the transposed and reshaped
version of wb_t_all of shape (max_loras * lora_rank, h_out).
Matmul input x with wa. Multiply x with a mask to zero-out inputs of
inactive LoRA indices. Matmul masked output with wb and scale it to get
the final output.
Source code in vllm_gaudi/extension/ops.py
dynamic_quant
¶
Source code in vllm_gaudi/extension/ops.py
flat_pa
¶
flat_pa(
query,
key_cache,
value_cache,
block_list,
block_mapping,
block_bias,
block_groups,
block_size,
scale,
matmul_qk_op,
position_bias,
matmul_av_op,
batch2block_matmul_op,
block2batch_matmul_op,
keys_fetch_func,
values_fetch_func,
sinks,
k_scales,
v_scales,
**ignored_args,
)
Source code in vllm_gaudi/extension/ops.py
flat_pa_mla
¶
flat_pa_mla(
query,
key_cache,
value_cache,
block_list,
block_mapping,
block_bias,
block_groups,
block_size,
scale,
matmul_qk_op,
matmul_av_op,
batch2block_matmul_op,
block2batch_matmul_op,
keys_fetch_func,
values_fetch_func,
kv_lora_rank,
)
Source code in vllm_gaudi/extension/ops.py
fp8_block_linear_postprocess_weights
¶
Source code in vllm_gaudi/extension/ops.py
fp8_block_moe_prepare_weights
¶
Source code in vllm_gaudi/extension/ops.py
fp8_channel_moe_prepare_weights
¶
Source code in vllm_gaudi/extension/ops.py
fp8_perchannel_linear_postprocess_weights
¶
Source code in vllm_gaudi/extension/ops.py
gaudi_weight_wrapper
¶
Wrapper for Gaudi weight conversion.
Source code in vllm_gaudi/extension/ops.py
get_dequant_weights_func
¶
Source code in vllm_gaudi/extension/ops.py
get_inc_quant_method
¶
grouped_max
¶
Source code in vllm_gaudi/extension/ops.py
matmul_shape
¶
Source code in vllm_gaudi/extension/ops.py
oot_get_quantization_config
¶
oot_get_quantization_config(
quantization: str,
) -> QuantizationConfig
pad_block_fp8_weight_naive
¶
Source code in vllm_gaudi/extension/ops.py
pad_weight
¶
Pads a matrix to make its dimensions multiples of block_size.
Source code in vllm_gaudi/extension/ops.py
per_tensor_dequantize
¶
Source code in vllm_gaudi/extension/ops.py
pipelined_pa
¶
pipelined_pa(
attn,
value,
block_bias,
block_groups,
block_mapping,
sink,
batch_size,
matmul_av_op,
batch2block_matmul_op,
block2batch_matmul_op,
)
Source code in vllm_gaudi/extension/ops.py
process_fp8_weight_tensor_strategy
¶
process_fp8_weight_tensor_strategy(
weight: Tensor,
weight_scale: Tensor,
logical_widths: list[int],
input_scale: Tensor | None = None,
) -> tuple[Tensor, Tensor, Tensor | None]
Process weights for tensor-wise quantization strategy.
Source code in vllm_gaudi/extension/ops.py
prompt_attention
¶
Source code in vllm_gaudi/extension/ops.py
requantize_with_max_scale
¶
requantize_with_max_scale(
weight: Tensor,
weight_scale: Tensor,
logical_widths: list[int],
) -> tuple[Tensor, Tensor]
Source code in vllm_gaudi/extension/ops.py
scaled_fp8_quant
¶
scaled_fp8_quant(
input: Tensor,
scale: Optional[Tensor] = None,
num_token_padding: Optional[int] = None,
scale_ub: Optional[Tensor] = None,
use_per_token_if_dynamic: bool = False,
) -> Tuple[Tensor, Tensor]
Quantize input tensor to FP8 and return quantized tensor and scale. This function supports both static and dynamic quantization: If you provide the scale, it will use static scaling and if you omit it, the scale will be determined dynamically. The function also allows optional padding of the output tensor for downstream kernels that will benefit from padding. Args: input: The input tensor to be quantized to FP8 scale: Optional scaling factor for the FP8 quantization scale_ub: Optional upper bound for scaling factor in dynamic per token case num_token_padding: If specified, pad the first dimension of the output to at least this value. use_per_token_if_dynamic: Whether to do per_tensor or per_token in the dynamic quantization case. Returns: Tuple[torch.Tensor, torch.Tensor]: The output tensor in FP8 and scaling factor.
Source code in vllm_gaudi/extension/ops.py
synced_weight_loader
¶
unpad_weight
¶
Removes padding from the matrix to restore its original shape.