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
¶
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
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,
dispatch_fn: Callable[[Tensor], Tensor] = None,
)
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
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,
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
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 | |
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
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 | |
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
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
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 1323 1324 1325 1326 1327 1328 | |
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
_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,
**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,
**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,
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
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,
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.