vllm_gaudi.extension.ops
¶
MAX_EXPERTS_PER_SLICE
module-attribute
¶
MAX_EXPERTS_PER_SLICE = int(
get("MAX_EXPERTS_PER_SLICE", -1)
)
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
¶
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 = ModuleList(
[(MoeMatmul()) for _ in (range(num_total_experts))]
)
w2_list
instance-attribute
¶
w2_list = 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
¶
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
1160 1161 1162 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 | |
w13_list
instance-attribute
¶
w13_list = ModuleList(
[
(MoeFP8Matmul(quant_method=value))
for _ in (range(num_experts))
]
)
w2_list
instance-attribute
¶
w2_list = ModuleList(
[
(MoeFP8Matmul(quant_method=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
1226 1227 1228 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 | |
w13_list
instance-attribute
¶
w13_list = ModuleList(
[(MoeFP8Matmul()) for _ in (range(num_experts))]
)
w2_list
instance-attribute
¶
w2_list = 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
VllmMixtureOfExpertsOpWNA16
¶
Bases: Module
Mixture of Experts for compressed int4 WNA16
Source code in vllm_gaudi/extension/ops.py
1456 1457 1458 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 | |
moe_n_slice
instance-attribute
¶
w13_list
instance-attribute
¶
w13_list = ModuleList(
[(MoeWNA16Matmul()) for _ in (range(num_experts))]
)
w2_list
instance-attribute
¶
w2_list = 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.