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
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 382 383 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 | |
_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
_supports_activation staticmethod ¶
_supports_parallel_config staticmethod ¶
_supports_parallel_config(
moe_parallel_config: FusedMoEParallelConfig,
) -> bool
Source code in vllm/model_executor/layers/fused_moe/gpt_oss_triton_kernels_moe.py
_supports_quant_scheme staticmethod ¶
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
activation_format staticmethod ¶
activation_format() -> FusedMoEActivationFormat
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
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 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 | |
activation_format staticmethod ¶
activation_format() -> FusedMoEActivationFormat
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
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 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 | |
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
legacy_routing ¶
legacy_routing(
logits: Tensor, n_expts_act: int, sm_first: bool = False
) -> tuple[RoutingData, GatherIndx, ScatterIndx]
Replacement for the removed triton_kernels.routing.routing function. Computes routing data from gating logits.
Source code in vllm/model_executor/layers/fused_moe/gpt_oss_triton_kernels_moe.py
legacy_routing_from_bitmatrix ¶
legacy_routing_from_bitmatrix(
bitmatrix: Bitmatrix,
expt_scal: Tensor,
expt_indx: Tensor,
n_expts_tot: int,
n_expts_act: int,
) -> tuple[RoutingData, GatherIndx, ScatterIndx]
Replacement for the removed triton_kernels.routing.routing_from_bitmatrix. Creates routing data from a bitmatrix representation.
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
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 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 | |
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