vllm.model_executor.layers.fused_moe.gpt_oss_triton_kernels_moe ¶
BaseOAITritonExperts ¶
Bases: FusedMoEPermuteExpertsUnpermute
Source code in vllm/model_executor/layers/fused_moe/gpt_oss_triton_kernels_moe.py
__init__ ¶
__init__(quant_config: FusedMoEQuantConfig)
_make_routing_data ¶
_make_routing_data(
topk_ids: Tensor,
topk_weights: Tensor,
num_local_experts: int,
) -> tuple[RoutingData, Tensor, Tensor]
Source code in vllm/model_executor/layers/fused_moe/gpt_oss_triton_kernels_moe.py
finalize_weight_and_reduce_impl ¶
finalize_weight_and_reduce_impl() -> TopKWeightAndReduce
moe_problem_size ¶
moe_problem_size(
a1: Tensor, w1: Tensor, w2: Tensor, topk_ids: Tensor
) -> tuple[int, int, int, int, int]
Extract the MoE problem size from the given tensor arguments: - a: The hidden states, input to the MoE layer. - w1: The first set of expert weights. - w2: The second set of expert weights. - topk_ids: The topk ids. Note: extracting the problem shape from the weight and activation tensors is not obvious. It needs to be done this way specifically due to subtle issues with particular kernels, e.g. the int4 kernels divide the trailing dimension by two, so it's not "correct" to extract N or K from the trailing dimension of w1 or w2. Similarly, some kernels transpose the weights, so this needs to be kept in mind. Note: This implementation covers most cases. However, if experts require a specialized implementation, like MarlinExperts, they are free to override this function.
Source code in vllm/model_executor/layers/fused_moe/gpt_oss_triton_kernels_moe.py
OAITritonExperts ¶
Bases: BaseOAITritonExperts
Source code in vllm/model_executor/layers/fused_moe/gpt_oss_triton_kernels_moe.py
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 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
activation_formats property ¶
activation_formats: tuple[
FusedMoEActivationFormat, FusedMoEActivationFormat
]
__init__ ¶
__init__(quant_config: FusedMoEQuantConfig)
apply ¶
apply(
output: Tensor,
hidden_states: Tensor,
w1: Tensor,
w2: Tensor,
topk_weights: Tensor,
topk_ids: Tensor,
activation: str,
global_num_experts: int,
expert_map: Tensor | None,
a1q_scale: Tensor | None,
a2_scale: Tensor | None,
workspace13: Tensor,
workspace2: Tensor,
expert_tokens_meta: ExpertTokensMetadata | None,
apply_router_weight_on_input: bool,
)
Source code in vllm/model_executor/layers/fused_moe/gpt_oss_triton_kernels_moe.py
workspace_shapes ¶
workspace_shapes(
M: int,
N: int,
K: int,
topk: int,
global_num_experts: int,
local_num_experts: int,
expert_tokens_meta: ExpertTokensMetadata | None,
activation: str,
) -> tuple[
tuple[int, ...], tuple[int, ...], tuple[int, ...]
]
Source code in vllm/model_executor/layers/fused_moe/gpt_oss_triton_kernels_moe.py
UnfusedOAITritonExperts ¶
Bases: BaseOAITritonExperts
A Triton based MoE expert class that operates on expert standard format and explicitly keeps the activation and reduction (moe_sum) steps unfused from the matmul_ogs kernel. This exposes injection points for activation and moe_sum.
One use case for it is to inject LoRA modules on the activation and moe_sum.
Source code in vllm/model_executor/layers/fused_moe/gpt_oss_triton_kernels_moe.py
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 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 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | |
activation_formats property ¶
activation_formats: tuple[
FusedMoEActivationFormat, FusedMoEActivationFormat
]
__init__ ¶
__init__(quant_config: FusedMoEQuantConfig)
apply ¶
apply(
output: Tensor,
hidden_states: Tensor,
w1: Tensor,
w2: Tensor,
topk_weights: Tensor,
topk_ids: Tensor,
activation: str,
global_num_experts: int,
expert_map: Tensor | None,
a1q_scale: Tensor | None,
a2_scale: Tensor | None,
workspace13: Tensor,
workspace2: Tensor,
expert_tokens_meta: ExpertTokensMetadata | None,
apply_router_weight_on_input: bool,
)
Source code in vllm/model_executor/layers/fused_moe/gpt_oss_triton_kernels_moe.py
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 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | |
moe_sum ¶
workspace_shapes ¶
workspace_shapes(
M: int,
N: int,
K: int,
topk: int,
global_num_experts: int,
local_num_experts: int,
expert_tokens_meta: ExpertTokensMetadata | None,
activation: str,
) -> tuple[
tuple[int, ...], tuple[int, ...], tuple[int, ...]
]
Source code in vllm/model_executor/layers/fused_moe/gpt_oss_triton_kernels_moe.py
make_routing_data ¶
make_routing_data(
topk_ids: Tensor,
topk_weights: Tensor,
num_local_experts: int,
) -> tuple[RoutingData, Tensor, Tensor]
Source code in vllm/model_executor/layers/fused_moe/gpt_oss_triton_kernels_moe.py
pack_bitmatrix ¶
pack_bitmatrix(
bitmatrix,
topk_ids,
n_rows,
bm_cols: constexpr,
n_expts_act,
BLOCK_SIZE_M: constexpr,
BLOCK_SIZE_K: constexpr,
)
Packs topk_ids into a bitmatrix. code reference: https://github.com/triton-lang/triton/blob/dd1bbc52b34d202dfe5ffea1e04fb16166c5c04e/python/triton_kernels/bench/distributed.py#L264
Source code in vllm/model_executor/layers/fused_moe/gpt_oss_triton_kernels_moe.py
triton_kernel_fused_experts ¶
triton_kernel_fused_experts(
output_tensor: Tensor,
hidden_states: Tensor,
w1,
w2,
routing_data,
gather_indx,
scatter_indx,
topk: int,
activation: str = "silu",
quant_config: FusedMoEQuantConfig | None = None,
swiglu_alpha: float = 1.702,
swiglu_limit: float = 7.0,
apply_router_weight_on_input: bool = False,
global_num_experts: int = -1,
expert_map: Tensor | None = None,
intermediate_cache: Tensor | None = None,
a1q_scale: Tensor | None = None,
) -> Tensor
Source code in vllm/model_executor/layers/fused_moe/gpt_oss_triton_kernels_moe.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
triton_kernel_moe_forward ¶
triton_kernel_moe_forward(
hidden_states: Tensor,
w1,
w2,
gating_output: Tensor,
topk: int,
renormalize: bool,
activation: str = "silu",
quant_config: FusedMoEQuantConfig | None = None,
apply_router_weight_on_input: bool = False,
global_num_experts: int = -1,
expert_map: Tensor | None = None,
) -> Tensor