vllm.lora.ops.triton_ops.fused_moe_lora_op
¶
_adjust_kernel_inputs(num_active_loras, sorted_token_ids, expert_ids)
¶
Helper function to adjust kernel inputs when sorted_token_ids is None.
Source code in vllm/lora/ops/triton_ops/fused_moe_lora_op.py
_fused_moe_lora(output, qcurr_hidden_states, lora_a_stacked, lora_b_stacked, topk_weights, sorted_token_ids, expert_ids, num_tokens_post_padded, token_lora_mapping, max_lora_rank, top_k_num, lora_ids, num_active_loras, adapter_enabled, shrink_block_size_m, shrink_block_size_n, shrink_block_size_k, shrink_group_size_m, shrink_num_warps, shrink_num_stages, shrink_split_k, expand_block_size_m, expand_block_size_n, expand_block_size_k, expand_group_size_m, expand_num_warps, expand_num_stages, expand_split_k, mul_routed_weight=False, fully_sharded=False, offset=0, add_inputs=True, row_map=None)
¶
Adds the MoE LoRA delta of each (token, topk) pair to output.
If row_map is given, output (and qcurr_hidden_states when it holds
one row per pair, i.e. mul_routed_weight=True) are indexed by
row_map[token * top_k_num + k] instead of the pair index, and pairs
mapped to a negative row are skipped.
Source code in vllm/lora/ops/triton_ops/fused_moe_lora_op.py
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 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 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 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 | |
_fused_moe_lora_small_batch_kernel(x_ptr, A_ptrs, B_ptrs, out_ptr, topk_weights_ptr, expert_ids_ptr, token_lora_mapping_ptr, adapter_enabled_ptr, row_map_ptr, N, K, top_k_num, max_loras, work_total, pair_slices, stride_xm, stride_xk, stride_A_lora, stride_A_expert, stride_A_r, stride_A_k, stride_B_lora, stride_B_expert, stride_B_n, stride_B_r, stride_om, stride_on, slice_n_offset, n_tiles_per_program, n_chunks_per_pair_slice, token_mapping_factor, MUL_ROUTED_WEIGHT, ADD_INPUTS, BLOCK_R, actual_rank, BLOCK_N, BLOCK_K, NUM_SLICES, EVEN_K, HAS_ROW_MAP)
¶
Persistent fused MoE-LoRA kernel for naive_block_assignment inputs.
Each program owns one (pair × slice × n_chunk) work item. A "chunk"
covers n_tiles_per_program consecutive output-N tiles, all of which
share a single shrink — so the rank-vector is computed once per
program and the A weights for that (lora, expert, slice) are loaded
once instead of n_tiles_per_program times.
The wrapper picks n_tiles_per_program to keep the grid close to
2*SM_count: at very small batch (work_total ≤ SM_count) the chunk
size collapses to 1 and behaviour matches a per-tile GEMV; as batch
grows the chunk grows so we trade some N-axis parallelism for shrink
reuse. When work_total exceeds the launched grid, the outer stride
loop drains the leftover work units serially.
Source code in vllm/lora/ops/triton_ops/fused_moe_lora_op.py
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 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 | |
_get_expert_id(expert_ids_ptr, lora_id, pid_m, stride_el, max_loras, naive_block_assignment)
¶
Returns expert_id.
Source code in vllm/lora/ops/triton_ops/fused_moe_lora_op.py
_get_lora_id(lora_ids, token_lora_mapping_ptr, lora_idx, pid_m, top_k_num, naive_block_assignment)
¶
Returns lora_id.
Source code in vllm/lora/ops/triton_ops/fused_moe_lora_op.py
_get_ptr(lora_weights, device)
¶
_LORA_PTR_DICT collects the required information during profile_run,
After this, it remains constant and subsequent usage is through LUT.
Refer to:
https://github.com/triton-lang/triton/blob/release/3.1.x/python/tutorials/08-grouped-gemm.py
Source code in vllm/lora/ops/triton_ops/fused_moe_lora_op.py
_get_token_offs(sorted_token_ids_ptr, lora_id, pid_m, offs, stride_tl, max_loras, num_valid_tokens, naive_block_assignment, BLOCK_SIZE_M)
¶
Returns token offsets.
Source code in vllm/lora/ops/triton_ops/fused_moe_lora_op.py
_pick_small_batch_chunk(pair_slices, N_tiles, sm_count)
¶
Pick n_tiles_per_program so the launched grid stays near
2*SM_count.
Sizes for occupancy first (more programs in flight → better latency hiding for the K-loop A/x loads). Once the per-tile grid already exceeds 2*SM_count we increase the chunk size to amortise the shrink cost — at that point the GPU is saturated by per-program work and packing more tiles per program lets the rank_vec be reused.
Source code in vllm/lora/ops/triton_ops/fused_moe_lora_op.py
_run_fused_moe_lora_one_shot(output, qcurr_hidden_states, lora_a_stacked, lora_b_stacked, topk_weights, sorted_token_ids, expert_ids, num_tokens_post_padded, token_lora_mapping, max_lora_rank, top_k_num, lora_ids, num_active_loras, adapter_enabled, mul_routed_weight, block_size_m, add_inputs=True, row_map=None)
¶
Fast-path wrapper: launches one fused shrink+expand kernel.
The shape contract matches _fused_moe_lora. output has shape
(num_tokens, top_k_num, num_slices * N_per_slice). When
add_inputs=True (default) the kernel reads-modifies-writes output
in place; when add_inputs=False the kernel overwrites output with
the LoRA delta only. The latter is used by the dual-stream path that
sums LoRA into the base output on a separate stream.
Source code in vllm/lora/ops/triton_ops/fused_moe_lora_op.py
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 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 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 | |
_run_fused_moe_lora_small_batch(output, qcurr_hidden_states, lora_a_stacked, lora_b_stacked, topk_weights, expert_ids_flat, token_lora_mapping, top_k_num, adapter_enabled, mul_routed_weight, add_inputs=True, row_map=None)
¶
Small-batch GEMV-style wrapper. Naive-block-assignment inputs only.
Shape contract matches _run_fused_moe_lora_one_shot: output is
(num_tokens, top_k_num, num_slices * N_per_slice) with
contiguous-style strides, expert_ids_flat is the flattened
topk_ids of shape (num_tokens * top_k_num,), and the
rank-padded LoRA weights live in lora_a_stacked /
lora_b_stacked.
The kernel is persistent over (pair × slice × n_chunk) work items —
each program does one shrink and reuses the rank vector across
n_tiles_per_program expand tiles. The chunk size scales with the
pair-slice count so very small batches keep per-tile parallelism
while medium batches cut redundant shrinks.
Source code in vllm/lora/ops/triton_ops/fused_moe_lora_op.py
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 | |